Skip to content

Commit 88c47a8

Browse files
committed
Refactor description section for clarity
Also: - add color to operation description example and counter-example - add descriptions in operation examples throughout section 2
1 parent 1a1a4b3 commit 88c47a8

File tree

1 file changed

+59
-28
lines changed

1 file changed

+59
-28
lines changed

spec/Section 2 -- Language.md

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -291,53 +291,76 @@ Descriptions may appear before:
291291
- Fragment definitions.
292292
- Variable definitions within operation definitions.
293293

294-
Descriptions are not permitted on the shorthand form of operations (e.g.,
295-
`{ ... }`).
296-
297-
Note: Descriptions and comments in executable GraphQL documents are purely for
298-
documentation purposes. They MUST NOT affect the execution, validation, or
299-
response of a GraphQL document. It is safe to remove all descriptions and
300-
comments from executable documents without changing their behavior or results.
301-
302294
Example:
303295

304296
```graphql example
305-
"Some description"
306-
query SomeOperation(
307-
"ID you should provide"
308-
$id: String
297+
"""
298+
Request the current status of a time machine and its operator.
309299
310-
"Switch for experiment ...."
311-
$enableBaz: Boolean = false,
300+
This operation retrieves the latest information about a specific time machine,
301+
including its model, last maintenance date, and the operator currently assigned.
302+
303+
You can also check the status for a particular year, to see if the time machine
304+
was scheduled for travel or maintenance at that time.
305+
"""
306+
query GetTimeMachineStatus(
307+
"The unique serial number of the time machine to inspect."
308+
$machineId: ID!
309+
310+
"""
311+
The year to check the status for.
312+
**Warning:** Requesting status information for certain years may trigger an anomaly in the space-time continuum.
313+
"""
314+
$year: Int
312315
) {
313-
foo(id: $id) {
314-
bar
315-
baz @include(if: $enableBaz) {
316-
...BazInfo
316+
timeMachine(id: $machineId) {
317+
...TimeMachineDetails
318+
operator {
319+
...OperatorDetails
317320
}
321+
status(year: $year)
318322
}
319323
}
320324

321-
"Some description here"
322-
fragment BazInfo on Baz {
323-
# ...
325+
"""
326+
Time machine details.
327+
"""
328+
fragment TimeMachineDetails on TimeMachine {
329+
id
330+
model
331+
lastMaintenance
332+
}
333+
334+
"""
335+
Basic information about a time machine operator.
336+
"""
337+
fragment OperatorDetails on Operator {
338+
name
339+
licenseLevel
324340
}
325341
```
326342

327-
Counterexample:
343+
Descriptions are not permitted on the shorthand form of operations:
328344

329345
```graphql counter-example
330-
"Descriptions are not permitted on the shorthand form of operations"
346+
"This description is invalid, because this is a shorthand operation definition"
331347
{
332-
foo {
333-
bar
334-
baz {
335-
...BazInfo
348+
timeMachine(id: "TM-1985") {
349+
status
350+
destination {
351+
year
352+
location
336353
}
337354
}
338355
}
339356
```
340357

358+
Note: Descriptions and comments in executable GraphQL documents are purely for
359+
documentation purposes. They MUST NOT affect the execution, validation, or
360+
response of a GraphQL document. It is safe to remove all descriptions and
361+
comments from executable documents without changing their behavior or results.
362+
363+
341364
## Operations
342365

343366
OperationDefinition :
@@ -361,6 +384,10 @@ For example, this mutation operation might "like" a story and then retrieve the
361384
new number of likes:
362385

363386
```graphql example
387+
"""
388+
Mark story 12345 as "liked"
389+
and return the updated number of likes on the story
390+
"""
364391
mutation {
365392
likeStory(storyID: 12345) {
366393
story {
@@ -633,6 +660,7 @@ query withFragments {
633660
}
634661
}
635662

663+
"""Common fields for a user's friends."""
636664
fragment friendFields on User {
637665
id
638666
name
@@ -1263,7 +1291,10 @@ In this example, we want to fetch a profile picture size based on the size of a
12631291
particular device:
12641292

12651293
```graphql example
1266-
query getZuckProfile($devicePicSize: Int) {
1294+
query getZuckProfile(
1295+
"""The size of the profile picture to fetch."""
1296+
$devicePicSize: Int
1297+
) {
12671298
user(id: 4) {
12681299
id
12691300
name

0 commit comments

Comments
 (0)