-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Subscriptions RFC: Should the "event stream" be derived only from the root field? #282
Comments
Depending on the resulution of #284 (subscriptions vs. live queries), I think only allowing the event stream to be derived from the root field parameters would be an important way to make the distinction. Knowing that you are going to get the same set of events regardless of the query passed in allows you to have more understanding of the system you're calling into, and means you can refactor your client code at will, for example by moving some of the fields into a follow-up query. Most arguments for including information about the whole query/selection set I've seen so far involve building a live-query like system on top of subscriptions - people are suggesting that you might want to receive updates based on the fields you asked for, which seems to break my understanding of the fundamentals of the system. |
IMO the nicest way to write the spec has things just work out this way. I take back what I said about live queries. |
A worthwhile detail from dshafer's comment:
(emphasis mine) In light of that, these two subscriptions may receive different events: # Pushed only when a new comment is left on Post #4
subscription {
commentCreated(postId: 4) {
# ...
}
} # Pushed only when a new comment is left on Post #5
subscription {
commentCreated(postId: 5) {
# ...
}
} |
I this is quite an import aspect, as dshafer pointed in in his comment. Given this schema: type Subscription {
a: A
b: B!
c(d: D): Int!
} and following query subscription {
a {a1, a2}
b {b1, b2}
c(d: {foo: BAR})
} Here are several questions I was struggling with:
|
My personal take on it :)
What do you think? |
Might be useful to generate some marble diagrams for some of these (or in the short term repurpose existing ones). Re 4/6 the choice can be rendered as the distinction between Is subscription muxing and demuxing (cf queries in relay and apollo) important at this layer? I imagine it should be an overlay to the base subscription mechanism. |
@OlegIlyenko I differ on some of these points. Mainly the null/not null stuff.
|
So I guess it's actually "yes" since they share a common property: they represent event types :) Do I understand it correctly? The question was more about semantic similarities rather than a relation between values during the runtime.
a very good point! I guess I got a bit confused along the way :) I added 8 in an edit mostly because I thought that Regarding nullable vs not-null. I don't hold a strong opinion on this one per se. I just wonder how it will interact with the fact that we now have 2 sources of field omission/
I think I'm also ok with defining it like this:
Though it would look a bit strange when
I'm not sure about this one. I feel that this aspect has deeper implications on subscription semantics. |
I think this conversation about multiple root fields and null should happen on a separate issue IMO |
The “no” was mostly directed at the serial execution bit at the end of point 1 😊
I like this as well 👍
Yeah, you’re right. I saw JSON and immediately jumped to the conclusion that it is a serialization concern 😊 I think it’s limiting to think about subscription responses purely in the context of the current response format. Let’s see if we can think of something else that better fits the subscription case. I’m not sure that I like {
"event": "a",
"data": { "a1": "foo", "a2": "bar" }
} {
"event": "b",
"data": { "b1": "baz", "b2": null }
} This enforces only one event per message. |
Another thought is that the subscriptions grammar should be customized to only allow fields and not other selections like inline fragments or fragment spreads. For example:
|
Ah, I see. Sorry, I was more focused on meaning of the field rather them execution characteristics :)
I haven't thought about it. It's definitely something worth considering. What is your reasoning for disallowing inline fragments and fragment spreads? @stubailo Indeed, I agree. It looks like these two points are relatively independent and can be discussed separately. |
It would enforce a few properties about subscriptions:
It may even be worth extending this argument for mutations as well. A more thorough approach then only allowing What do you think? I haven’t thought much about this idea either so I’m developing it on the fly 😊 |
That's a good point as well that it might be worth specifying that no field can return the Subscription type. |
@calebmer Thanks a lot for detailed explanation! And I'm sorry for the late reply. I definitely don't want to discard this idea, but I have some concerns:
@stubailo @calebmer Indeed, It's good point. I feel that may be even necessary for subscription type since it's semantics is quite different from anything else. Maybe it would be an option to introduce it for mutations as well, though I wonder whether it can be just a linting/optional validation rule in case of mutations. I wonder what are the use-cases for mutation/query/subscription type as a return type of a field |
@OlegIlyenko I don’t feel super strong on the mutation and subscriptions are not root objects point, and it kind of derails from the original discussion. We may want to separate into another own issue if the idea is worth exploring. At a high level I do agree though that the simplicity of the language is incredibly important, but it may actually be simpler to add special semantics for root mutations and subscriptions instead of adding special cases to object types which people may want to extend to other object types that are not root mutations or subscriptions (see #252). Instead of changing GraphQL syntax we should just be able to do this with a validation rule. As for the original question, I don’t think there is any disagreement that the specification should require subscription events to be exclusively derived from the root field. Correct @robzhu? |
Updated the RFC text to describe this more clearly: #304 |
The "event stream" should be derived purely from the subscription root field (and ignore selection set).
@dschafer @leebyron @rmosolgo @taion @OlegIlyenko @stubailo
Continuing the conversation from: #267 (comment)
The text was updated successfully, but these errors were encountered: