Skip to content

Add better error message for extension with descriptions #2568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions src/language/__tests__/schema-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,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 }],
});

Expand All @@ -354,7 +355,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 }],
});

Expand Down
11 changes: 10 additions & 1 deletion src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand Down