-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
There was a undescribed "Breaking change" in useMutation hook #9065
Comments
Also noticed that the following code does not work: await doMutation({
onError: (error) => console.log(error), // This is never called, errors keeps getting throwed
}) |
The commit you’re referencing was only merged in 3.5, and was mainly a rote refactoring of the hook so I didn’t have to reason about code across 15 files, so I don’t think that’s the behavior change you’re looking for. Might be related to this issue: #8793 |
Closing as a duplicate of #8793, let me know if you don’t think was right! |
@brainkim don't really think its a related to #8793 as that ticket wants to use the I think either the interface needs to be updated or (my preference) the errors should always be returned. |
@TriPSs |
Yea, if the line where it now throws the error would return it just like it does a couple of lines above it the behaviour would be how it was. Currently we have it this was in a lot of places, so if this behaviour won't work anymore we would have to refractor all off those and add empty try catches to it otherwise our error reporting tool will send un needed messages. |
I think I can enable the behaviour I want by setting the following on my Apollo client:
@brainkim could you confirm this? |
Hi @TriPSs, I'm having the same problem. It is in my opinion an unexpected behavior because when i can get an error returned i expect that it does not throw an error. In addition it isn't documented: Currently my solution looks like this: class ApolloCatchError implements ApolloQueryResult<undefined> {
data = undefined;
loading = false;
networkStatus = NetworkStatus.error;
errors = [];
constructor(public error: ApolloError) {}
}
async function fetchUser() {
return gqlClient
.query<QueryCurrentUserData, QueryCurrentUserVariables>({
query: QUERY_CURRENT_USER,
fetchPolicy: 'network-only',
})
.catch((error: ApolloError) => new ApolloCatchError(error));
} This is a typesafe solution providing the same result as @TriPSs and me expect |
Hi there, it's been months, and I see that this issue has been fixed on Thanks for your work 🙆♂️ |
TriPSs comment about changing the error policy worked for me, this should be documented! The error policy default value does not work as described in the docs! |
The highlighted part does not work at all, at least not in React. The onError and onComplete handlers are not executed at all when GraphQL Errors or Network Errors happen. It only worked with the "all" value, but the description for the "none" value suggests I would have at least the onError callback fired. |
Since this commit there was a "breaking change" in the
useMutation
hook.Intended outcome:
When doing the following code:
errors
was filled if there was an error from the APIActual outcome:
Error is now thrown instead of returned.
How to reproduce the issue:
Versions
Everything after 3.4.0
Tasks
The text was updated successfully, but these errors were encountered: