apollographql / graphql-subscriptions

:newspaper: A small module that implements GraphQL subscriptions for Node.js
MIT License
1.59k stars 133 forks source link

withFilter does not wait for asyncIteratorFn to resolve #161

Closed ghost closed 6 years ago

ghost commented 6 years ago

In here, if asyncIteratorFn returns a promise it won't wait to resolve, and asyncIterator will just be a Promise. This causes it to fail:

  group: {
    subscribe: withFilter(async (_, args, context) => {
      const userId = await getUserId(context)

      return context.pubsub.asyncIterator('group')
    }, (...args) => { console.log(args); return true }),
  },

gives

/home/void/dev/homework-manager/backend-graphql-pure/node_modules/graphql-subscriptions/dist/with-filter.js:27
                    return asyncIterator.return();
                                               ^

TypeError: asyncIterator.return is not a function
grantwwu commented 6 years ago

Sorry, I misled you in the Slack - the interface doesn't allow you to return a promise there.

NeoPhi commented 6 years ago
group: {
  async subscribe(rootValue, args, context) {
    const userId = await getUserId(subscribeContext);
    return withFilter(() => context.pubsub.asyncIterator('group'), filter)(rootValue, args, context);
  },
},