订阅字段必须 return Async Iterable。收到:未定义

Subscription field must return Async Iterable. Received: undefined

我将 graphql nodejs 与 apollo-server 一起使用。 当我尝试时出现此错误:

我已经 returns pubsub.asyncIterator 在解析器中。 它 returns 错误。另一个项目相同的设置有效,但它不工作。我在这里检查了一些堆栈问题,但我无法解决。

服务器: App.js

const express = require('express');
const mongoose = require('mongoose');
const { ApolloServer } = require('apollo-server');


const { mainSchema } = require('./graphql/schemas/index');
const { rootResolver } = require('./graphql/resolvers/index');

const app = express();


const server = new ApolloServer({
typeDefs: mainSchema,
resolvers: rootResolver,
subscriptions: {
         path: `/graphql`,
         onConnect: (connectionParams, webSocket, context) => {
         console.log('Client connected');
},
onDisconnect: (webSocket, context) => {
         console.log('Client disconnected')
    },

  },
});

server.listen(3000, "192.168.1.106").then(({ url }) => {
console.log(`  Server ready at ${url}`);
});

订阅解析器

    Subscription :{
    userNotifications : withFilter(
            ()=>pubSub.asyncIterator(NEW_NOTIFICATION_CREATE),
            (payload, variables)=>{
                console.log("payload=>", payload);
                console.log("variables=>", variables);
                return true
            }
        )}}

PubSub.js

  const { PubSub } = require('graphql-subscriptions')

  const pubSub =new PubSub()

  exports.pubSub = pubSub;

我必须为 subs 定义使用 subccribe 关键字。谢谢我。 订阅:{ 用户通知:withFilter( 订阅:()=>pubSub.asyncIterator(NEW_NOTIFICATION_CREATE), (有效载荷,变量)=> { console.log("有效载荷=>", 有效载荷); console.log("变量=>", 变量); return 是的 } )}}