Skip to content

Commit 8ae5bd7

Browse files
committed
Include fragment name lookahead in parser as specced
1 parent 91e6109 commit 8ae5bd7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/language/__tests__/parser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ fragment MissingOn Type
6363
).to.throw('Syntax Error GraphQL (1:22) Duplicate input object field a.');
6464
});
6565

66+
it('does not accept fragments named "on"', () => {
67+
expect(
68+
() => parse('fragment on on on { on }')
69+
).to.throw('Syntax Error GraphQL (1:10) Unexpected Name "on"');
70+
});
71+
6672
var kitchenSink = readFileSync(
6773
join(__dirname, '/kitchen-sink.graphql'),
6874
{ encoding: 'utf8' }

src/language/parser.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,25 @@ function parseFragment(parser): FragmentSpread | InlineFragment {
435435
}
436436
return {
437437
kind: FRAGMENT_SPREAD,
438-
name: parseName(parser),
438+
name: parseFragmentName(parser),
439439
directives: parseDirectives(parser),
440440
loc: loc(parser, start)
441441
};
442442
}
443443

444+
function parseFragmentName(parser): Name {
445+
if (parser.token.value === 'on') {
446+
throw unexpected(parser);
447+
}
448+
return parseName(parser);
449+
}
450+
444451
function parseFragmentDefinition(parser): FragmentDefinition {
445452
var start = parser.token.start;
446453
expectKeyword(parser, 'fragment');
447454
return {
448455
kind: FRAGMENT_DEFINITION,
449-
name: parseName(parser),
456+
name: parseFragmentName(parser),
450457
typeCondition: (expectKeyword(parser, 'on'), parseName(parser)),
451458
directives: parseDirectives(parser),
452459
selectionSet: parseSelectionSet(parser),

0 commit comments

Comments
 (0)