First of all, Subscriptions is working if I have next code structure
schema
type Subscription {
somethingChanged: IResult
}
type IResult {
id: String!
}
resolvers
export const resolvers = {
Query: {
},
Mutation: {
},
Subscription: {
somethingChanged: {
subscribe: () => pubSub.asyncIterator(SOMETHING_CHANGED_TOPIC)
}
},
};
The problem became be a problem when I try to make somethingChanged
node as a child of another account
node, like so:
So next schema and resolvers are not working
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
{ "error": { "message": "Subscription field must return Async Iterable. Received: undefined" } }
I believe that is not an issue and only misunderstanding )) Please help me ))
Additional info which might help:
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}`);
});