Lighthouse: Subscription with multiple root fields should not be allowed

Created on 14 Apr 2020  路  5Comments  路  Source: nuwave/lighthouse

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

bug

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

basudebpalfreelancer picture basudebpalfreelancer  路  4Comments

wimski picture wimski  路  3Comments

Leuloch picture Leuloch  路  3Comments

m1guelpf picture m1guelpf  路  3Comments

souljacker picture souljacker  路  3Comments