File tree 4 files changed +18
-5
lines changed
4 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,8 @@ function buildExecutionContext(
174
174
'Must provide operation name if query contains multiple operations.'
175
175
) ;
176
176
}
177
- if ( ! operationName || definition . name . value === operationName ) {
177
+ if ( ! operationName ||
178
+ definition . name && definition . name . value === operationName ) {
178
179
operation = definition ;
179
180
}
180
181
break ;
Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ fragment MissingOn Type
92
92
it ( 'parse provides useful error when using source' , ( ) => {
93
93
expect (
94
94
( ) => parse ( new Source ( 'query' , 'MyQuery.graphql' ) )
95
- ) . to . throw ( 'Syntax Error MyQuery.graphql (1:6) Expected Name , found EOF' ) ;
95
+ ) . to . throw ( 'Syntax Error MyQuery.graphql (1:6) Expected { , found EOF' ) ;
96
96
} ) ;
97
97
98
98
it ( 'parses variable inline values' , ( ) => {
@@ -193,6 +193,14 @@ fragment ${fragmentName} on Type {
193
193
` ) ) . to . not . throw ( ) ;
194
194
} ) ;
195
195
196
+ it ( 'parses anonymous operations' , ( ) => {
197
+ expect ( ( ) => parse ( `
198
+ mutation {
199
+ mutationField
200
+ }
201
+ ` ) ) . to . not . throw ( ) ;
202
+ } ) ;
203
+
196
204
it ( 'parse creates ast' , ( ) => {
197
205
198
206
var source = new Source ( `{
Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ function parseDefinition(parser): Definition {
215
215
/**
216
216
* OperationDefinition :
217
217
* - SelectionSet
218
- * - OperationType Name VariableDefinitions? Directives? SelectionSet
218
+ * - OperationType Name? VariableDefinitions? Directives? SelectionSet
219
219
*
220
220
* OperationType : one of query mutation
221
221
*/
@@ -234,10 +234,14 @@ function parseOperationDefinition(parser): OperationDefinition {
234
234
}
235
235
var operationToken = expect ( parser , TokenKind . NAME ) ;
236
236
var operation = operationToken . value ;
237
+ var name ;
238
+ if ( peek ( parser , TokenKind . NAME ) ) {
239
+ name = parseName ( parser ) ;
240
+ }
237
241
return {
238
242
kind : OPERATION_DEFINITION ,
239
243
operation,
240
- name : parseName ( parser ) ,
244
+ name,
241
245
variableDefinitions : parseVariableDefinitions ( parser ) ,
242
246
directives : parseDirectives ( parser ) ,
243
247
selectionSet : parseSelectionSet ( parser ) ,
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export function getOperationAST(
33
33
return null ;
34
34
}
35
35
operation = definition ;
36
- } else if ( definition . name . value === operationName ) {
36
+ } else if ( definition . name && definition . name . value === operationName ) {
37
37
return definition ;
38
38
}
39
39
}
You can’t perform that action at this time.
0 commit comments