-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscription types incompatible with graphql-subscription's PubSub #7197
Comments
I do habe the same problem ... any recommendations? |
I also have this same issue. import { SubscriptionResolvers } from '../../generated/graphql'
import { Context } from '../context'
export const NEW_POINT = 'NEW_POINT'
export const Subscription: SubscriptionResolvers<Context> = {
newPoint: {
subscribe: (_,__,context) => context.pubsub.asyncIterator(NEW_POINT)
},
} I can get the subscription to work if I alter the Graphql Codegen type file to accept 'AsyncIterator<unknown, any, undefined>' This is not a fix I still need to understand how to get it to work without altering the code manually. |
#7015 (comment) |
@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? apollographql/graphql-subscriptions#250 |
In the meantime you could use something like this: subscribe: () => ({
[Symbol.asyncIterator]: () => pubsub.asyncIterator<{ numberIncremented: number }>('NUMBER_INCREMENTED'),
}), |
@Mad-Kat This would be a working, but rather an ugly workaround. You should not tailor your code and add overhead for pleasing a library with wrong typings. I recommend everyone to read through #7015 for a full breakdown of the situation and migrate off graphql-subscriptions or use the mentioned patch-package for fixing the typings. |
Any updates? |
I will close this issue as there is nothing wrong within graphql-code-generator. |
Workaround proposed in above #7197 (comment) with import { withFilter } from 'graphql-subscriptions';
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => ({
[Symbol.asyncIterator]: withFilter(
(_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}.${args.relevantId}`),
(payload, variables: SubscriptionSomethingChangedArgs) => payload.somethingChanged.id === variables.relevantId,
),
}),
},
},
} |
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#L8AsyncIterable
andAsyncIterator
types are incompatible.Example (this code will throw a type error):
What's the recommended workaround for this issue?
The text was updated successfully, but these errors were encountered: