diff --git a/src/language/__tests__/schema-parser-test.js b/src/language/__tests__/schema-parser-test.js index a9577d12daf..d05a7446100 100644 --- a/src/language/__tests__/schema-parser-test.js +++ b/src/language/__tests__/schema-parser-test.js @@ -90,7 +90,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('world', { start: 15, end: 20 }), typeNode('String', { start: 22, end: 28 }), - { start: 15, end: 28 }, + { + start: 15, + end: 28, + }, ), ], loc: { start: 0, end: 30 }, @@ -186,7 +189,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('world', { start: 22, end: 27 }), typeNode('String', { start: 29, end: 35 }), - { start: 22, end: 35 }, + { + start: 22, + end: 35, + }, ), ], loc: { start: 0, end: 37 }, @@ -333,7 +339,8 @@ describe('Schema Parser', () => { world: String } `).to.deep.equal({ - message: 'Syntax Error: Unexpected Name "extend".', + message: + 'Syntax Error: Unexpected Name "extend". Extension do not include descriptions.', locations: [{ line: 3, column: 7 }], }); @@ -354,7 +361,8 @@ describe('Schema Parser', () => { world: String } `).to.deep.equal({ - message: 'Syntax Error: Unexpected Name "extend".', + message: + 'Syntax Error: Unexpected Name "extend". Extension do not include descriptions.', locations: [{ line: 3, column: 7 }], }); @@ -482,7 +490,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('field', { start: 35, end: 40 }), typeNode('String', { start: 42, end: 48 }), - { start: 35, end: 48 }, + { + start: 35, + end: 48, + }, ), ], loc: { start: 0, end: 50 }, @@ -508,7 +519,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('field', { start: 30, end: 35 }), typeNode('String', { start: 37, end: 43 }), - { start: 30, end: 43 }, + { + start: 30, + end: 43, + }, ), ], loc: { start: 0, end: 45 }, @@ -537,7 +551,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('field', { start: 33, end: 38 }), typeNode('String', { start: 40, end: 46 }), - { start: 33, end: 46 }, + { + start: 33, + end: 46, + }, ), ], loc: { start: 0, end: 48 }, @@ -565,7 +582,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('field', { start: 38, end: 43 }), typeNode('String', { start: 45, end: 51 }), - { start: 38, end: 51 }, + { + start: 38, + end: 51, + }, ), ], loc: { start: 0, end: 53 }, @@ -594,7 +614,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('field', { start: 35, end: 40 }), typeNode('String', { start: 42, end: 48 }), - { start: 35, end: 48 }, + { + start: 35, + end: 48, + }, ), ], loc: { start: 0, end: 50 }, @@ -624,7 +647,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('field', { start: 40, end: 45 }), typeNode('String', { start: 47, end: 53 }), - { start: 40, end: 53 }, + { + start: 40, + end: 53, + }, ), ], loc: { start: 0, end: 55 }, @@ -695,7 +721,10 @@ describe('Schema Parser', () => { fieldNode( nameNode('world', { start: 20, end: 25 }), typeNode('String', { start: 27, end: 33 }), - { start: 20, end: 33 }, + { + start: 20, + end: 33, + }, ), ], loc: { start: 0, end: 35 }, diff --git a/src/language/parser.js b/src/language/parser.js index 2fdcdc6ab64..1cb9ff0fafb 100644 --- a/src/language/parser.js +++ b/src/language/parser.js @@ -725,7 +725,8 @@ class Parser { */ parseTypeSystemDefinition(): TypeSystemDefinitionNode { // Many definitions begin with a description and require a lookahead. - const keywordToken = this.peekDescription() + const hasDescription = this.peekDescription(); + const keywordToken = hasDescription ? this._lexer.lookahead() : this._lexer.token; @@ -750,6 +751,14 @@ class Parser { } } + if (hasDescription && keywordToken.value === 'extend') { + throw syntaxError( + this._lexer.source, + keywordToken.start, + 'Unexpected Name "extend". Extension do not include descriptions.', + ); + } + throw this.unexpected(keywordToken); }