Skip to content

Commit a38362d

Browse files
committed
Add better error message for extension with descriptions
1 parent 74ce729 commit a38362d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/language/__tests__/schema-parser-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ describe('Schema Parser', () => {
333333
world: String
334334
}
335335
`).to.deep.equal({
336-
message: 'Syntax Error: Unexpected Name "extend".',
336+
message: 'Syntax Error: Unexpected Name "extend". Extension do not include descriptions.',
337337
locations: [{ line: 3, column: 7 }],
338338
});
339339

@@ -354,7 +354,7 @@ describe('Schema Parser', () => {
354354
world: String
355355
}
356356
`).to.deep.equal({
357-
message: 'Syntax Error: Unexpected Name "extend".',
357+
message: 'Syntax Error: Unexpected Name "extend". Extension do not include descriptions.',
358358
locations: [{ line: 3, column: 7 }],
359359
});
360360

src/language/parser.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ class Parser {
725725
*/
726726
parseTypeSystemDefinition(): TypeSystemDefinitionNode {
727727
// Many definitions begin with a description and require a lookahead.
728-
const keywordToken = this.peekDescription()
728+
const hasDescription = this.peekDescription();
729+
const keywordToken = hasDescription
729730
? this._lexer.lookahead()
730731
: this._lexer.token;
731732

@@ -750,6 +751,14 @@ class Parser {
750751
}
751752
}
752753

754+
if (hasDescription && keywordToken.value === 'extend') {
755+
throw syntaxError(
756+
this._lexer.source,
757+
keywordToken.start,
758+
'Unexpected Name "extend". Extension do not include descriptions.',
759+
);
760+
}
761+
753762
throw this.unexpected(keywordToken);
754763
}
755764

0 commit comments

Comments
 (0)