@@ -19,6 +19,7 @@ import type {
19
19
VariableNode ,
20
20
DocumentNode ,
21
21
DefinitionNode ,
22
+ ExecutableDefinitionNode ,
22
23
OperationDefinitionNode ,
23
24
OperationTypeNode ,
24
25
VariableDefinitionNode ,
@@ -213,26 +214,17 @@ function parseDocument(lexer: Lexer<*>): DocumentNode {
213
214
214
215
/**
215
216
* Definition :
216
- * - OperationDefinition
217
- * - FragmentDefinition
217
+ * - ExecutableDefinition
218
218
* - TypeSystemDefinition
219
219
*/
220
220
function parseDefinition ( lexer : Lexer < * > ) : DefinitionNode {
221
- if ( peek ( lexer , TokenKind . BRACE_L ) ) {
222
- return parseOperationDefinition ( lexer ) ;
223
- }
224
-
225
221
if ( peek ( lexer , TokenKind . NAME ) ) {
226
222
switch ( lexer . token . value ) {
227
223
case 'query' :
228
224
case 'mutation' :
229
225
case 'subscription' :
230
- return parseOperationDefinition ( lexer ) ;
231
-
232
226
case 'fragment' :
233
- return parseFragmentDefinition ( lexer ) ;
234
-
235
- // Note: The schema definition language is an experimental addition.
227
+ return parseExecutableDefinition ( lexer ) ;
236
228
case 'schema' :
237
229
case 'scalar' :
238
230
case 'type' :
@@ -242,13 +234,37 @@ function parseDefinition(lexer: Lexer<*>): DefinitionNode {
242
234
case 'input' :
243
235
case 'extend' :
244
236
case 'directive' :
237
+ // Note: The schema definition language is an experimental addition.
245
238
return parseTypeSystemDefinition ( lexer ) ;
246
239
}
240
+ } else if ( peek ( lexer , TokenKind . BRACE_L ) ) {
241
+ return parseExecutableDefinition ( lexer ) ;
242
+ } else if ( peekDescription ( lexer ) ) {
243
+ // Note: The schema definition language is an experimental addition.
244
+ return parseTypeSystemDefinition ( lexer ) ;
247
245
}
248
246
249
- // Note: The schema definition language is an experimental addition.
250
- if ( peekDescription ( lexer ) ) {
251
- return parseTypeSystemDefinition ( lexer ) ;
247
+ throw unexpected ( lexer ) ;
248
+ }
249
+
250
+ /**
251
+ * ExecutableDefinition :
252
+ * - OperationDefinition
253
+ * - FragmentDefinition
254
+ */
255
+ function parseExecutableDefinition ( lexer : Lexer < * > ) : ExecutableDefinitionNode {
256
+ if ( peek ( lexer , TokenKind . NAME ) ) {
257
+ switch ( lexer . token . value ) {
258
+ case 'query' :
259
+ case 'mutation' :
260
+ case 'subscription' :
261
+ return parseOperationDefinition ( lexer ) ;
262
+
263
+ case 'fragment' :
264
+ return parseFragmentDefinition ( lexer ) ;
265
+ }
266
+ } else if ( peek ( lexer , TokenKind . BRACE_L ) ) {
267
+ return parseOperationDefinition ( lexer ) ;
252
268
}
253
269
254
270
throw unexpected ( lexer ) ;
@@ -1321,14 +1337,31 @@ function parseDirectiveLocations(lexer: Lexer<*>): Array<NameNode> {
1321
1337
}
1322
1338
1323
1339
/*
1324
- * DirectiveLocation: one of
1325
- * `QUERY` `SCHEMA` `ENUM`
1326
- * `MUTATION` `SCALAR` `ENUM_VALUE`
1327
- * `SUBSCRIPTION` `OBJECT` `INPUT_OBJECT`
1328
- * `FIELD` `FIELD_DEFINITION` `INPUT_FIELD_DEFINITION`
1329
- * `FRAGMENT_DEFINITION` `ARGUMENT_DEFINITION`
1330
- * `FRAGMENT_SPREAD` `INTERFACE`
1331
- * `INLINE_FRAGMENT` `UNION`
1340
+ * DirectiveLocation :
1341
+ * - ExecutableDirectiveLocation
1342
+ * - TypeSystemDirectiveLocation
1343
+ *
1344
+ * ExecutableDirectiveLocation : one of
1345
+ * `QUERY`
1346
+ * `MUTATION`
1347
+ * `SUBSCRIPTION`
1348
+ * `FIELD`
1349
+ * `FRAGMENT_DEFINITION`
1350
+ * `FRAGMENT_SPREAD`
1351
+ * `INLINE_FRAGMENT`
1352
+ *
1353
+ * TypeSystemDirectiveLocation : one of
1354
+ * `SCHEMA`
1355
+ * `SCALAR`
1356
+ * `OBJECT`
1357
+ * `FIELD_DEFINITION`
1358
+ * `ARGUMENT_DEFINITION`
1359
+ * `INTERFACE`
1360
+ * `UNION`
1361
+ * `ENUM`
1362
+ * `ENUM_VALUE`
1363
+ * `INPUT_OBJECT`
1364
+ * `INPUT_FIELD_DEFINITION`
1332
1365
*/
1333
1366
function parseDirectiveLocation ( lexer : Lexer < * > ) : NameNode {
1334
1367
const start = lexer . token ;
0 commit comments