Error in apollo-server-express: Subscription field must return Async Iterable. Received: undefined
See original GitHub issueI’m trying to implement subscriptions with apollo-server-express. From graphql-playground I receive the following error…
{
"error": {
"message": "Subscription field must return Async Iterable. Received: undefined"
}
}
Until now I had not had problems with queries and mutations. I also had no errors with subscriptions using apollo-server. But I do have them with apollo-server-express.
This is the code:
const {gql, ApolloError, PubSub} = require('apollo-server-express');
// Mongoose models
const NoteModel = require('../../mongoose/NoteModel');
// Instance PubSub (publications and subscriptions)
const pubsub = new PubSub();
// Subscriptions tags
const NOTE_ADDED = 'NOTE_ADDED';
// Type definitions define the "shape" of your data and specify
// which ways the data can be fetched from the GraphQL server.
const typeDefs = gql`
type Note {
_id: Int
title: String
description: String
}
input NoteInput {
title: String
description: String
}
# The "Query" type is the root of all GraphQL queries.
# Using extend is particularly useful in avoiding a large
# list of fields on root Queries and Mutations
# More info: https://www.apollographql.com/docs/graphql-tools/generate-schema#extend-types
extend type Query {
listNotes: [Note]
}
extend type Mutation {
addNote(input: NoteInput) : Note!,
updateNote(
id: Int!,
input: NoteInput
): Note!,
deleteNote(id: Int!): Boolean!
}
extend type Subscription {
noteAdded: [Note]
}
`;
const resolvers = {
Query: {
listNotes: async (parent, args, context, info) => {
}
},
Mutation: {
addNote: (parent, args, context, info) => {
pubsub.publish(NOTE_ADDED, { noteAdded: args.input });
return NoteModel.create(args.input);
},
updateNote: (parent, args, context, info) => {
},
deleteNote: (parent, args, context, info) => {
}
},
Subscription: {
noteAdded: {
subscribe: () => pubsub.asyncIterator([NOTE_ADDED]),
},
},
};
module.exports = {
typeDefs,
resolvers
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Subscription field must return Async Iterable. Received ...
We are trying to get the resolver for a subscription working in Apollo Server. The subscription works when it is a top-level field...
Read more >apollo "Subscription field must return Async Iterable. Received
I fixed this error by hardening imports (there was some issue w/ the index file not properly exporting). "message": "Subscription field must ......
Read more >Subscription field must return Async Iterable. Received
It means that somewhere, some piece of code expected an object to be an async iterable, but it was undefined instead :slight_smile:.
Read more >Subscriptions in Apollo Server - Apollo GraphQL Docs
The subscribe function must return an object of type AsyncIterator , a standard interface for iterating over asynchronous results. In the above postCreated....
Read more >Subscription field must return Async Iterable. Received
received : undefined. Add Answer | View In TPC Matrix. Technical Problem Cluster First Answered On August 31, 2021 Popularity 6/10 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
👋 I’ll close this since this doesn’t appear to be a bug with Apollo Server, but rather a question about how to use it or one of its components.
Rather than asking it here in GitHub Issues — where efforts are focused on fixing bugs and adding new features — I’d ask that you take this question to the Apollo Server channel within the Apollo community on Spectrum.chat where there are community members who might be able to relate to a similar problem, or might be able to help you out more interactively. Thanks for your understanding!
@abernix It is definitely a bug! And I did some investigation.
@LaurenceM10 wrote that it works with
new ApolloServer({ typeDefs, resolvers })
, but it does not withnew ApolloServer({ modules })
In my case it does not work with
new ApolloServer({ schema })
So, I found where the problem appears: http://center.koryagin.com/i/2019-08-04_00:29:39_6df691.png
And with this trivial monkey-patching everything is working, subscription messages arrive in browser.