Skip to content

Commit

Permalink
Add better error message for extension with descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
thenamankumar committed May 21, 2020
1 parent 74ce729 commit f5cf916
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
51 changes: 40 additions & 11 deletions src/language/__tests__/schema-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 }],
});

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

Expand Down Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
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

0 comments on commit f5cf916

Please sign in to comment.