@@ -268,6 +268,13 @@ export class Parser {
268268 ? this . _lexer . lookahead ( )
269269 : this . _lexer . token ;
270270
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+ }
271278 if ( keywordToken . kind === TokenKind . NAME ) {
272279 switch ( keywordToken . value ) {
273280 case 'schema' :
@@ -301,7 +308,7 @@ export class Parser {
301308 throw syntaxError (
302309 this . _lexer . source ,
303310 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.' ,
305312 ) ;
306313 }
307314
@@ -323,6 +330,18 @@ export class Parser {
323330 */
324331 parseOperationDefinition ( ) : OperationDefinitionNode {
325332 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+
326345 if ( this . peek ( TokenKind . BRACE_L ) ) {
327346 return this . node < OperationDefinitionNode > ( start , {
328347 kind : Kind . OPERATION_DEFINITION ,
@@ -551,7 +570,7 @@ export class Parser {
551570 }
552571 return this . node < FragmentDefinitionNode > ( start , {
553572 kind : Kind . FRAGMENT_DEFINITION ,
554- description,
573+ description,
555574 name : this . parseFragmentName ( ) ,
556575 typeCondition : ( this . expectKeyword ( 'on' ) , this . parseNamedType ( ) ) ,
557576 directives : this . parseDirectives ( false ) ,
0 commit comments