-
Notifications
You must be signed in to change notification settings - Fork 2k
Please make subscription value structure consistent with query value structure #1433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jedwards1211 It's actually very consistent with Actually, it's so consistent with a query that if you register |
Oh. Is this documented anywhere? |
I thought the resolution was just happening on the types of objects I yield, not the root query. Is there an example of what would actually be the point of having a resolve next to subscribe on foo? |
It's documented in GraphQL specification:
From the top of my head:
|
Okay, great! So to be clear what you really mean by
Is really:
i.e., the value you yield is resolved against the |
Yes exactly. |
I meant |
Okay, makes sense. Thanks! |
You know, now that I think about this, I kind of wish I could yield a root value for the |
@jedwards1211 Not sure it's a good idea but nothing prevents you from doing: type Query {
foo(tag: String): MetadataItem
}
type Subscription {
foo(tag: String): Query
} |
@jedwards1211 Not sure about Apollo but in Relay caching is based on object ID so it should be updated automatically without requiring matching path in a query. |
Oh I see, good point. |
Nevermind, I misunderstood my own code 😅 |
@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:
I am using Apollo's |
So imagine the following basic schema:
My resolver for
Query.foo
can return aPromise<MetadataItem>
.You would think my
subscribe
resolver could return anAsyncIterable<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.
The text was updated successfully, but these errors were encountered: