I have the following resolver to fetch the "curren...
# orm-help
c
I have the following resolver to fetch the "current user"-related Company data
Copy code
const 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?
a
Hi @Christian, I did something like this yesterday:
Copy code
const 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 🙂
n
that's pretty much what I would do as well, @anton-b
c
right, this would do the trick:
Copy code
export 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]
  },
}
in the
myLocation
query the
user
query is called with a third argument, using
WrapQuery
to wrap the selection
this seems to be deprecated?