Skip to content

Commit

Permalink
Fix GraphQLError missing positions/locations when node.loc.start === 0
Browse files Browse the repository at this point in the history
Because the GraphQLError constructor filtered out falsy values for
node.loc.start, that would also filter out 0.
  • Loading branch information
martijnwalraven committed Sep 19, 2016
1 parent 2406d3a commit 8a9addc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/error/GraphQLError.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export function GraphQLError( // eslint-disable-line no-redeclare

let _positions = positions;
if (!_positions && nodes) {
_positions = nodes.map(node => node.loc && node.loc.start).filter(Boolean);
_positions = nodes.filter(node => node.loc !== null)
.map(node => node.loc.start);
}
if (_positions && _positions.length === 0) {
_positions = undefined;
Expand Down
13 changes: 13 additions & 0 deletions src/error/__tests__/GraphQLError-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ describe('GraphQLError', () => {
expect(e.locations).to.deep.equal([ { line: 2, column: 7 } ]);
});

it('converts node with loc.start === 0 to positions and locations', () => {
const source = new Source(`{
field
}`);
const ast = parse(source);
const operationAST = ast.definitions[0];
const e = new GraphQLError('msg', [ operationAST ]);
expect(e.nodes).to.deep.equal([ operationAST ]);
expect(e.source).to.equal(source);
expect(e.positions).to.deep.equal([ 0 ]);
expect(e.locations).to.deep.equal([ { line: 1, column: 1 } ]);
});

it('converts source and positions to locations', () => {
const source = new Source(`{
field
Expand Down

0 comments on commit 8a9addc

Please sign in to comment.