-
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
RFC: __typename is not valid at subscription root #776
Conversation
Exception doesn't need to be as prominent since this sentence first introduces the idea of Validation rule should change to "one non introspection field" Example that needs to change https://spec.graphql.org/draft/#example-2353b |
GraphQL.js PR here: graphql/graphql-js#2861 |
It would be helpful I think if this would be valid to allow for a completely typed result to be passed to result transformers. Otherwise result transformers have to be passed additional state in terms of which operation type was sent and treat the data field differently than inner fields during processing, at least for subscriptions. |
Of course, you can save the request document and add __typename to all abstract fields and then combine request and result to know types of everything, including subscription root. That is another way. But seems like this way should also be allowed to work in terms of symmetry of the root types. |
Of course, then you need to repeat the same field collection algorithm that happened during field resolution on the server when processing the result, so we currently do that in graphql-tools only when we need to know the types of scalar fields. Perhaps a generic solution would be to annotate fields using aliases that would include the typename, that is yet another option, just would be easier I think if all of these options worked... |
@benjie I still think we need to allow adding
|
FWIW I checked how graphql-ruby handles this, and it Just Works (I suppose in contravention of the spec). If you put a |
@IvanGoncharov I've written up a solution that follows your suggestion (and might be how I'm on the fence between these two solutions. In general I'm leaning towards the simplicity of this one ("there can only be one field, and it can't be __typename") but #806's expansion of My main hesitation against #806, beyond complexity, is that it feels like it's going to make the "subscriptions must only have one root-level field" rule muddier ("if we can have a normal field and an introspection field, why can't we have another normal field?"). Interestingly if we merged this PR, we could later merge #806 and it would be a non-breaking change (an expansion of capabilities). Both invalidate the operation |
Looks like some of this language already leaked in via editorial changes in #844 - https://spec.graphql.org/draft/#sel-FAJZDABzCBjF8wX |
I think this is fine to merge, it doesn't prevent us changing our mind in future 👍 One caveat: I think graphql-ruby (?) allows |
I know PR is still in review. The implementation there may change but the test suite looks 👌. I think we're good here to go to RFC 3:
|
I'm writing up some of the GraphQL "query ambiguity" work currently and noticed this issue in the spec. In the case of a subscription it seems that
does not correctly get evaluated by the reference implementation during subscriptions (though you can query it with
graphql(...)
you can't access it viasubscribe(...)
). It doesn't really make sense to request__typename
here since it's not ever going to change during the life of the schema, and subscriptions only support one root-level field, however I thought it was worth highlighting.Reproduction with GraphQL-js (toggle which
doc
is commented to see a functioning subscription):Produces this error: