Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain original errors through stitching #485

Closed
wants to merge 2 commits into from
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

### VNEXT

* ...
...

### v2.8.1

* When concatenating errors maintain a reference to the original for use downstream [Issue #480](https://github.com/apollographql/graphql-tools/issues/480) [PR #485](https://github.com/apollographql/graphql-tools/pull/485)

### v2.9.0

Expand Down
12 changes: 11 additions & 1 deletion src/stitching/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export function getErrorsFromParent(
};
}

class CombinedError extends Error {
public errors: Error[];
constructor(message: string, errors: Error[]) {
super(message);
this.errors = errors;
}
}

export function checkResultAndHandleErrors(
result: any,
info: GraphQLResolveInfo,
Expand All @@ -80,8 +88,10 @@ export function checkResultAndHandleErrors(
const errorMessage = result.errors
.map((error: { message: string }) => error.message)
.join('\n');
const combinedError = new CombinedError(errorMessage, result.errors);

throw locatedError(
errorMessage,
combinedError,
info.fieldNodes,
responsePathAsArray(info.path),
);
Expand Down