@@ -122,29 +122,47 @@ describe('GraphQLError', () => {
122
122
} ) ;
123
123
} ) ;
124
124
125
- it ( 'serializes to include message' , ( ) => {
126
- const e = new GraphQLError ( 'msg' ) ;
127
- expect ( JSON . stringify ( e ) ) . to . equal ( '{"message":"msg"}' ) ;
128
- } ) ;
125
+ it ( 'serializes to include all standard fields' , ( ) => {
126
+ const eShort = new GraphQLError ( 'msg' ) ;
127
+ expect ( JSON . stringify ( eShort , null , 2 ) + '\n' ) . to . equal ( dedent `
128
+ {
129
+ "message": "msg"
130
+ }
131
+ ` ) ;
129
132
130
- it ( 'serializes to include message and locations' , ( ) => {
131
- const e = new GraphQLError ( 'msg' , fieldNode ) ;
132
- expect ( JSON . stringify ( e ) ) . to . equal (
133
- '{"message":"msg","locations":[{"line":2,"column":3}]}' ,
133
+ const path = [ 'path' , 2 , 'field' ] ;
134
+ const extensions = { foo : 'bar' } ;
135
+ const eFull = new GraphQLError (
136
+ 'msg' ,
137
+ fieldNode ,
138
+ undefined ,
139
+ undefined ,
140
+ path ,
141
+ undefined ,
142
+ extensions ,
134
143
) ;
135
- } ) ;
136
144
137
- it ( 'serializes to include path' , ( ) => {
138
- const e = new GraphQLError ( 'msg' , null , null , null , [
139
- 'path' ,
140
- 3 ,
141
- 'to' ,
142
- 'field' ,
143
- ] ) ;
144
- expect ( e ) . to . have . deep . property ( 'path' , [ 'path' , 3 , 'to' , 'field' ] ) ;
145
- expect ( JSON . stringify ( e ) ) . to . equal (
146
- '{"message":"msg","path":["path",3,"to","field"]}' ,
147
- ) ;
145
+ // We should try to keep order of fields stable
146
+ // Changing it wouldn't be breaking change but will fail some tests in other libraries.
147
+ expect ( JSON . stringify ( eFull , null , 2 ) + '\n' ) . to . equal ( dedent `
148
+ {
149
+ "message": "msg",
150
+ "locations": [
151
+ {
152
+ "line": 2,
153
+ "column": 3
154
+ }
155
+ ],
156
+ "path": [
157
+ "path",
158
+ 2,
159
+ "field"
160
+ ],
161
+ "extensions": {
162
+ "foo": "bar"
163
+ }
164
+ }
165
+ ` ) ;
148
166
} ) ;
149
167
} ) ;
150
168
0 commit comments