Multiple subscription operations in document

@benwilson512

I’m trying to understand the following sentence from the GraphQL spec:

While each subscription must have exactly one root field,
a document may contain any number of operations,
each of which may contain different root fields.
When executed, a document containing multiple subscription
operations must provide the operation name as described in GetOperation().

I understand that a subscription operation can only have one root level field, but I interpret the above to mean that a document can have multiple subscription operations. Therefore, I expected the following to work (pseudo code naming below):

        subscription EntityCreated {
          entityCreated(input: {someField: 123}) {
              entity {
                id
              }
          }
        }
        subscription OtherEntityCreated {
             otherEntityCreated(input: {someField: 456}) {
              entity {
                id
              }
          }
        }

But I’m getting the following error: "Must provide a valid operation name if query contains multiple operations.\n\nNo operation name was given.\n". I’m encountering this error with both assert_reply and assert_push using the document above.

What am I missing? It seems I’m including two unique operation names, EntityCreated and OtherEntityCreated.

Hi @michaelcaterisano a document can contain multiple operations, but only one will be executed for any given invocation of that document. You have to supply an operation name parameter when you provide multiple operations to let your GraphQL server know which of the available operations to perform.

@benwilson512 Gotcha. Do you know if operationName supports a list of operations? I’m not sure how to interpret this:

  • If operationName exists
    • Let operations be all operation definitions in the document named operationName.
    • operations must be a set of one.

No, the whole idea is that you’re doing exactly one operation per invocation.