Skip to content

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
Contributor

Choose a reason for hiding this comment

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

@fotoetienne @benjie

I took a stab at addressing this feedback slightly differently to better preserve existing behavior, please see

fotoetienne#1

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 }

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

Successfully merging this pull request may close these issues.

3 participants