Skip to content

Commit 8ff5609

Browse files
committed
feat(gateway): Pass fetch.Response to didEncounterError after request
Relates to #4380, but in a non-breaking change, but also possibly just as a short-term band-aid while we figure out the details.
1 parent 43470d6 commit 8ff5609

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/apollo-gateway/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> 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.
66
7-
- _Nothing yet! Stay tuned!_
7+
- 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.
88

99
## v0.17.0
1010

packages/apollo-gateway/src/datasources/RemoteGraphQLDataSource.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ export class RemoteGraphQLDataSource<TContext extends Record<string, any> = Reco
145145
body: JSON.stringify(requestWithoutHttp),
146146
});
147147

148+
let httpResponse: Response | undefined;
149+
148150
try {
149151
// Use our local `fetcher` to allow for fetch injection
150-
const httpResponse = await this.fetcher(httpRequest);
152+
httpResponse = await this.fetcher(httpRequest);
151153

152154
if (!httpResponse.ok) {
153155
throw await this.errorFromResponse(httpResponse);
@@ -164,7 +166,7 @@ export class RemoteGraphQLDataSource<TContext extends Record<string, any> = Reco
164166
http: httpResponse,
165167
};
166168
} catch (error) {
167-
this.didEncounterError(error, httpRequest);
169+
this.didEncounterError(error, httpRequest, httpResponse);
168170
throw error;
169171
}
170172
}
@@ -183,7 +185,11 @@ export class RemoteGraphQLDataSource<TContext extends Record<string, any> = Reco
183185
>,
184186
): ValueOrPromise<GraphQLResponse>;
185187

186-
public didEncounterError(error: Error, _request: Request) {
188+
public didEncounterError(
189+
error: Error,
190+
_request: Request,
191+
_response?: Response
192+
) {
187193
throw error;
188194
}
189195

0 commit comments

Comments
 (0)