-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add descriptions to executable documents | 2025 Update #1170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
5517373
9f7ec63
1a1a4b3
88c47a8
f186ce7
9175057
9af6480
73c19c8
6d7b259
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,11 +275,74 @@ operations, each operation must be named. When submitting a Document with | |
multiple operations to a GraphQL service, the name of the desired operation to | ||
be executed must also be provided. | ||
|
||
## Descriptions | ||
|
||
Description : StringValue | ||
|
||
Documentation is a first-class feature of GraphQL. GraphQL descriptions are | ||
defined using the Markdown syntax (as specified by | ||
[CommonMark](https://commonmark.org/)). Description strings (often | ||
{BlockString}) occur immediately before the definition they describe. | ||
|
||
Descriptions may appear before: | ||
|
||
- Operation definitions (queries, mutations, subscriptions) in their full form | ||
(not the shorthand form). | ||
- Fragment definitions. | ||
- Variable definitions within operation definitions. | ||
|
||
Descriptions are not permitted on the shorthand form of operations (e.g., | ||
`{ ... }`). | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure where we stand on adding new syntax in the spec. I know we have this:
This change would be fine in that regard I think: all existing documents are still working exactly as before. This may still cause interoperability issues: an old version of GraphiQL will show an error on the description. This is probably okay but do we have examples of how we handled that in the past? Do we need to make this dependent on service capabilities? |
||
|
||
Example: | ||
|
||
```graphql example | ||
"Some description" | ||
query SomeOperation( | ||
"ID you should provide" | ||
$id: String | ||
|
||
"Switch for experiment ...." | ||
$enableBaz: Boolean = false, | ||
) { | ||
foo(id: $id) { | ||
bar | ||
baz @include(if: $enableBaz) { | ||
...BazInfo | ||
} | ||
} | ||
} | ||
|
||
"Some description here" | ||
fragment BazInfo on Baz { | ||
# ... | ||
} | ||
``` | ||
|
||
Counterexample: | ||
|
||
```graphql counter-example | ||
"Descriptions are not permitted on the shorthand form of operations" | ||
{ | ||
foo { | ||
bar | ||
baz { | ||
...BazInfo | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Operations | ||
|
||
OperationDefinition : | ||
|
||
- OperationType Name? VariablesDefinition? Directives? SelectionSet | ||
- Description? OperationType Name? VariablesDefinition? Directives? SelectionSet | ||
- SelectionSet | ||
|
||
OperationType : one of `query` `mutation` `subscription` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the use case for providing descriptions for a FragmentDefinition. Is this tailored to the case where we use a FragmentDefinition as a reusable selection-set across the codebase? Do we really want to encourage that? I'd think that with Fragment Arguments this could carry merit though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have it in Apollo Kotlin to add Kdoc to the generated models. Not 100% sure how many people use it. Probably not too many but I would still include it for consistency.
We have also APIs to load fragments from the cache so maybe having more contextual info about what is loaded could help.