Skip to content

Descriptions on executable documents #4430

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

Open
wants to merge 2 commits into
base: 16.x.x
Choose a base branch
from

Conversation

fotoetienne
Copy link

Enhance GraphQL parser and printer to support descriptions for operations, variables, and fragments

This commit is based on #3402 , rebased onto graphql-js 16 and with added tests

Implements graphql/graphql-spec#1170

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
Comment on lines -291 to +302
if (hasDescription) {
throw syntaxError(
this._lexer.source,
this._lexer.token.start,
'Unexpected description, descriptions are supported only on type definitions.',
);
}

switch (keywordToken.value) {
case 'query':
case 'mutation':
case 'subscription':
return this.parseOperationDefinition();
case 'fragment':
return this.parseFragmentDefinition();
case 'extend':
if (hasDescription) {
throw syntaxError(
this._lexer.source,
this._lexer.token.start,
'Unexpected description, descriptions are not supported on type extensions.',
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this changes the behavior of the this.unexpected() fallback lower down. I think we should restore the previous format - two switch statements with a "no descriptions" assertion between them.

Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! We should have a test to ensure that a description on an anonymous query results in a sensible parse error if we don't already have one, plus the comment I made before. Other than that, I think this is good to go!

"""Invalid"""
{ __typename }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants