Please make subscription value structure consistent with query value structure
See original GitHub issueSo imagine the following basic schema:
type Query {
foo(tag: String): MetadataItem
}
type Subscription {
foo(tag: String): MetadataItem
}
My resolver for Query.foo can return a Promise<MetadataItem>.
You would think my subscribe resolver could return an AsyncIterable<MetadataItem>.
But noooo…
For whatever reason it has to return an AsyncIterable<{foo: MetadataItem}>.
Why do I have to wrap the values I yield in an object?
Is there a good reason for this or is it just a mistake?
This is really annoying and it always trips me up. Why were subscriptions designed this way instead of being more consistent with queries? I feel very angry about how often I have had to debug issues stemming from this, because it’s just not an intuitive inconsistency. It’s very easy to forget about.
GraphQL could so easily wrap the values I yield in an object with the field name, the only reason I can imagine that it doesn’t is some performance nitpick.
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (6 by maintainers)

Top Related StackOverflow Question
@jedwards1211 It’s actually very consistent with
queryif you have the right mental model. You yield root value for the entire query (not just forfoofield) and then it executing exactly the same as a query: http://facebook.github.io/graphql/June2018/#ExecuteSubscriptionEvent()Actually, it’s so consistent with a query that if you register
resolveonSubscription.fooit would be called with the value you yielded from your stream.@IvanGoncharov I still find this terribly confusing.
Although this doesn’t seem to the behavior described in the spec, from what I’m observing with running code, it appears that:
subscribehas a siblingresolvefunction, thensubscribecan yield just the value of its field without any wrapper object?subscribehas to yield an object corresponding to the shape of theSubscriptiontypeI am using Apollo’s
buildExecutableSchemaso maybe the confusion’s coming from there…