Subscription types incompatible with graphql-subscription's PubSub
See original GitHub issueThe 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:
- Created 2 years ago
- Reactions:15
- Comments:8
Top 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 >
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

@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
In the meantime you could use something like this: