Skip to content

Commit 5e76745

Browse files
committed
clarify meaning and purpose of operation name
1 parent ac2f86e commit 5e76745

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,14 @@ query HeroNameQuery {
264264
}
265265
```
266266

267-
The initial line, `query HeroNameQuery`, says that we're running a query,
268-
and tells GraphQL to start with the schema's root query type; in this case,
269-
`Query`. As defined above, `Query` has a `hero` field that returns a
267+
The initial line, `query HeroNameQuery`, defines a query with the operation
268+
name `HeroNameQuery` that starts with the schema's root query type; in this
269+
case, `Query`. As defined above, `Query` has a `hero` field that returns a
270270
`Character`, so we'll query for that. `Character` then has a `name` field that
271271
returns a `String`, so we query for that, completing our query. The result of
272272
this query would then be:
273273

274+
274275
```json
275276
{
276277
"hero": {
@@ -279,6 +280,18 @@ this query would then be:
279280
}
280281
```
281282

283+
Specifying the `query` keyword and an operation name is only required when a
284+
GraphQL document defines multiple operations. We therefore could have written
285+
our the previous query with the query shorthand:
286+
287+
```
288+
{
289+
hero {
290+
name
291+
}
292+
}
293+
```
294+
282295
Assuming that the backing data for the GraphQL server identified R2-D2 as the
283296
hero. The response continues to vary based on the request; if we asked for
284297
R2-D2's ID and friends with this query:

Section 2 -- Language.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ name of the desired operation must also be provided.
3232

3333
If a document contains only one query operation, that operation may be
3434
represented in the shorthand form, which omits the query keyword and
35-
query name.
35+
operation name.
3636

3737
## Operations
3838

@@ -41,12 +41,12 @@ There are two types of operations that GraphQL models:
4141
* query - a read-only fetch.
4242
* mutation - a write followed by a fetch.
4343

44-
Each operation is represented by a custom name and a selection of fields.
44+
Each operation is represented by an operation name and a selection of fields.
4545

4646
**Query shorthand**
4747

48-
If a query has no variables or directives or name, the `query` keyword can be
49-
omitted. This means it must be the only query in the document.
48+
If a query has no variables or directives or name, the `query` keyword and name
49+
can be omitted. This means it must be the only query in the document.
5050

5151
Note: many examples below will use the query shorthand syntax.
5252

Section 6 -- Execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This section describes how GraphQL generates a response from a request.
66

77
To evaluate a request, the executor must have a parsed `Document` (as defined
88
in the “Query Language” part of this spec) and a selected operation name to
9-
run.
9+
run if the document defines multiple operations.
1010

1111
The executor should find the `Operation` in the `Document` with the given
1212
operation name. If no such operation exists, the executor should throw an

0 commit comments

Comments
 (0)