picosam
05/30/2018, 7:44 PMquery {
id
multilingualData {
language
title
}
}
where info would be an array. I want the user to query GraphQL Yoga as follows:
query {
id
title
}
It is, of course, easy to map the Prisma result to another object and return it to the user. But then the info argument comes into play. In order for me to fetch multilingualData I have to pass an info object to the Prisma query, the following string for example: { id multilingualData { language title } } which is of course error-prone. Any thoughts on how to better achieve this?lawjolla
05/30/2018, 9:01 PMpicosam
05/30/2018, 9:05 PMpicosam
05/30/2018, 9:05 PMinfo object to Prisma as textpicosam
05/30/2018, 9:05 PMlawjolla
05/30/2018, 9:08 PMpicosam
05/30/2018, 9:08 PMpicosam
05/30/2018, 9:08 PMlawjolla
05/30/2018, 9:09 PMpicosam
05/30/2018, 9:10 PMpicosam
05/30/2018, 9:11 PMlawjolla
05/30/2018, 9:11 PMInfo blogpicosam
05/30/2018, 9:12 PMpicosam
05/30/2018, 9:13 PMinfo that would just say “return everything”lawjolla
05/30/2018, 9:14 PMquery { id title ...}, is that returning everything? Is the problem that there are fields nested in multilingual data that may need to be returned?picosam
05/30/2018, 9:15 PMlawjolla
05/30/2018, 9:17 PMinfo to get all of the scalars. Does multilingual data have nested queryable types that could also be returned?picosam
05/30/2018, 9:17 PMpicosam
05/30/2018, 9:18 PMlawjolla
05/30/2018, 9:18 PMpicosam
05/30/2018, 9:19 PMimport { Context } from '../../context';
export const families = async (parent, { filters }, ctx: Context) => {
return ctx.db.query
.families(
{
where: {
accommodationOptions_some: {
price_lte: filters.maxRate,
type_in: filters.accommodationOptionTypes
}
}
},
`{
id
oldId
info {
language
name
description
}
type
children
pets
genderAccepted
canHostOtherGuests
photos {
storeId
}
accommodationOptions {
id
type
price
}
}`
)
.then(result =>
result.map(family => {
const familyInfo = family.info.find(item => item.language === 'en');
return {
id: family.id,
oldId: family.oldId,
name: familyInfo.name,
description: familyInfo.description,
type: family.type,
children: family.children,
pets: family.pets,
genderAccepted: family.genderAccepted,
canHostOtherGuests: family.canHostOtherGuests,
photos: family.photos,
accommodationOptions: family.accommodationOptions
};
})
);
};picosam
05/30/2018, 9:21 PMpicosam
05/30/2018, 9:22 PMlawjolla
05/30/2018, 9:23 PMlawjolla
05/30/2018, 9:25 PMresult.map, you're returning everything that could be asked for?picosam
05/30/2018, 9:25 PMpicosam
05/30/2018, 9:26 PMlawjolla
05/30/2018, 9:30 PMlawjolla
05/30/2018, 9:34 PMexport const families = async (parent, { filters }, ctx: Context, info) => {
return ctx.db.query
.families(
{
where: {
accommodationOptions_some: {
price_lte: filters.maxRate,
type_in: filters.accommodationOptionTypes
}
}
}, info)
}
...
Family = {
accomodationOptions: async (dataReturnedFromFamliesQuery, args, ctx, info) => {
return ctx.db.accmmodationOptions({...}, info)
},
info: ...,
etc
}picosam
05/30/2018, 9:37 PMlawjolla
05/30/2018, 9:38 PMpicosam
05/30/2018, 9:38 PMpicosam
05/30/2018, 9:38 PMpicosam
05/30/2018, 9:39 PMlawjolla
05/30/2018, 9:39 PMpicosam
05/30/2018, 9:41 PMpicosam
05/30/2018, 9:41 PMlawjolla
05/30/2018, 9:42 PMFamily: {
accomodationOptions: {
fragment: `fragment needFamilyId on Family {id}`,
resolve: async(...) => { ... }
}
}lawjolla
05/30/2018, 9:43 PMpicosam
05/30/2018, 9:44 PMcmcinroy
05/31/2018, 10:06 AMpicosam
05/31/2018, 10:10 AMcmcinroy
05/31/2018, 10:12 AM