Skip to content

Commit 9f7ec63

Browse files
committed
Updated spec wording for descriptions in executable documents
- Expanded the "Descriptions" section to clarify that descriptions may appear before operation definitions (full form only), fragment definitions, and variable definitions, but not on the shorthand form of operations. - Updated grammar summary and relevant sections to permit descriptions in these locations. - Added a normative note that descriptions and comments do not affect execution, validation, or response, and are safe to remove from executable documents. - Clarified and consolidated description rules in the type system section, referencing the normative rules in the language section and removing redundant statements. - Updated execution section to include a clear normative note about ignoring descriptions and comments during execution. - Ensured all changes are cross-referenced and consistent across the specification.
1 parent 5517373 commit 9f7ec63

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed

spec/Appendix B -- Grammar Summary.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ FragmentSpread : ... FragmentName Directives?
176176

177177
InlineFragment : ... TypeCondition? Directives? SelectionSet
178178

179-
FragmentDefinition : Description? fragment FragmentName TypeCondition Directives?
180-
SelectionSet
179+
FragmentDefinition : Description? fragment FragmentName TypeCondition
180+
Directives? SelectionSet
181181

182182
FragmentName : Name but not `on`
183183

@@ -215,7 +215,8 @@ ObjectField[Const] : Name : Value[?Const]
215215

216216
VariablesDefinition : ( VariableDefinition+ )
217217

218-
VariableDefinition : Description? Variable : Type DefaultValue? Directives[Const]?
218+
VariableDefinition : Description? Variable : Type DefaultValue?
219+
Directives[Const]?
219220

220221
Variable : $ Name
221222

spec/Section 2 -- Language.md

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,70 @@ be executed must also be provided.
279279

280280
Description : StringValue
281281

282-
Documentation is a first-class feature of GraphQL.
283-
GraphQL descriptions are defined using the Markdown syntax (as specified by
284-
[CommonMark](https://commonmark.org/)). Description strings (often {BlockString})
285-
occur immediately before the definition they describe.
282+
Documentation is a first-class feature of GraphQL. GraphQL descriptions are
283+
defined using the Markdown syntax (as specified by
284+
[CommonMark](https://commonmark.org/)). Description strings (often
285+
{BlockString}) occur immediately before the definition they describe.
286+
287+
Descriptions may appear before:
288+
289+
- Operation definitions (queries, mutations, subscriptions) in their full form
290+
(not the shorthand form).
291+
- Fragment definitions.
292+
- Variable definitions within operation definitions.
293+
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+
302+
Example:
303+
304+
```graphql
305+
"Some description"
306+
query SomeOperation(
307+
"ID you should provide"
308+
$id: String
309+
310+
"Switch for experiment ...."
311+
$enableBaz: Boolean = false,
312+
) {
313+
foo(id: $id) {
314+
bar
315+
baz @include(if: $enableBaz) {
316+
...BazInfo
317+
}
318+
}
319+
}
320+
321+
"Some description here"
322+
fragment BazInfo on Baz {
323+
# ...
324+
}
325+
```
326+
327+
Counterexample:
286328

287-
GraphQL definitions (e.g. queries, fragments, types, fields, arguments, etc.)
288-
which can be described should provide a {Description} unless they are considered
289-
self descriptive.
329+
```graphql counter-example
330+
"Descriptions are not permitted on the shorthand form of operations"
331+
{
332+
foo {
333+
bar
334+
baz {
335+
...BazInfo
336+
}
337+
}
338+
}
339+
```
290340

291341
## Operations
292342

293343
OperationDefinition :
294344

295-
- OperationType Name? VariablesDefinition? Directives? SelectionSet
345+
- Description? OperationType Name? VariablesDefinition? Directives? SelectionSet
296346
- SelectionSet
297347

298348
OperationType : one of `query` `mutation` `subscription`

spec/Section 3 -- Type System.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ documentation of a GraphQL service remains consistent with its capabilities,
5959
descriptions of GraphQL definitions are provided alongside their definitions and
6060
made available via introspection.
6161

62+
Note: See Section 2, "Descriptions", for normative rules and additional details
63+
on descriptions in executable documents.
64+
6265
To allow GraphQL service designers to easily publish documentation alongside the
6366
capabilities of a GraphQL service, GraphQL descriptions are defined using the
6467
Markdown syntax (as specified by [CommonMark](https://commonmark.org/)). In the

spec/Section 6 -- Execution.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ Note: GraphQL requests do not require any specific serialization format or
3333
transport mechanism. Message serialization and transport mechanisms should be
3434
chosen by the implementing service.
3535

36+
Note: Descriptions and comments in executable documents (operation definitions,
37+
fragment definitions, and variable definitions) MUST be ignored during execution
38+
and have no effect on the execution, validation, or response of a GraphQL
39+
document. Descriptions and comments on executable documents MAY be used for
40+
observability and logging purposes.
41+
3642
## Executing Requests
3743

3844
To execute a request, the executor must have a parsed {Document} and a selected

0 commit comments

Comments
 (0)