Skip to content

Non-nullable graphql fields are being marked as required in the generated typescript code #10144

Answered by charpeni
vidishanevatia asked this question in Q&A
Discussion options

You must be logged in to vote

The expected behavior you described matches the behavior I would expect, but it also matches my experience so far.

"Full" types will be generated from the GraphQL schema, and they will include all non-nullable fields as required, but those types shouldn't be used as-is as they are 1:1 with their GraphQL schema type.

Instead, GraphQL operations can be composed of colocated fragments (or not) that expose the data requirements of components. Non-nullable fields shouldn't be required as part of the operation, but they will be non-nullable if queried. Full types aren't expected to be imported. Instead, we should rely on type utilities like FragmentType, ResultOf, and VariablesOf to infer the r…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by vidishanevatia
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