Skip to content

Async parseValue resolver does not provide promise resolution value #2758

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

Closed
newhouse opened this issue Aug 26, 2020 · 2 comments
Closed

Async parseValue resolver does not provide promise resolution value #2758

newhouse opened this issue Aug 26, 2020 · 2 comments
Labels

Comments

@newhouse
Copy link

In graphql v15.3 we've recently re-written our resolver for a custom type to be something like this:

new GraphQLScalarType({
  name: 'MyThing',
  parseValue: async (value) => {
    return {foo: 'bar'}
  }
  ...
})

In code that handles a mutation where a MyThing is passed, it's coming out as an unresolved promise, like so:

// myThing was defined as type MyThing

console.log(myThing) // => Promise { { foo: 'bar' } } }

console.log(await myThing) // => { foo: 'bar' }

I'd like to not have to await myThing every time I want to use it, and the following comment suggests that the resolution values of async/promise-returning parseValue will be what the user gets to work with:

If a Promise is returned from a resolver, the executor will wait on that value to resolve before continuing.

Originally posted by @leebyron in #820 (comment)

Am I misunderstanding this comment? Or is this not how it's supposed to work? Or is it a bug?

@danielrearden
Copy link
Contributor

The comment you linked concerns resolving field values. Scalars do not have resolvers. They just have methods that parse values when they are submitted as inputs and serialize values when they are returned as outputs. These methods should not be asynchronous as discussed here.

@newhouse
Copy link
Author

Somehow I missed that issue when searching before posting...it's very helpful. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants