File tree 2 files changed +64
-3
lines changed 2 files changed +64
-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,66 @@ 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
+ const graphqlError = new GraphQLError (
171
+ 'msg' ,
172
+ null ,
173
+ null ,
174
+ null ,
175
+ null ,
176
+ original ,
177
+ {
178
+ someKey : 'someValue' ,
179
+ } ,
180
+ ) ;
181
+
182
+ const e = new GraphQLError (
183
+ graphqlError . message ,
184
+ null ,
185
+ null ,
186
+ null ,
187
+ null ,
188
+ graphqlError ,
189
+ { correlationId : '123-echo-tango-delta' } ,
190
+ ) ;
191
+
192
+ expect ( JSON . stringify ( e . extensions , null , 2 ) + '\n' ) . to . equal ( dedent `
193
+ {
194
+ "correlationId": "123-echo-tango-delta"
195
+ }
196
+ ` ) ;
197
+ } ) ;
198
+
199
+ it ( 'uses the provided extensions when original extensions are empty object' , ( ) => {
200
+ const original = new Error ( 'original' ) ;
201
+ const graphqlError = new GraphQLError (
202
+ 'msg' ,
203
+ null ,
204
+ null ,
205
+ null ,
206
+ null ,
207
+ original ,
208
+ { } ,
209
+ ) ;
210
+
211
+ const e = new GraphQLError (
212
+ graphqlError . message ,
213
+ null ,
214
+ null ,
215
+ null ,
216
+ null ,
217
+ graphqlError ,
218
+ { correlationId : '123-echo-tango-delta' } ,
219
+ ) ;
220
+
221
+ expect ( JSON . stringify ( e . extensions , null , 2 ) + '\n' ) . to . equal ( dedent `
222
+ {
223
+ "correlationId": "123-echo-tango-delta"
224
+ }
225
+ ` ) ;
226
+ } ) ;
167
227
} ) ;
168
228
169
229
describe ( 'printError' , ( ) => {
You can’t perform that action at this time.
0 commit comments