Skip to content

Typescript typing if separating out the resolver impl #165

Answered by hayes
theogravity asked this question in Q&A
Discussion options

You must be logged in to vote

So if you are defining your resolver outside the field, you can't benefit from inference and need to manually type your resolver. I'm on a phone, so examples here will be a bit simplified and probably have some errors or typos..

There are 2 general options. The first option is to define functions that load the required data (or perform the required action) and have that function take whatever args it needs, rather than following the resolver convention. This let's you extract your core logic in a way that is abstracted from graphql, and might be re-usable.

builder.queryType({
  fields: (t) => ({
    user: t.field({
      type: User,
      args: {
        id: t.arg.id(),
      },
      res…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@theogravity
Comment options

Answer selected by theogravity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants