Skip to content

Commit d81fd1e

Browse files
committed
Merge pull request #99 from facebook/optional-op-name
[RFC] Make operation name optional.
2 parents 139a0a0 + 02af0fd commit d81fd1e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

spec/Appendix B -- Grammar Summary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Definition :
9292

9393
OperationDefinition :
9494
- SelectionSet
95-
- OperationType Name VariableDefinitions? Directives? SelectionSet
95+
- OperationType Name? VariableDefinitions? Directives? SelectionSet
9696

9797
OperationType : one of query mutation
9898

spec/Section 2 -- Language.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ contain an operation. However documents which do not contain operations may
178178
still be parsed and validated to allow client to represent a single request
179179
across many documents.
180180

181-
If a query document contains only one query operation, that operation may be
182-
represented in the shorthand form, which omits the query keyword and
181+
If a document contains only one operation, that operation may be unnamed or
182+
represented in the shorthand form, which omits both the query keyword and
183183
operation name. Otherwise, if a GraphQL query document contains multiple
184184
operations, each operation must be named. When submitting a query document with
185185
multiple operations to a GraphQL service, the name of the desired operation to
@@ -189,7 +189,7 @@ be executed must also be provided.
189189
### Operations
190190

191191
OperationDefinition :
192-
- OperationType Name VariableDefinitions? Directives? SelectionSet
192+
- OperationType Name? VariableDefinitions? Directives? SelectionSet
193193
- SelectionSet
194194

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

202-
Each operation is represented by an operation name and a selection set.
202+
Each operation is represented by an optional operation name and a selection set.
203+
204+
For example, this mutation operation might "like" a story and then retrieve the
205+
new number of likes:
206+
207+
```
208+
mutation {
209+
likeStory(storyID: 12345) {
210+
story {
211+
likeCount
212+
}
213+
}
214+
}
215+
```
203216

204217
**Query shorthand**
205218

0 commit comments

Comments
 (0)