File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments