Subscriptions do not work with asynchronous resolver function
See original GitHub issueI noticed that the subscribe function does not work properly when it is used with an asynchronous field resolver function.
Also, there is no unit test for this case. This is what I have in mind (must be added to subscribe-test.js):
it('should work with an asynchronous resolver', async () => {
const asyncEmailSchema = emailSchemaWithResolvers(
async function*() {
yield { email: { subject: 'Hello' } };
},
async function*(email) { // <-- this currently does not work
return email;
},
);
const subscription = await subscribe(
asyncEmailSchema,
parse(`
subscription {
importantEmail {
email {
subject
}
}
}
`),
);
const payload = await subscription.next();
expect(payload).to.deep.equal({
done: false,
value: {
data: {
importantEmail: {
email: {
subject: 'Hello',
},
},
},
},
});
expect(await subscription.next()).to.deep.equal({
done: true,
value: undefined,
});
});
Is this an oversight? Or am I doing something stupid or against the spec? As far as I see the ResolveFieldEventStream section says nothing about whether the resolver function can be asynchronous, so I am assuming that is allowed, just at it is for resolver function used for normal queries, and as far as I understand it is intended that they are compatible.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Subscriptions in Apollo Server - Apollo GraphQL Docs
The subscribe function must return an object of type AsyncIterator , a standard interface for iterating over asynchronous results. In the above postCreated....
Read more >GraphQL Subscription fields not able to access context of ...
I don't get an error if I use the subscription without the postedBy field. I can only assume that the undefined object is...
Read more >Execution - GraphQL
A resolver function receives four arguments: obj The previous object, which for a field on the root Query type is often not used....
Read more >Subscriptions | NestJS - A progressive Node.js framework
GraphQL subscriptions are a way to push data from the server to the clients that choose ... To mutate the published payload, we...
Read more >Wiring up subscriptions for GraphQL remote schema stitching
Let's now create a new async function called getRemoteSchema where we can create our ... your subscriptions that delegate to remote services will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I might be mistaken, but is this Issue not somewhat similar to Issue #1537 ? After kind and clarifying feedback from @Cito it became clear that indeed the above is a different Issue.
Is the old problem that generators return values are a separate beast from the yielded payloads?