diff --git a/gateway-js/CHANGELOG.md b/gateway-js/CHANGELOG.md index 3ff531803..ca762eede 100644 --- a/gateway-js/CHANGELOG.md +++ b/gateway-js/CHANGELOG.md @@ -4,7 +4,7 @@ > 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. -- _Nothing yet! Stay tuned!_ +- The `RemoteGraphQLDataSource`'s `didEncounterError` method will now receive [`Response`](https://github.com/apollographql/apollo-server/blob/43470d6561bee31101f3afc56bdd154db3f92b30/packages/apollo-server-env/src/fetch.d.ts#L98-L111) as the third argument when it is available, making its signature `(error: Error, request: Request, response?: Response)`. This compliments the existing [`Request`](https://github.com/apollographql/apollo-server/blob/43470d6561bee31101f3afc56bdd154db3f92b30/packages/apollo-server-env/src/fetch.d.ts#L37-L45) type it was already receiving. Both of these types are [HTTP WHATWG Fetch API](https://fetch.spec.whatwg.org/) types, not `GraphQLRequest`, `GraphQLResponse` types. ## v0.17.0 diff --git a/gateway-js/src/datasources/RemoteGraphQLDataSource.ts b/gateway-js/src/datasources/RemoteGraphQLDataSource.ts index 700e78e2f..9a92be9f4 100644 --- a/gateway-js/src/datasources/RemoteGraphQLDataSource.ts +++ b/gateway-js/src/datasources/RemoteGraphQLDataSource.ts @@ -145,9 +145,11 @@ export class RemoteGraphQLDataSource = Reco body: JSON.stringify(requestWithoutHttp), }); + let httpResponse: Response | undefined; + try { // Use our local `fetcher` to allow for fetch injection - const httpResponse = await this.fetcher(httpRequest); + httpResponse = await this.fetcher(httpRequest); if (!httpResponse.ok) { throw await this.errorFromResponse(httpResponse); @@ -164,7 +166,7 @@ export class RemoteGraphQLDataSource = Reco http: httpResponse, }; } catch (error) { - this.didEncounterError(error, httpRequest); + this.didEncounterError(error, httpRequest, httpResponse); throw error; } } @@ -183,7 +185,11 @@ export class RemoteGraphQLDataSource = Reco >, ): ValueOrPromise; - public didEncounterError(error: Error, _request: Request) { + public didEncounterError( + error: Error, + _request: Request, + _response?: Response + ) { throw error; }