Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/error/GraphQLError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ function toNormalizedOptions(
): GraphQLErrorOptions {
const firstArg = args[0];
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
const originalError =
args[4] instanceof GraphQLError && args[4].originalError
? args[4].originalError
: args[4];

return {
nodes: firstArg,
source: args[1],
positions: args[2],
path: args[3],
originalError: args[4],
originalError,
extensions: args[5],
};
}
Expand Down
24 changes: 24 additions & 0 deletions src/error/__tests__/GraphQLError-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ describe('GraphQLError', () => {
});
});

it('uses correct originalError for deprecated declaration of GraphQLError', () => {
const originalError = new Error('original');
const graphQLError = new GraphQLError('msg', {
originalError,
});
const deprecatedError = new GraphQLError(
'msg',
null,
undefined,
undefined,
undefined,
graphQLError,
);
const expectedError = new GraphQLError('msg', graphQLError);

expect(deprecatedError).to.include({
name: 'GraphQLError',
message: 'msg',
stack: originalError.stack,
originalError,
});
expect(deprecatedError).to.deep.equal(expectedError);
});

it('creates new stack if original error has no stack', () => {
const original = new Error('original');
const e = new GraphQLError('msg', { originalError: original });
Expand Down