dotansimha / dotansimha/graphql-code-generator
Support TResult | null for TypedDocumentNode when top-level data may be null
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Is your feature request related to a problem? Please describe.
According to the GraphQL [specification](https://spec.graphql.org/October2021/#sel-DAPHEPHAAERBAAwyB), it's possible for the top-level data field in the response to be null in case of certain errors (e.g. when a non-nullable root field throws an unexpected error).
### Describe the solution you'd like
I’d like to have an option added to the `@graphql-codegen/typescript` plugin that allows it to generate TResult | null in operation result types.
graphql.ts
```ts:graphql.ts
export const GetHogeDocument = {
...
} as TypedDocumentNode
```
instead of the current:
```ts:graphql.ts
export const GetHogeDocument = {
...
} as TypedDocumentNode
```
This would allow safer and more accurate typing for clients where data: null is a valid result according to GraphQL spec.
### Describe alternatives you've considered
_No response_
### Any additional important details?
I asked the urql team about this, and they suggested handling it by altering the TypedDocumentNode type generated/produced.
Reference: https://github.com/urql-graphql/urql/issues/3803#issuecomment-3148608215
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.