Non-nullable graphql fields are being marked as required in the generated typescript code #10144
-
Problem: Expected Behavior: Is there a way I can achieve this behavior? @dotansimha |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 We can even go further by conditionally queried fields with I don't see why all non-nullable fields would always be required to be queried as part of all GraphQL operations, but it's hard to help further without knowing your current setup. Do you use |
Beta Was this translation helpful? Give feedback.
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
, andVariablesOf
to infer the r…