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

Replace Promise with PromiseLike in resolver types #6378

Open
qsona opened this issue Jul 29, 2021 · 4 comments
Open

Replace Promise with PromiseLike in resolver types #6378

qsona opened this issue Jul 29, 2021 · 4 comments
Labels
core Related to codegen core/cli help wanted Extra attention is needed kind/enhancement New feature or request

Comments

@qsona
Copy link

qsona commented Jul 29, 2021

Is your feature request related to a problem? Please describe.

When using non-native Promise library like Bluebird, the return type of resolvers will often be PromiseLike, but it doesn't adapt with generated resolver-types because the generated code is using native Promise type.

sample code:

const resolvers: Resolvers = {
  Query: {
    name: () => { // string field
      return Promise.resolve('1') as PromiseLike<string>
    }
  }
}

error message:

(...omitted)
    Type 'PromiseLike<string>' is not assignable to type 'ResolverTypeWrapper<string> | Promise<ResolverTypeWrapper<string>>'.
      Type 'PromiseLike<string>' is missing the following properties from type 'Promise<ResolverTypeWrapper<string>>': catch, finally, [Symbol.toStringTag]

Describe the solution you'd like

Can Promise be just replaced with PromiseLike?

📝 https://github.com/graphql/graphql-js/blob/0fef3c49907b63b1ea5a4ff1da7011775f465fc2/src/execution/execute.ts#L505-L506

Describe alternatives you've considered

We can customize it by using customResolverFn.

So this feature request is not mandatory, but I feel it's better if I don't have to customize and manage it in our code.

Additional context

@dotansimha
Copy link
Owner

Hi @qsona ! This is a great idea. What do you think about creating a PR for this? :)

@dotansimha dotansimha added help wanted Extra attention is needed kind/enhancement New feature or request labels Aug 3, 2021
@qsona
Copy link
Author

qsona commented Aug 6, 2021

Yes, I'd like to try this :)

@qsona
Copy link
Author

qsona commented Sep 3, 2021

I realized it's necessary to clarify if graphql-js expects PromiseLike value as resolver's return value. I'm waiting and seeing the discussion on graphql-js.
graphql/graphql-js#3243 (review)

@qsona
Copy link
Author

qsona commented Jan 8, 2022

Hi, I'm sorry for not updating this long time. My idea was simply replacing Promise with PromiseLike (firstly in graphql-js firstly, then this repository) but it seems it needs some works to be accepted in graphql-js. Actually I'm not so enthusiastic for this issue (because casting PromiseLike to Promise is easy by using async-await) so please feel free to close this issue and PR.

@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
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 help wanted Extra attention is needed kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants