-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Update persisted query link error handling to match the rest of the client #12704
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
Conversation
🦋 Changeset detectedLatest commit: e5b8e87 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
size-limit report 📦
|
.changeset/sharp-glasses-sneeze.md
Outdated
}); | ||
``` | ||
|
||
The `response` property has also been removed. To access partial data returned in GraphQL responses, access the `data` property on the `CombinedGraphQLErrors` instance. |
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 think it makes sense to remove this, but one thing we did lose in this process is access to extensions
since CombinedGraphQLErrors
doesn't have an extensions
property. Is that something we want to add? Seems more relevant here especially since persisted queries does a lot with extensions.
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.
Yeah, it sounds like a good idea to add that to CombinedGraphQLErrors
!
@@ -789,3 +796,693 @@ describe("failure path", () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
test("disables persisted queries from future requests when `disable` returns true", async () => { |
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.
We didn't test disable
or retry
at all 😱
src/link/persisted-queries/index.ts
Outdated
|
||
const graphQLErrors: GraphQLFormattedError[] = []; | ||
function handleRetry(errorResponse: ErrorResponse, cb: () => void) { |
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.
The diff is a bit horrendous, but if you want to look at the refactor to see how I got here, check out the diff commit-by-commit.
@@ -24,9 +29,7 @@ import { defaultCacheSizes } from "../../utilities/caching/sizes.js"; | |||
export const VERSION = 1; | |||
|
|||
export interface ErrorResponse { | |||
graphQLErrors?: ReadonlyArray<GraphQLFormattedError>; | |||
networkError?: Error | ServerParseError | ServerError | null; | |||
response?: FormattedExecutionResult; |
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.
Response seems to also be available in onError
link so we should probably keep this around.
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.
Keep this. Rename it to result
. Rename the interface and have both a RetryFunctionOptions
and DisableFunctionOptions
that point to the same type.
.changeset/sharp-glasses-sneeze.md
Outdated
|
||
- if (errorResponse.networkError) { | ||
+ if (errorResponse.error) { | ||
// ... handle a NetworkError errors |
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.
// ... handle a NetworkError errors | |
// ... handle NetworkError-type errors |
not sure if this is strictly better, but the a
was irritiating me,.
.changeset/sharp-glasses-sneeze.md
Outdated
}); | ||
``` | ||
|
||
The `response` property has also been removed. To access partial data returned in GraphQL responses, access the `data` property on the `CombinedGraphQLErrors` instance. |
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.
Yeah, it sounds like a good idea to add that to CombinedGraphQLErrors
!
.changeset/sharp-glasses-sneeze.md
Outdated
disable: (errorResponse) => { | ||
- if (errorResponse.response) { | ||
- const data = errorResponse.response.data; | ||
+ if (CombinedGraphQLErrors.is(errorResponse.error)) { |
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.
Maybe we should rename errorResponse
and the ErrorResponse
type here? errorResponse.error
is seriously weird. Otoh., errorResponse.response
wasn't strictly better previously.
Just as food for thought: What about disablePayload
or even just payload
?
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.
Maybe we should just destructure in these examples? 🤔
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.
Good call! I did a bunch of updates in 0ed0931 to give better examples and use destructuring.
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.
And I agree, I'm not a huge fan of ErrorResponse
, but it does match what we have in onError
link. the only thing about something like disablePayload
is that this object is also passed to retry
.
00e32f0
to
0ed0931
Compare
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.
Generally approved, but needs the incremental error handling like the error link.
src/link/persisted-queries/index.ts
Outdated
error: new CombinedGraphQLErrors(response), | ||
meta: processErrors(response.errors), |
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 added a better way to handle incremental stuff here - take a look at
apollo-client/src/link/error/index.ts
Lines 47 to 51 in 61cfe94
const handler = operation.client["queryManager"].incrementalHandler; | |
const errors = | |
handler?.isIncrementalResult(result) ? | |
handler.extractErrors(result) | |
: (result as FormattedExecutionResult).errors; |
}); | ||
}); | ||
|
||
test("calls `retry` with GraphQL errors when parsed from non-2xx response", async () => { |
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'm thinking here... do we want to do that kind of parsing or go the "GraphQL over Http" route and only do this with the right mime-type (in which case we don't need any extra logic)?
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.
Let's leave this for now until servers catch up with the GraphQL over HTTP spec.
0ed0931
to
e1f553e
Compare
Closes #12569
Updates
createPersistedQueryLink
to combinegraphQLErrors
andnetworkError
properties into a singleerror
property to match the rest of the client.error
is of typeErrorLike
.The
response
property has also been removed in favor of accessingdata
from theCombinedGraphQLErrors
instance.