Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The significance of the string immediately after query type (query / mutation) GraphQL

I was wondering what the significance of the string that follows the query type, in this case "ProvisionQueues", it seems removing this from the string doesn't affect anything - is it just for logging or something. meta data?

mutation ProvisionQueues {
 createQueue(name: "new-queue") {
    url
  }
}
like image 666
Melbourne2991 Avatar asked Mar 13 '16 09:03

Melbourne2991


1 Answers

That string is the operation name. If you don't specify a name, the operation is known as an anonymous operation. When practical I like to always specify an operation name though, because it makes it easier for doing things like reading stack traces.

it seems removing this from the string doesn't affect anything

You can only use an anonymous operation when you are performing a single operation. For instance, the following results in an error:

query {
  user(id: 1) {
    name
  }
}

query {
  user(id: 2) {
    name
  }
}

The error:

"message": "This anonymous operation must be the only defined operation."

If you want to learn more, you can check out the GraphQL spec:

If a document contains only one operation, that operation may be unnamed or represented in the shorthand form, which omits both the query keyword and operation name. Otherwise, if a GraphQL query document contains multiple operations, each operation must be named.

like image 142
Eric Streeper Avatar answered Oct 10 '22 23:10

Eric Streeper