Christian
05/18/2018, 12:21 PMconst companyQuery = `
{
company {
id
}
}
`
export const companies = {
async company(parent, args, ctx: Context, info) {
const userId = getUserId(ctx)
const userCompanyId = await ctx.db.query.user(
{ where: { id: userId } },
companyQuery,
)
return ctx.db.query.company(
{ where: { id: userCompanyId.company.id } },
info,
)
},
}
I would like to get the Company data directly with the user query though, but for this I need to transform the info object (wrapping the SelectionSet for a Company into one suitable for User)... what is the best way to do this?anton-b
05/18/2018, 12:55 PMconst userId = getUserId(ctx)
return ctx.db.query.serviceProviders({
where: { users_some: { id: userId } },
});
However this only work because I know that a user
can only be connected to a single serviceProvider
.
Maybe you can use that approach. I'm not sure if it is the best though 🙂nilan
05/18/2018, 1:00 PMChristian
05/18/2018, 1:39 PMexport const companies = {
async company(parent, args, ctx: Context, info) {
const userId = getUserId(ctx)
const userCompanies = await ctx.db.query.companies(
{ where: { users_some: { id: userId } } },
info,
)
return userCompanies[0]
},
}
Christian
05/18/2018, 1:40 PMChristian
05/18/2018, 1:42 PMmyLocation
query the user
query is called with a third argument, using WrapQuery
to wrap the selectionChristian
05/18/2018, 1:42 PM