I'm trying go use subscriptions in graphql, but I'm receiving this weird error:
subscription {
notification {
type
message
}
}
I'm using import { PubSub } from "graphql-subscriptions";
import { Inject } from "@nestjs/common";
import { Resolver, Subscription } from "@nestjs/graphql";
import { PubSub } from "graphql-subscriptions";
import { Notification } from "./models/notification";
@Resolver(() => Notification)
export class NotificationResolver {
constructor(@Inject('PUB_SUB') private pubSub: PubSub) {}
@Subscription(() => Notification, {
resolve: (payload) => payload?.notification || {}
})
notification() {
return this.pubSub.asyncIterator('notification');
}
}
Error:
{ "error": { "message": "Subscription field must return Async Iterable. Received: { pubsub: { ee: [Object], subscriptions: {}, subIdCounter: 0 }, pullQueue: [], pushQueue: [], running: true, allSubscribed: null, eventsArray: [\"notification\"] }." } }
I tryied to use, but the error was the same:
subscriptions: {
'graphql-ws': true
},
For people who are still experiencing this problem. My problem was caused by the global interceptor:
ClassSerializerInterceptor
.When you disable that in
main.ts
: