带有子节点的graphql订阅似乎对我不起作用

时间:2019-06-02 20:41:34

标签: node.js graphql apollo-server graphql-subscriptions

首先,如果我具有下一个代码结构,则订阅工作正常

模式

type Subscription {
   somethingChanged: IResult
}
type IResult {
   id: String!
}

解析器

export const resolvers = {
   Query: {
   },
   Mutation: {
   },
   Subscription: {
      somethingChanged: {
         subscribe: () => pubSub.asyncIterator(SOMETHING_CHANGED_TOPIC)
      }
   },
};

enter image description here

当我尝试将somethingChanged节点设为另一个account节点的子节点时,问题就变成了问题,就像这样:

因此下一个架构和解析器不起作用

type Subscription {
   account(token: String!): IAccountAction
}
type IResult {
   id: String!
}
type IAccountAction {
   somethingChanged: IResult
}
export const resolvers = {
   Query: {
   },
   Mutation: {
   },
   Subscription: {
      account: (root: any, token: string) => ({
         somethingChanged: {
            subscribe: () => pubSub.asyncIterator(SOMETHING_CHANGED_TOPIC)
         }
      })
   },
};

错误

  

{     “错误”:{       “ message”:“订阅字段必须返回异步可迭代。已接收:未定义”     }   }

enter image description here

我相信这不是问题,只是误会))请帮助我))


其他信息可能会有所帮助:

server.ts

import {resolvers} from './generated/resolvers';
import {typeDefs} from './generated/mergedGQLSchemas';
import http from 'http';

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

const PORT = 4001;

const app = express();

const server = new ApolloServer({
   typeDefs,
   resolvers,
});

server.applyMiddleware({
   app
});

const httpServer = http.createServer(app);
server.installSubscriptionHandlers(httpServer);

httpServer.listen(PORT, () => {
  console.log(`? Server ready at http://localhost:${PORT}${server.graphqlPath}`);
  console.log(`? Subscriptions ready at ws://localhost:${PORT}${server.subscriptionsPath}`);
});

0 个答案:

没有答案