diff --git a/gateway-js/CHANGELOG.md b/gateway-js/CHANGELOG.md index d283db2c5..c5c594653 100644 --- a/gateway-js/CHANGELOG.md +++ b/gateway-js/CHANGELOG.md @@ -4,6 +4,8 @@ > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section. +- Include original error during creation of `GraphQLError` in `downstreamServiceError()`. [PR #309](https://github.com/apollographql/federation/pull/309) + ## v0.21.4 - Update version of `@apollo/federation` diff --git a/gateway-js/src/executeQueryPlan.ts b/gateway-js/src/executeQueryPlan.ts index 6844385b0..7a24606a3 100644 --- a/gateway-js/src/executeQueryPlan.ts +++ b/gateway-js/src/executeQueryPlan.ts @@ -9,6 +9,7 @@ import { Kind, TypeNameMetaFieldDef, GraphQLFieldResolver, + GraphQLFormattedError, } from 'graphql'; import { Trace, google } from 'apollo-reporting-protobuf'; import { defaultRootOperationNameLookup } from '@apollo/federation'; @@ -316,12 +317,10 @@ async function executeFetch( if (response.errors) { const errors = response.errors.map(error => downstreamServiceError( - error.message, + error, fetch.serviceName, source, variables, - error.extensions, - error.path, ), ); context.errors.push(...errors); @@ -452,13 +451,17 @@ function flattenResultsAtPath(value: any, path: ResponsePath): any { } function downstreamServiceError( - message: string | undefined, + originalError: GraphQLFormattedError, serviceName: string, query: string, variables?: Record, - extensions?: Record, - path?: ReadonlyArray | undefined, ) { + let { + message, + extensions, + path, + } = originalError + if (!message) { message = `Error while fetching subquery from service "${serviceName}"`; } @@ -477,7 +480,7 @@ function downstreamServiceError( undefined, undefined, path, - undefined, + originalError as Error, extensions, ); }