Skip to content

Commit 332ce48

Browse files
committed
fix: property originalError when normalize for GraphQLError
1 parent 4a82557 commit 332ce48

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ describe('GraphQLError', () => {
7171
});
7272
});
7373

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

0 commit comments

Comments
 (0)