Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
make TypeCondition optional in InlineFragments
Browse files Browse the repository at this point in the history
  • Loading branch information
asiandrummer authored and leebyron committed Feb 2, 2016
1 parent 06f48a2 commit 5b8ba38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/mode-test.js
Expand Up @@ -36,6 +36,20 @@ describe('graphql-mode', () => {
]);
});

it('parses inline fragments with optional syntax correctly', () => {
CodeMirror.runMode('{ ... on OptionalType { name } }', 'graphql',
(token, style) => expect(style).to.not.equal('invalidchar')
);

CodeMirror.runMode('{ ... { name } }', 'graphql',
(token, style) => expect(style).to.not.equal('invalidchar')
);

CodeMirror.runMode('{ ... @optionalDirective { name } }', 'graphql',
(token, style) => expect(style).to.not.equal('invalidchar')
);
});

it('returns "invalidchar" message when there is no matching token', () => {
CodeMirror.runMode('qauery name', 'graphql', (token, style) => {
if (token.trim()) {
Expand Down
4 changes: 2 additions & 2 deletions src/mode.js
Expand Up @@ -359,8 +359,8 @@ var ParseRules = {
SelectionSet: [ p('{'), list('Selection'), p('}') ],
Selection(token, stream) {
return token.value === '...' ?
stream.match(/[\s\u00a0,]*on\b/, false) ?
'InlineFragment' : 'FragmentSpread' :
stream.match(/[\s\u00a0,]*(?!on\b)[_A-Za-z]/, false) ?
'FragmentSpread' : 'InlineFragment' :
stream.match(/[\s\u00a0,]*:/, false) ? 'AliasedField' : 'Field';
},
// Note: this minor deviation of "AliasedField" simplifies the lookahead.
Expand Down

0 comments on commit 5b8ba38

Please sign in to comment.