Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Resolvers plugin doesn't allow null to be returned from a promise #6173

Open
Tracked by #8296 ...
timothyarmes opened this issue Jun 23, 2021 · 2 comments
Open
Tracked by #8296 ...
Labels
core Related to codegen core/cli stage/0-issue-prerequisites Needs more information before we can start working on it

Comments

@timothyarmes
Copy link

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<ResolverTypeWrapper<SubscriptionDetails>>

So I can return null immediately (thanks to the Maybe), but if I return a Promise then I have to return ResolverTypeWrapper<SubscriptionDetails>, which is defined as:

export type ResolverTypeWrapper<T> = Promise<T> | 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<ResolverTypeWrapper<Maybe<SubscriptionDetails>>>

@dotansimha
Copy link
Owner

Hi @timothyarmes and thank you for the report!

Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow.

It seems like we are on stage 0.
Now in order to advance to stage 1 we'll need an easily running reproduction, do you think you can create that on code sandbox?

Thank you and sorry that this comment is not a complete solution (yet).

@dotansimha dotansimha added the stage/0-issue-prerequisites Needs more information before we can start working on it label Jun 29, 2021
@jonparkdev
Copy link

@timothyarmes I've run into this too. Did you find out any more information about this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli stage/0-issue-prerequisites Needs more information before we can start working on it
Projects
None yet
Development

No branches or pull requests

4 participants