Skip to content

Commit a0c25e5

Browse files
authored
Merge pull request #487 from martijnwalraven/graphqlerror-missing-locations
Fix GraphQLError missing positions/locations when node.loc.start === 0
2 parents 948864e + 8a9addc commit a0c25e5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/error/GraphQLError.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ export function GraphQLError( // eslint-disable-line no-redeclare
103103

104104
let _positions = positions;
105105
if (!_positions && nodes) {
106-
_positions = nodes.map(node => node.loc && node.loc.start).filter(Boolean);
106+
_positions = nodes.filter(node => node.loc !== null)
107+
.map(node => node.loc.start);
107108
}
108109
if (_positions && _positions.length === 0) {
109110
_positions = undefined;

src/error/__tests__/GraphQLError-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ describe('GraphQLError', () => {
7272
expect(e.locations).to.deep.equal([ { line: 2, column: 7 } ]);
7373
});
7474

75+
it('converts node with loc.start === 0 to positions and locations', () => {
76+
const source = new Source(`{
77+
field
78+
}`);
79+
const ast = parse(source);
80+
const operationAST = ast.definitions[0];
81+
const e = new GraphQLError('msg', [ operationAST ]);
82+
expect(e.nodes).to.deep.equal([ operationAST ]);
83+
expect(e.source).to.equal(source);
84+
expect(e.positions).to.deep.equal([ 0 ]);
85+
expect(e.locations).to.deep.equal([ { line: 1, column: 1 } ]);
86+
});
87+
7588
it('converts source and positions to locations', () => {
7689
const source = new Source(`{
7790
field

0 commit comments

Comments
 (0)