dotansimha / dotansimha/graphql-code-generator
TypeScript Resolvers plugin doesn't allow null to be returned from a promise
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Describe the bug**
Given a query with an optional response:
```
type Query {
subscription: SubscriptionDetails
}
```
I should be able to write a resolver that returns a promise that returns null:
```
const subscription: QueryResolvers["subscription"] = async (
_root,
_args,
) => {
return await fetchResult(); // Might return null
}
```
However, I can't because the return type is defined like this:
`Maybe>`
So I can return null _immediately_ (thanks to the `Maybe`), but if I return a Promise then I have to return `ResolverTypeWrapper`, which is defined as:
`export type ResolverTypeWrapper = Promise | T;`
Where the type T itself (SubscriptionDetails in the example) isn't null, so I can't return null.
**Proposed Solution**:
If the response is optional then the generated code should be something like:
`Maybe>>`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.