From 9c1e85306e2ab10fb1a458d889f0f9a613c7217d Mon Sep 17 00:00:00 2001 From: alexfaunt Date: Wed, 15 Nov 2017 15:40:32 +0000 Subject: [PATCH] Maintain original errors where possible --- CHANGELOG.md | 6 +++++- src/stitching/errors.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e24d3144335..4fa05091448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.8.0 diff --git a/src/stitching/errors.ts b/src/stitching/errors.ts index ee6869fed3b..fdac4cbb3d7 100644 --- a/src/stitching/errors.ts +++ b/src/stitching/errors.ts @@ -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, @@ -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), );