Skip to content

Commit

Permalink
[RFC] Make operation name optional.
Browse files Browse the repository at this point in the history
Based on feedback from those using GraphQL and inspired by RelayQL's syntax, this makes operation names optional.

The primary value is the ability to express mutations (or eventually subscriptions) without being required to provide a name if the name adds no value for your use case. (Value typically being query disambiguation and logging). Systems which want to enforce a name for queries should have a separate linting/validation rule - such a rule would probably also want to ban "query shorthand"
  • Loading branch information
leebyron committed Oct 1, 2015
1 parent 139a0a0 commit 02af0fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/Appendix B -- Grammar Summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Definition :

OperationDefinition :
- SelectionSet
- OperationType Name VariableDefinitions? Directives? SelectionSet
- OperationType Name? VariableDefinitions? Directives? SelectionSet

OperationType : one of query mutation

Expand Down
21 changes: 17 additions & 4 deletions spec/Section 2 -- Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ contain an operation. However documents which do not contain operations may
still be parsed and validated to allow client to represent a single request
across many documents.

If a query document contains only one query operation, that operation may be
represented in the shorthand form, which omits the query keyword and
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. When submitting a query document with
multiple operations to a GraphQL service, the name of the desired operation to
Expand All @@ -189,7 +189,7 @@ be executed must also be provided.
### Operations

OperationDefinition :
- OperationType Name VariableDefinitions? Directives? SelectionSet
- OperationType Name? VariableDefinitions? Directives? SelectionSet
- SelectionSet

OperationType : one of `query` `mutation`
Expand All @@ -199,7 +199,20 @@ There are two types of operations that GraphQL models:
* query - a read-only fetch.
* mutation - a write followed by a fetch.

Each operation is represented by an operation name and a selection set.
Each operation is represented by an optional operation name and a selection set.

For example, this mutation operation might "like" a story and then retrieve the
new number of likes:

```
mutation {
likeStory(storyID: 12345) {
story {
likeCount
}
}
}
```

**Query shorthand**

Expand Down

0 comments on commit 02af0fd

Please sign in to comment.