@@ -144,29 +144,47 @@ describe('GraphQLError', () => {
144
144
} ) ;
145
145
} ) ;
146
146
147
- it ( 'serializes to include message' , ( ) => {
148
- const e = new GraphQLError ( 'msg' ) ;
149
- expect ( JSON . stringify ( e ) ) . to . equal ( '{"message":"msg"}' ) ;
150
- } ) ;
147
+ it ( 'serializes to include all standard fields' , ( ) => {
148
+ const eShort = new GraphQLError ( 'msg' ) ;
149
+ expect ( JSON . stringify ( eShort , null , 2 ) ) . to . equal ( dedent `
150
+ {
151
+ "message": "msg"
152
+ }
153
+ ` ) ;
151
154
152
- it ( 'serializes to include message and locations' , ( ) => {
153
- const e = new GraphQLError ( 'msg' , fieldNode ) ;
154
- expect ( JSON . stringify ( e ) ) . to . equal (
155
- '{"message":"msg","locations":[{"line":2,"column":3}]}' ,
155
+ const path = [ 'path' , 2 , 'field' ] ;
156
+ const extensions = { foo : 'bar' } ;
157
+ const eFull = new GraphQLError (
158
+ 'msg' ,
159
+ fieldNode ,
160
+ undefined ,
161
+ undefined ,
162
+ path ,
163
+ undefined ,
164
+ extensions ,
156
165
) ;
157
- } ) ;
158
166
159
- it ( 'serializes to include path' , ( ) => {
160
- const e = new GraphQLError ( 'msg' , null , null , null , [
161
- 'path' ,
162
- 3 ,
163
- 'to' ,
164
- 'field' ,
165
- ] ) ;
166
- expect ( e ) . to . have . deep . property ( 'path' , [ 'path' , 3 , 'to' , 'field' ] ) ;
167
- expect ( JSON . stringify ( e ) ) . to . equal (
168
- '{"message":"msg","path":["path",3,"to","field"]}' ,
169
- ) ;
167
+ // We should try to keep order of fields stable
168
+ // Changing it wouldn't be breaking change but will fail some tests in other libraries.
169
+ expect ( JSON . stringify ( eFull , null , 2 ) ) . to . equal ( dedent `
170
+ {
171
+ "message": "msg",
172
+ "locations": [
173
+ {
174
+ "line": 2,
175
+ "column": 3
176
+ }
177
+ ],
178
+ "path": [
179
+ "path",
180
+ 2,
181
+ "field"
182
+ ],
183
+ "extensions": {
184
+ "foo": "bar"
185
+ }
186
+ }
187
+ ` ) ;
170
188
} ) ;
171
189
} ) ;
172
190
0 commit comments