Skip to content

typescript plugin: Resolvers and Optional vs Nullable types. #4345

Discussion options

You must be logged in to vote

The default output of typescript-resolvers is a 1:1 match of the JSON structure. That means, you can't have partials return values with the default settings.

There are several solutions you can use:

  1. Allow partials, by adding this to your configuration: defaultMapper: Partial<{T}>. This will allow you to return partial values on resolvers.
  2. Use mappers - In most cases, your data models are not the same as your GraphQL API. You can tell codegen where are your TypeScript types that represents each GraphQL type, and it will use those types instead of using the default types.

You can read more about resolvers and codegen here: https://the-guild.dev/blog/better-type-safety-for-resolvers-with-g…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dotansimha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants