Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ function buildExecutionContext(
'Must provide operation name if query contains multiple operations.'
);
}
if (!operationName || definition.name.value === operationName) {
if (!operationName ||
definition.name && definition.name.value === operationName) {
operation = definition;
}
break;
Expand Down
10 changes: 9 additions & 1 deletion src/language/__tests__/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fragment MissingOn Type
it('parse provides useful error when using source', () => {
expect(
() => parse(new Source('query', 'MyQuery.graphql'))
).to.throw('Syntax Error MyQuery.graphql (1:6) Expected Name, found EOF');
).to.throw('Syntax Error MyQuery.graphql (1:6) Expected {, found EOF');
});

it('parses variable inline values', () => {
Expand Down Expand Up @@ -193,6 +193,14 @@ fragment ${fragmentName} on Type {
`)).to.not.throw();
});

it('parses anonymous operations', () => {
expect(() => parse(`
mutation {
mutationField
}
`)).to.not.throw();
});

it('parse creates ast', () => {

var source = new Source(`{
Expand Down
8 changes: 6 additions & 2 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function parseDefinition(parser): Definition {
/**
* OperationDefinition :
* - SelectionSet
* - OperationType Name VariableDefinitions? Directives? SelectionSet
* - OperationType Name? VariableDefinitions? Directives? SelectionSet
*
* OperationType : one of query mutation
*/
Expand All @@ -234,10 +234,14 @@ function parseOperationDefinition(parser): OperationDefinition {
}
var operationToken = expect(parser, TokenKind.NAME);
var operation = operationToken.value;
var name;
if (peek(parser, TokenKind.NAME)) {
name = parseName(parser);
}
return {
kind: OPERATION_DEFINITION,
operation,
name: parseName(parser),
name,
variableDefinitions: parseVariableDefinitions(parser),
directives: parseDirectives(parser),
selectionSet: parseSelectionSet(parser),
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/getOperationAST.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getOperationAST(
return null;
}
operation = definition;
} else if (definition.name.value === operationName) {
} else if (definition.name && definition.name.value === operationName) {
return definition;
}
}
Expand Down