Skip to content

Commit 006f980

Browse files
committed
fix: return correct originalError after normalize for deprecated GraphQLError
1 parent 4a82557 commit 006f980

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/error/GraphQLError.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ function toNormalizedOptions(
4545
): GraphQLErrorOptions {
4646
const firstArg = args[0];
4747
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
48+
const originalError =
49+
args[4] instanceof GraphQLError && args[4].originalError
50+
? args[4].originalError
51+
: args[4];
52+
4853
return {
4954
nodes: firstArg,
5055
source: args[1],
5156
positions: args[2],
5257
path: args[3],
53-
originalError: args[4],
58+
originalError,
5459
extensions: args[5],
5560
};
5661
}

src/error/__tests__/GraphQLError-test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ describe('GraphQLError', () => {
7171
});
7272
});
7373

74+
it('uses correct originalError for deprecated declaration of GraphQLError', () => {
75+
const originalError = new Error('original');
76+
const graphQLError = new GraphQLError('msg', {
77+
originalError,
78+
});
79+
const deprecatedError = new GraphQLError(
80+
'msg',
81+
null,
82+
undefined,
83+
undefined,
84+
undefined,
85+
graphQLError,
86+
);
87+
const expectedError = new GraphQLError('msg', graphQLError);
88+
89+
expect(deprecatedError).to.include({
90+
name: 'GraphQLError',
91+
message: 'msg',
92+
stack: originalError.stack,
93+
originalError,
94+
});
95+
expect(deprecatedError).to.deep.equal(expectedError);
96+
});
97+
7498
it('creates new stack if original error has no stack', () => {
7599
const original = new Error('original');
76100
const e = new GraphQLError('msg', { originalError: original });

0 commit comments

Comments
 (0)