Considering the following thinned out schema:
"Example subscriptions"
type Subscription {
"Will broadcast 'pong' every minute."
ping: String
"Will broadcast an updated counter every second."
counter: Int
}
When executing the following query:
subscription sub {
ping
counter
}
No errors are givin and multiple subscribers and topics are created/populated.
Expected behavior/Solution
Query error. Only a single root field is allowed according to the GraphQL spec when requesting a subscription.
http://spec.graphql.org/June2018/#sec-Single-root-field
This seems like it could/should be solved upstream in https://github.com/webonyx/graphql-php
Probably yes.
I am looking into it but it looks like https://github.com/webonyx/graphql-php implemented only placeholders for the subscriptions and does not actually implement much concrete functionality, so I'm seeing if we or upstream should be responsible for this validation. Much code to go through both here and upstream 馃槃
I'll investigate a bit more to see if this needs to be reported and fixed upstream instead.
Those kinds of validations are usually implemented as Rule classes. Here is the implementation by graphql-js: https://github.com/graphql/graphql-js/blob/master/src/validation/rules/SingleFieldSubscriptionsRule.js
You can pretty much translate their implementation and tests and add a PR to webonyx, that usually goes quite smoothly.
Awesome, thanks for that info. That looks doable, going to give that a go.
I think I've done it. Will close this in favor of: webonyx/graphql-php#644.