question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subscriptions do not work with asynchronous resolver function

See original GitHub issue

I 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:open
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asishallabcommented, Oct 2, 2018

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.

0reactions
yaacovCRcommented, May 22, 2022

Is the old problem that generators return values are a separate beast from the yielded payloads?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found