mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.34k stars 234 forks source link

__resolveReference in Typescript Loader #932

Open timclaason opened 1 year ago

timclaason commented 1 year ago

Wondering if there is a Typescript equivalent of the Javascript example given in documentation for how to have a cached reference resolver in a loader. For some reason, I can't get it to work...

const loaders = {
  User: {
    async __resolveReference(queries, context) {
      // This should be a bulk query to the database
      return queries.map(({ obj }) => users[obj.id])
    }
  }
}
mcollina commented 1 year ago

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.