-
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?
Conversation
✅ Deploy Preview for graphql-spec-draft ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- 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.
995d1b6
to
9f7ec63
Compare
Enables the fancy formatting
Enhance GraphQL parser and printer to support descriptions for operations, variables, and fragments This commit is based on graphql#3402 , rebased onto graphql-js 16 and with added tests Implements graphql/graphql-spec#1170
@@ -174,8 +176,8 @@ FragmentSpread : ... FragmentName Directives? | |||
|
|||
InlineFragment : ... TypeCondition? Directives? SelectionSet | |||
|
|||
FragmentDefinition : fragment FragmentName TypeCondition Directives? | |||
SelectionSet | |||
FragmentDefinition : Description? fragment FragmentName TypeCondition |
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.
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 comment
The 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:
Once a query is written, it should always mean the same thing and return the
same shaped result. Future changes should not change the meaning of existing
schema or requests or in any other way cause an existing compliant GraphQL
service to become non-compliant for prior versions of the spec.
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?
This PR builds upon @IvanGoncharov's 2021 RFC, with changes rebased onto the current spec and updated to incorporate feedback from previous discussion as well as an additional editorial pass.
Descriptions are a core feature of GraphQL, enabling schema and document authors to provide human-readable documentation directly alongside type system elements and executable definitions. This proposal extends the utility of descriptions by allowing them to appear not only on type system definitions, but also on operations, fragments, and variable definitions within executable documents.
Enabling descriptions in these locations improves the expressiveness and maintainability of GraphQL documents, supports better tooling and code generation, and enhances the developer experience by making intent and usage clearer at the point of definition. Importantly, descriptions remain non-semantic—they do not affect execution, validation, or response—ensuring that they serve purely as documentation and can be safely removed without impacting behavior. This change aligns with GraphQL’s commitment to self-documenting APIs and empowers teams to deliver more understandable and maintainable GraphQL applications.
Key points:
Example:
Implemented in Graphql.js by graphql/graphql-js#4430