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

feat(federation): Include originalError in downstreamServiceError #309

Merged
merged 8 commits into from
Jan 5, 2021
Merged
2 changes: 2 additions & 0 deletions gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
17 changes: 10 additions & 7 deletions gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Kind,
TypeNameMetaFieldDef,
GraphQLFieldResolver,
GraphQLFormattedError,
} from 'graphql';
import { Trace, google } from 'apollo-reporting-protobuf';
import { defaultRootOperationNameLookup } from '@apollo/federation';
Expand Down Expand Up @@ -316,12 +317,10 @@ async function executeFetch<TContext>(
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);
Expand Down Expand Up @@ -452,13 +451,17 @@ function flattenResultsAtPath(value: any, path: ResponsePath): any {
}

function downstreamServiceError(
message: string | undefined,
originalError: GraphQLFormattedError,
serviceName: string,
query: string,
variables?: Record<string, any>,
extensions?: Record<string, any>,
path?: ReadonlyArray<string | number> | undefined,
) {
let {
message,
extensions,
path,
} = originalError

if (!message) {
message = `Error while fetching subquery from service "${serviceName}"`;
}
Expand All @@ -477,7 +480,7 @@ function downstreamServiceError(
undefined,
undefined,
path,
undefined,
originalError as Error,
extensions,
);
}
Expand Down