@@ -250,6 +250,12 @@ export class Parser {
250250
251251 if ( keywordToken . kind === TokenKind . NAME ) {
252252 switch ( keywordToken . value ) {
253+ case 'query' :
254+ case 'mutation' :
255+ case 'subscription' :
256+ return this . parseOperationDefinition ( ) ;
257+ case 'fragment' :
258+ return this . parseFragmentDefinition ( ) ;
253259 case 'schema' :
254260 return this . parseSchemaDefinition ( ) ;
255261 case 'scalar' :
@@ -266,24 +272,14 @@ export class Parser {
266272 return this . parseInputObjectTypeDefinition ( ) ;
267273 case 'directive' :
268274 return this . parseDirectiveDefinition ( ) ;
269- }
270-
271- if ( hasDescription ) {
272- throw syntaxError (
273- this . _lexer . source ,
274- this . _lexer . token . start ,
275- 'Unexpected description, descriptions are supported only on type definitions.' ,
276- ) ;
277- }
278-
279- switch ( keywordToken . value ) {
280- case 'query' :
281- case 'mutation' :
282- case 'subscription' :
283- return this . parseOperationDefinition ( ) ;
284- case 'fragment' :
285- return this . parseFragmentDefinition ( ) ;
286275 case 'extend' :
276+ if ( hasDescription ) {
277+ throw syntaxError (
278+ this . _lexer . source ,
279+ this . _lexer . token . start ,
280+ 'Unexpected description, descriptions are not supported on type extensions.' ,
281+ ) ;
282+ }
287283 return this . parseTypeSystemExtension ( ) ;
288284 }
289285 }
@@ -300,23 +296,28 @@ export class Parser {
300296 */
301297 parseOperationDefinition ( ) : OperationDefinitionNode {
302298 const start = this . _lexer . token ;
299+
303300 if ( this . peek ( TokenKind . BRACE_L ) ) {
304301 return this . node < OperationDefinitionNode > ( start , {
305302 kind : Kind . OPERATION_DEFINITION ,
303+ description : undefined ,
306304 operation : OperationTypeNode . QUERY ,
307305 name : undefined ,
308306 variableDefinitions : [ ] ,
309307 directives : [ ] ,
310308 selectionSet : this . parseSelectionSet ( ) ,
311309 } ) ;
312310 }
311+
312+ const description = this . parseDescription ( ) ;
313313 const operation = this . parseOperationType ( ) ;
314314 let name ;
315315 if ( this . peek ( TokenKind . NAME ) ) {
316316 name = this . parseName ( ) ;
317317 }
318318 return this . node < OperationDefinitionNode > ( start , {
319319 kind : Kind . OPERATION_DEFINITION ,
320+ description,
320321 operation,
321322 name,
322323 variableDefinitions : this . parseVariableDefinitions ( ) ,
@@ -359,6 +360,7 @@ export class Parser {
359360 parseVariableDefinition ( ) : VariableDefinitionNode {
360361 return this . node < VariableDefinitionNode > ( this . _lexer . token , {
361362 kind : Kind . VARIABLE_DEFINITION ,
363+ description : this . parseDescription ( ) ,
362364 variable : this . parseVariable ( ) ,
363365 type : ( this . expectToken ( TokenKind . COLON ) , this . parseTypeReference ( ) ) ,
364366 defaultValue : this . expectOptionalToken ( TokenKind . EQUALS )
@@ -506,13 +508,15 @@ export class Parser {
506508 */
507509 parseFragmentDefinition ( ) : FragmentDefinitionNode {
508510 const start = this . _lexer . token ;
511+ const description = this . parseDescription ( ) ;
509512 this . expectKeyword ( 'fragment' ) ;
510513 // Legacy support for defining variables within fragments changes
511514 // the grammar of FragmentDefinition:
512515 // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
513516 if ( this . _options ?. allowLegacyFragmentVariables === true ) {
514517 return this . node < FragmentDefinitionNode > ( start , {
515518 kind : Kind . FRAGMENT_DEFINITION ,
519+ description,
516520 name : this . parseFragmentName ( ) ,
517521 variableDefinitions : this . parseVariableDefinitions ( ) ,
518522 typeCondition : ( this . expectKeyword ( 'on' ) , this . parseNamedType ( ) ) ,
@@ -522,6 +526,7 @@ export class Parser {
522526 }
523527 return this . node < FragmentDefinitionNode > ( start , {
524528 kind : Kind . FRAGMENT_DEFINITION ,
529+ description,
525530 name : this . parseFragmentName ( ) ,
526531 typeCondition : ( this . expectKeyword ( 'on' ) , this . parseNamedType ( ) ) ,
527532 directives : this . parseDirectives ( false ) ,
0 commit comments