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.

Subscription types incompatible with graphql-subscription's PubSub

See original GitHub issue

The latest version of graphql-code-generator has changed the subscribe function return type to AsyncIterable<TResult> | Promise<AsyncIterable<TResult>>;

However, when using apollo’s graphql-subscriptions lib, the type returned from their pubsub-engine is AsyncIterator https://github.com/apollographql/graphql-subscriptions/blob/master/src/pubsub-engine.ts#L8

AsyncIterable and AsyncIterator types are incompatible.

Example (this code will throw a type error):

const pubsub = new PubSub();

const typeDefs = gql`
  type Subscription {
    root: String
  }
`

const resolvers: Resolvers = {
  Subscription: {
    root: {
      subscribe: () => {
        // Type 'AsyncIterator<unknown, any, undefined>' is not assignable to type 'AsyncIterable<any> | Promise<AsyncIterable<any>>'.
        return pubsub.asyncIterator('root');
      }
    }
  }
};

What’s the recommended workaround for this issue?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:15
  • Comments:8

github_iconTop GitHub Comments

3reactions
Urigocommented, Jan 2, 2022

@mpokrovsky I think graphql-subscriptions 3.0 might be happening soon and I think it includes the changes from @n1ru4l

Could you check if using the current state of their PR solves this issue? https://github.com/apollographql/graphql-subscriptions/pull/250

2reactions
Mad-Katcommented, Apr 13, 2022

In the meantime you could use something like this:

subscribe: () => ({
        [Symbol.asyncIterator]: () => pubsub.asyncIterator<{ numberIncremented: number }>('NUMBER_INCREMENTED'),
      }),
Read more comments on GitHub >

github_iconTop Results From Across the Web

Subscriptions in Apollo Server - Apollo GraphQL Docs
The subscription server (which we'll instantiate next) doesn't take typeDefs and resolvers options. Instead, it takes an executable GraphQLSchema .
Read more >
Graphql subscriptions for production pubsub - Reddit
I'm using Apollo with graphql for my app. For the chat feature of my app, I'm having issues in production with pubsub and...
Read more >
GraphQL Subscriptions in 2021 (The Backend) | by Doyun Kim
Let's say you want to set up graphql subscriptions on your express.js ... "description": "type-graphql subscription using apollo server",
Read more >
GraphQL Subscriptions is null using Express ... - Stack Overflow
The issue I am facing here is Subscription is not working properly and the data is always null. Can anyone help me to...
Read more >
Enhanced subscription filtering - AWS AppSync
The following sections explain how to configure enhanced subscription filters and show their practical use. Defining subscriptions in your GraphQL schema. To ...
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