подписки на GraphQl с дочерними узлами, кажется, не работают для меня - PullRequest
0 голосов
/ 02 июня 2019

Прежде всего, подписки работают, если у меня есть следующая структура кода

схема

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)
         }
      })
   },
};

ОШИБКА

{"error": {"message": "Поле подписки должно возвращать Async Iterable. Получено: undefined "}}

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}`);
});
...