@@ -268,6 +268,13 @@ export class Parser {
268
268
? this . _lexer . lookahead ( )
269
269
: this . _lexer . token ;
270
270
271
+ if ( hasDescription && keywordToken . kind === TokenKind . BRACE_L ) {
272
+ throw syntaxError (
273
+ this . _lexer . source ,
274
+ this . _lexer . token . start ,
275
+ 'Unexpected description, descriptions are not supported on shorthand queries.' ,
276
+ ) ;
277
+ }
271
278
if ( keywordToken . kind === TokenKind . NAME ) {
272
279
switch ( keywordToken . value ) {
273
280
case 'schema' :
@@ -301,7 +308,7 @@ export class Parser {
301
308
throw syntaxError (
302
309
this . _lexer . source ,
303
310
this . _lexer . token . start ,
304
- 'Unexpected description, descriptions are not supported on type extensions and shorthand queries .' ,
311
+ 'Unexpected description, descriptions are not supported on type extensions.' ,
305
312
) ;
306
313
}
307
314
@@ -323,6 +330,18 @@ export class Parser {
323
330
*/
324
331
parseOperationDefinition ( ) : OperationDefinitionNode {
325
332
const start = this . _lexer . token ;
333
+
334
+ // Check if there's a description first
335
+ const hasDescription = this . peekDescription ( ) ;
336
+ if ( hasDescription ) {
337
+ // Look ahead to see what comes after the description
338
+ const nextToken = this . _lexer . lookahead ( ) ;
339
+ if ( nextToken . kind === TokenKind . BRACE_L ) {
340
+ // Short-hand queries cannot have descriptions
341
+ throw this . unexpected ( this . _lexer . token ) ;
342
+ }
343
+ }
344
+
326
345
if ( this . peek ( TokenKind . BRACE_L ) ) {
327
346
return this . node < OperationDefinitionNode > ( start , {
328
347
kind : Kind . OPERATION_DEFINITION ,
@@ -551,7 +570,7 @@ export class Parser {
551
570
}
552
571
return this . node < FragmentDefinitionNode > ( start , {
553
572
kind : Kind . FRAGMENT_DEFINITION ,
554
- description,
573
+ description,
555
574
name : this . parseFragmentName ( ) ,
556
575
typeCondition : ( this . expectKeyword ( 'on' ) , this . parseNamedType ( ) ) ,
557
576
directives : this . parseDirectives ( false ) ,
0 commit comments