-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BREAKING] Expand didEncounterErrors API #4380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,9 +145,11 @@ export class RemoteGraphQLDataSource<TContext extends Record<string, any> = 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<TContext extends Record<string, any> = Reco | |
http: httpResponse, | ||
}; | ||
} catch (error) { | ||
this.didEncounterError(error, httpRequest); | ||
this.didEncounterError?.({ error, request: httpRequest, response: httpResponse, context }); | ||
throw error; | ||
} | ||
} | ||
|
@@ -183,9 +185,9 @@ export class RemoteGraphQLDataSource<TContext extends Record<string, any> = Reco | |
>, | ||
): ValueOrPromise<GraphQLResponse>; | ||
|
||
public didEncounterError(error: Error, _request: Request) { | ||
throw error; | ||
} | ||
public didEncounterError?( | ||
requestContextWithError: { error: Error, response?: Response, context: TContext, request: Request } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, a lengthy comment I wrote got on this line was lost (possibly because of a bug between the keyboard and the chair) and I cannot recover it. I'll try to come back to this later, but please forgive my lack of time to re-read my re-cobbled together from clipboard history response right now: The object that we colloquially refer to as the "request context" is the The object you are proposing that we pass here to I agree with the idea of unifying the API (and this If it is critical to also have user requestContext: GraphQLRequestContext<TContext>,
http: { error: Error, response: Response, request: Request },` Though will need to pause and consider whether we want the pattern to be "The request context is always the last argument", which can sometimes be more durable for other-use-cases, or if we'd prefer that it be the first parameter. I think there is existing art to consider in the plugin API on Anyhow, long-story-longer, but with less precision because I deleted everything and tried to ramble my way back through it: Maybe we can just add |
||
): ValueOrPromise<void>; | ||
|
||
public parseBody( | ||
response: Response, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what the original intention of this
throw
was, but I like the idea of removing it in the default implementation!