@@ -258,16 +258,25 @@ export class Parser {
258
258
* - InputObjectTypeDefinition
259
259
*/
260
260
parseDefinition ( ) : DefinitionNode {
261
- if ( this . peek ( TokenKind . BRACE_L ) ) {
262
- return this . parseOperationDefinition ( ) ;
263
- }
264
261
265
262
// Many definitions begin with a description and require a lookahead.
266
263
const hasDescription = this . peekDescription ( ) ;
267
264
const keywordToken = hasDescription
268
265
? this . _lexer . lookahead ( )
269
266
: this . _lexer . token ;
270
267
268
+ if ( keywordToken . kind === TokenKind . BRACE_L ) {
269
+ // Check for shorthand query with description
270
+ if ( hasDescription ) {
271
+ throw syntaxError (
272
+ this . _lexer . source ,
273
+ this . _lexer . token . start ,
274
+ 'Unexpected description, shorthand queries do not support descriptions.' ,
275
+ ) ;
276
+ }
277
+ return this . parseOperationDefinition ( ) ;
278
+ }
279
+
271
280
if ( keywordToken . kind === TokenKind . NAME ) {
272
281
switch ( keywordToken . value ) {
273
282
case 'schema' :
@@ -286,37 +295,27 @@ export class Parser {
286
295
return this . parseInputObjectTypeDefinition ( ) ;
287
296
case 'directive' :
288
297
return this . parseDirectiveDefinition ( ) ;
298
+ case 'query' :
299
+ case 'mutation' :
300
+ case 'subscription' :
301
+ return this . parseOperationDefinition ( ) ;
302
+ case 'fragment' :
303
+ return this . parseFragmentDefinition ( ) ;
289
304
}
290
305
291
- if ( hasDescription && keywordToken . value === 'extend' ) {
306
+ if ( hasDescription ) {
292
307
throw syntaxError (
293
308
this . _lexer . source ,
294
309
this . _lexer . token . start ,
295
- 'Unexpected description, descriptions are not supported on type extensions .' ,
310
+ 'Unexpected description, only GraphQL definitions support descriptions .' ,
296
311
) ;
297
312
}
298
313
299
- switch ( keywordToken . value ) {
300
- case 'query' :
301
- case 'mutation' :
302
- case 'subscription' :
303
- return this . parseOperationDefinition ( ) ;
304
- case 'fragment' :
305
- return this . parseFragmentDefinition ( ) ;
306
- case 'extend' :
307
- return this . parseTypeSystemExtension ( ) ;
314
+ if ( keywordToken . value == 'extend' ) {
315
+ return this . parseTypeSystemExtension ( ) ;
308
316
}
309
317
}
310
318
311
- // Check for shorthand query with description
312
- if ( hasDescription && keywordToken . kind === TokenKind . BRACE_L ) {
313
- throw syntaxError (
314
- this . _lexer . source ,
315
- this . _lexer . token . start ,
316
- 'Unexpected description, descriptions are not supported on shorthand queries.' ,
317
- ) ;
318
- }
319
-
320
319
throw this . unexpected ( keywordToken ) ;
321
320
}
322
321
0 commit comments