graphql-subscriptions: Subscription field must return Async Iterable. Received: undefined
We are trying to get the resolver for a subscription working in Apollo Server. The subscription works when it is a top-level field (i.e. directly under Subscription at the schema root).
However, if the subscription is contained within another type, I always get the error Subscription field must return Async Iterable. Received: undefined on the client’s websocket connection – the server’s resolver is never executed.
i.e. this schema works:
type Subscription {
postAdded: Post
}
but this one does not:
type Subscription {
post: PostSubscription
}
type PostSubscription {
postAdded: Post
}
My resolver for the second case looks like this, but I’ve tried a bunch of different variations with no success:
Subscription: {
post: () => ({
PostSubscription: {}
})
},
PostSubscription: {
postAdded: {
subscribe: () => pubSub.asyncIterator(['postAdded'])
}
}
Maybe relevant package versions:
"apollo-server-express": "1.3.6",
"apollo-server-module-graphiql": "1.3.4",
"graphql-subscriptions": "0.5.8",
"graphql": "0.13.2",
P.s.: Maybe unrelated, but just in case, this reminds me of https://github.com/yarax/swagger-to-graphql/commit/fa1000accd046b5db9f5d973e2e120c3f658f3b6#diff-6d186b954a58d5bb740f73d84fe39073L54
Clone of: https://stackoverflow.com/questions/51862571/apollo-server-subscription-nested-within-a-type
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 12
- Comments: 36 (10 by maintainers)
Hi @builtbyproxy
No, I have my resolvers (and schema) separated by small files. In the case of resolvers, they are javascript files, with a final
export default resolvers;
, and that’s the line I had forgotten.I’ll show the code just in case:
@iamcristos more less check have you export subscription and you don’t use nested types for subscription 😃 read that thread carefully 😉
I somehow miss the answer of 4F2E4A2E’s initial question. Is there a support of subscriptions in subfields (non root subscriptions)? Do I overlook something?
Upon staring at these resolvers - it’s not clear to me why this is actually supposed to work.
foo
needs to be an object with aresolve
and asubscribe
field - instead right now it’s returning a{ fooObj: true }
.I tried to fix up your resolvers into something that I think approximates what you want. Here it is: https://github.com/grantwwu/graphql-nested-subscriptions/compare/grantwu_fixed~...grantwwu:grantwu_fixed
(Note that I also made some formatting changes, as well as updating your dependencies when I was ruling that out as a bug).
I have some time now and I’m a bit confused - @builtbyproxy @abelosorio were you working on the same issue as OP? @RedShift1 are you still having issues?
@abelosorio by final export are you talking about:
or something else?