Skip to content

Commit fca6653

Browse files
fotoetienneIvanGoncharovglen-84leebyron
authored
Add descriptions to executable documents | 2025 Update (#1170)
* Add descriptions to executable definitions * 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. * Add example label to GraphQL code block in Language section Enables the fancy formatting * Refactor description section for clarity Also: - add color to operation description example and counter-example - add descriptions in operation examples throughout section 2 * Add optional description to fragment and variable definitions * Prettier * Refactor time machine status query documentation for clarity and conciseness * Reduced example * Single quotes for single line description Co-authored-by: Glen <glen.84@gmail.com> * Refactor descriptions text, incorporating feedback from working group * formatting * Editorial: move descriptions definition above document * editorial: move examples back to type system, add some links * Editorial --------- Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com> Co-authored-by: Glen <glen.84@gmail.com> Co-authored-by: Lee Byron <lee@leebyron.com>
1 parent 17e2a47 commit fca6653

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed

spec/Appendix B -- Grammar Summary.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ lines and uniform indentation with {BlockStringValue()}.
133133

134134
## Document Syntax
135135

136+
Description : StringValue
137+
136138
Document : Definition+
137139

138140
Definition :
@@ -149,7 +151,7 @@ ExecutableDefinition :
149151

150152
OperationDefinition :
151153

152-
- OperationType Name? VariablesDefinition? Directives? SelectionSet
154+
- Description? OperationType Name? VariablesDefinition? Directives? SelectionSet
153155
- SelectionSet
154156

155157
OperationType : one of `query` `mutation` `subscription`
@@ -174,8 +176,8 @@ FragmentSpread : ... FragmentName Directives?
174176

175177
InlineFragment : ... TypeCondition? Directives? SelectionSet
176178

177-
FragmentDefinition : fragment FragmentName TypeCondition Directives?
178-
SelectionSet
179+
FragmentDefinition : Description? fragment FragmentName TypeCondition
180+
Directives? SelectionSet
179181

180182
FragmentName : Name but not `on`
181183

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

214216
VariablesDefinition : ( VariableDefinition+ )
215217

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

218221
Variable : $ Name
219222

@@ -268,8 +271,6 @@ SchemaExtension :
268271

269272
RootOperationTypeDefinition : OperationType : NamedType
270273

271-
Description : StringValue
272-
273274
TypeDefinition :
274275

275276
- ScalarTypeDefinition

spec/Section 1 -- Overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ GraphQL has a number of design principles:
6363
endpoints. A GraphQL response, on the other hand, contains exactly what a
6464
client asks for and no more.
6565

66-
- **Introspective**: GraphQL is introspective. A GraphQL service's type system
67-
can be queryable by the GraphQL language itself, as will be described in this
68-
specification. GraphQL introspection serves as a powerful platform for
69-
building common tools and client software libraries.
66+
- **Self-describing**: GraphQL is self-describing and introspective. A GraphQL
67+
service's type system can be queryable by the GraphQL language itself, which
68+
includes readable documentation. GraphQL introspection serves as a powerful
69+
platform for building common developer tools and client software libraries.
7070

7171
Because of these principles, GraphQL is a powerful and productive environment
7272
for building client applications. Product developers and designers building

spec/Section 2 -- Language.md

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,57 @@ Any {Name} within a GraphQL type system must not start with two underscores
233233
{"\_\_"} unless it is part of the [introspection system](#sec-Introspection) as
234234
defined by this specification.
235235

236+
## Descriptions
237+
238+
Description : StringValue
239+
240+
Documentation is a first-class feature of GraphQL by including written
241+
descriptions on all named definitions in executable {Document} and GraphQL type
242+
systems, which is also made available via introspection ensuring the
243+
documentation of a GraphQL service remains consistent with its capabilities (see
244+
[Type System Descriptions](#sec-Type-System-Descriptions)).
245+
246+
GraphQL descriptions are provided as Markdown (as specified by
247+
[CommonMark](https://commonmark.org/)). Description strings (often
248+
{BlockString}) occur immediately before the definition they describe.
249+
250+
This is an example of a well-described operation:
251+
252+
```graphql example
253+
"""
254+
Request the current status of a time machine and its operator.
255+
You can also check the status for a particular year.
256+
**Warning:** certain years may trigger an anomaly in the space-time continuum.
257+
"""
258+
query GetTimeMachineStatus(
259+
"The unique serial number of the time machine to inspect."
260+
$machineId: ID!
261+
"The year to check the status for."
262+
$year: Int
263+
) {
264+
timeMachine(id: $machineId) {
265+
...TimeMachineDetails
266+
status(year: $year)
267+
}
268+
}
269+
270+
"Details about a time machine and its operator."
271+
fragment TimeMachineDetails on TimeMachine {
272+
id
273+
model
274+
lastMaintenance
275+
operator {
276+
name
277+
licenseLevel
278+
}
279+
}
280+
```
281+
282+
Descriptions in GraphQL executable documents are purely for documentation
283+
purposes. They MUST NOT affect the execution, validation, or response of a
284+
GraphQL document. It is safe to remove all descriptions and comments from
285+
executable documents without changing their behavior or results.
286+
236287
## Document
237288

238289
Document : Definition+
@@ -279,7 +330,7 @@ be executed must also be provided.
279330

280331
OperationDefinition :
281332

282-
- OperationType Name? VariablesDefinition? Directives? SelectionSet
333+
- Description? OperationType Name? VariablesDefinition? Directives? SelectionSet
283334
- SelectionSet
284335

285336
OperationType : one of `query` `mutation` `subscription`
@@ -298,6 +349,10 @@ For example, this mutation operation might "like" a story and then retrieve the
298349
new number of likes:
299350

300351
```graphql example
352+
"""
353+
Mark story 12345 as "liked"
354+
and return the updated number of likes on the story
355+
"""
301356
mutation {
302357
likeStory(storyID: 12345) {
303358
story {
@@ -322,6 +377,8 @@ For example, this unnamed query operation is written via query shorthand.
322377
}
323378
```
324379

380+
Descriptions are not permitted on query shorthand.
381+
325382
Note: many examples below will use the query short-hand syntax.
326383

327384
## Selection Sets
@@ -523,8 +580,8 @@ which returns the result:
523580

524581
FragmentSpread : ... FragmentName Directives?
525582

526-
FragmentDefinition : fragment FragmentName TypeCondition Directives?
527-
SelectionSet
583+
FragmentDefinition : Description? fragment FragmentName TypeCondition
584+
Directives? SelectionSet
528585

529586
FragmentName : Name but not `on`
530587

@@ -570,6 +627,7 @@ query withFragments {
570627
}
571628
}
572629

630+
"Common fields for a user's friends."
573631
fragment friendFields on User {
574632
id
575633
name
@@ -1181,7 +1239,8 @@ Variable : $ Name
11811239

11821240
VariablesDefinition : ( VariableDefinition+ )
11831241

1184-
VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
1242+
VariableDefinition : Description? Variable : Type DefaultValue?
1243+
Directives[Const]?
11851244

11861245
DefaultValue : = Value[Const]
11871246

@@ -1200,7 +1259,10 @@ In this example, we want to fetch a profile picture size based on the size of a
12001259
particular device:
12011260

12021261
```graphql example
1203-
query getZuckProfile($devicePicSize: Int) {
1262+
query getZuckProfile(
1263+
"The size of the profile picture to fetch."
1264+
$devicePicSize: Int
1265+
) {
12041266
user(id: 4) {
12051267
id
12061268
name

spec/Section 3 -- Type System.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,16 @@ Tools which only seek to produce and extend schema and not execute requests may
5050
choose to only allow {TypeSystemExtensionDocument} and not allow
5151
{ExecutableDefinition} but should provide a descriptive error if present.
5252

53-
## Descriptions
53+
## Type System Descriptions
5454

55-
Description : StringValue
55+
Documentation is a first-class feature of GraphQL type systems, written
56+
immediately alongside definitions in a {TypeSystemDocument} and made available
57+
via introspection.
5658

57-
Documentation is a first-class feature of GraphQL type systems. To ensure the
58-
documentation of a GraphQL service remains consistent with its capabilities,
59-
descriptions of GraphQL definitions are provided alongside their definitions and
60-
made available via introspection.
61-
62-
To allow GraphQL service designers to easily publish documentation alongside the
63-
capabilities of a GraphQL service, GraphQL descriptions are defined using the
64-
Markdown syntax (as specified by [CommonMark](https://commonmark.org/)). In the
65-
type system definition language, these description strings (often {BlockString})
66-
occur immediately before the definition they describe.
59+
[Descriptions](#sec-Descriptions) allow GraphQL service designers to easily
60+
provide documentation which remains consistent with the capabilities of a
61+
GraphQL service. Descriptions provided as Markdown (as specified by
62+
[CommonMark](https://commonmark.org/)) for every definition in a type system.
6763

6864
GraphQL schema and all other definitions (e.g. types, fields, arguments, etc.)
6965
which can be described should provide a {Description} unless they are considered

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 observable execution, validation, or response of a
39+
GraphQL document. Descriptions and comments on executable documents MAY be used
40+
for non-observable purposes, such as logging and other developer tools.
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)