Skip to content

Commit 995d1b6

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 995d1b6

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

spec/Section 2 -- Language.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,59 @@ GraphQL descriptions are defined using the Markdown syntax (as specified by
284284
[CommonMark](https://commonmark.org/)). Description strings (often {BlockString})
285285
occur immediately before the definition they describe.
286286

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.
287+
Descriptions may appear before:
288+
- Operation definitions (queries, mutations, subscriptions) in their full form (not the shorthand form).
289+
- Fragment definitions.
290+
- Variable definitions within operation definitions.
291+
292+
Descriptions are not permitted on the shorthand form of operations (e.g., `{ ... }`).
293+
294+
Note: Descriptions and comments in executable GraphQL documents are purely for documentation purposes. They MUST NOT affect the execution, validation, or response of a GraphQL document. It is safe to remove all descriptions and comments from executable documents without changing their behavior or results.
295+
296+
Example:
297+
298+
```graphql
299+
"Some description"
300+
query SomeOperation(
301+
"ID you should provide"
302+
$id: String
303+
304+
"Switch for experiment ...."
305+
$enableBaz: Boolean = false,
306+
) {
307+
foo(id: $id) {
308+
bar
309+
baz @include(if: $enableBaz) {
310+
...BazInfo
311+
}
312+
}
313+
}
314+
315+
"Some description here"
316+
fragment BazInfo on Baz {
317+
# ...
318+
}
319+
```
320+
321+
Counterexample:
322+
323+
```graphql counter-example
324+
"Descriptions are not permitted on the shorthand form of operations"
325+
{
326+
foo {
327+
bar
328+
baz {
329+
...BazInfo
330+
}
331+
}
332+
}
333+
```
290334

291335
## Operations
292336

293337
OperationDefinition :
294338

295-
- OperationType Name? VariablesDefinition? Directives? SelectionSet
339+
- Description? OperationType Name? VariablesDefinition? Directives? SelectionSet
296340
- SelectionSet
297341

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

spec/Section 3 -- Type System.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ 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 on descriptions in executable documents.
63+
6264
To allow GraphQL service designers to easily publish documentation alongside the
6365
capabilities of a GraphQL service, GraphQL descriptions are defined using the
6466
Markdown syntax (as specified by [CommonMark](https://commonmark.org/)). In the

spec/Section 6 -- Execution.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ 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, fragment definitions, and variable definitions) MUST be ignored during execution and have no effect on the execution, validation, or response of a GraphQL document. Descriptions and comments on executable documents MAY be used for observability and logging purposes.
37+
3638
## Executing Requests
3739

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

0 commit comments

Comments
 (0)