File tree Expand file tree Collapse file tree 2 files changed +68
-3
lines changed Expand file tree Collapse file tree 2 files changed +68
-3
lines changed Original file line number Diff line number Diff line change @@ -102,11 +102,12 @@ export class GraphQLError extends Error {
102
102
103
103
this . path = path ?? undefined ;
104
104
105
- this . extensions = extensions ?? { } ;
106
-
107
105
const originalExtensions = originalError ?. extensions ;
108
- if ( isObjectLike ( originalExtensions ) ) {
106
+
107
+ if ( extensions == null && isObjectLike ( originalExtensions ) ) {
109
108
this . extensions = { ...originalExtensions } ;
109
+ } else {
110
+ this. extensions = extensions ?? { } ;
110
111
}
111
112
112
113
// By being enumerable, JSON.stringify will include bellow properties in the resulting output.
Original file line number Diff line number Diff line change @@ -164,6 +164,70 @@ describe('GraphQLError', () => {
164
164
}
165
165
` ) ;
166
166
} ) ;
167
+
168
+ it ( 'uses the provided extensions when original extensions are undefined' , ( ) => {
169
+ const original = new Error ( 'original' ) ;
170
+ console . log ( 'Creating error 1' ) ;
171
+ const graphqlError = new GraphQLError (
172
+ 'msg' ,
173
+ null ,
174
+ null ,
175
+ null ,
176
+ null ,
177
+ original ,
178
+ {
179
+ someKey : 'someValue' ,
180
+ } ,
181
+ ) ;
182
+ console . log ( 'Creating error 2' ) ;
183
+
184
+ const e = new GraphQLError (
185
+ graphqlError . message ,
186
+ null ,
187
+ null ,
188
+ null ,
189
+ null ,
190
+ graphqlError ,
191
+ { correlationId : '123-echo-tango-delta' } ,
192
+ ) ;
193
+
194
+ expect ( JSON . stringify ( e . extensions , null , 2 ) + '\n' ) . to . equal ( dedent `
195
+ {
196
+ "correlationId": "123-echo-tango-delta"
197
+ }
198
+ ` ) ;
199
+ } ) ;
200
+
201
+ it ( 'uses the provided extensions when original extensions are empty object' , ( ) => {
202
+ const original = new Error ( 'original' ) ;
203
+ const graphqlError = new GraphQLError (
204
+ 'msg' ,
205
+ null ,
206
+ null ,
207
+ null ,
208
+ null ,
209
+ original ,
210
+ { } ,
211
+ ) ;
212
+ expect ( graphqlError . extensions ) . to . eql ( { } ) ;
213
+
214
+ const e = new GraphQLError (
215
+ graphqlError . message ,
216
+ null ,
217
+ null ,
218
+ null ,
219
+ null ,
220
+ graphqlError ,
221
+ { correlationId : '123-echo-tango-delta' } ,
222
+ ) ;
223
+ expect ( e . originalError . extensions ) . to . eql ( { } ) ;
224
+
225
+ expect ( JSON . stringify ( e . extensions , null , 2 ) + '\n' ) . to . equal ( dedent `
226
+ {
227
+ "correlationId": "123-echo-tango-delta"
228
+ }
229
+ ` ) ;
230
+ } ) ;
167
231
} ) ;
168
232
169
233
describe ( 'printError' , ( ) => {
You can’t perform that action at this time.
0 commit comments