-
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
useMutation onCompleted executed when errors present #9499
Comments
I'm on 3.5.10 and experienced this exact same behavior |
I have also faced the same on version 3.5.10. |
I just ran into this using
apollo-client/src/react/hooks/useMutation.ts Line 104 in 67a13b5
By comparison apollo-client/src/react/hooks/useQuery.ts Lines 505 to 513 in 67a13b5
The inconsistent behavior is surprising especially since the documentation doesn't reflect reality:
|
Same issue in |
I think what happens is normal, when you get a null data response, that's doesn't mean that you have errors, it's your response! |
Hey all 👋 Given that the documentation states that @abd30590 from what I understand with the GraphQL spec response format,
I'd expect the only time you'd ever see
|
+1 on this issue. It's a difficult bug for library users to work around due to the lack of errors + data in the onError and onComplete handlers. Thanks! |
Same issue in Does anybody know what could lead to this scenario? It does seem like an illegal state according to my limited understanding of the documentation, but I suspect that there's something I could fix on my end to get this working and it's just not obvious to me at this point. |
Hi, I have been using @apollo/client for a few years, and with
Now, since This change has been brought by this commit: e3d611d which fixes Edit: to avoid breaking changes, what about introducing |
Hey @adrienharnay 👋 I'll do my best to respond to a few of your comments here.
This was actually not quite the behavior specified in our documentation and as such, we classified it as a bug. If you take a look at our docs on the
Note here how this says "zero errors", not "zero network errors". Given that the client behaved differently than specified, we opted to fix this behavior to match the documented behavior. When we try and determine how to treat an issue, we typically look to our docs first to see how we are communicating the behavior. As such we treat our documentation as our source of truth when determining whether something is a bug or not. This was one of those cases where our documentation was different than the behavior, so we treated it as a bug fix and released it in a minor version.
This change was communicated both in our
Perhaps we could have called this out a bit better, so apologies if this change wasn't as clearly stated as it could have been. Let us know if you have recommendations on how we could have called this out in a way that was more understandable!
Unfortunately this is the downside to managing a library with such a large user base. What one set of users may see as a bug in behavior, others may come to rely on that behavior in their apps as a feature of the library. That means regardless of what decision we make, we always make someone unhappy. Just to reiterate, we viewed this as a buggy behavior because our documentation communicated a different behavior, hence why the minor release felt appropriate. I sincerely apologize this resulted in a breaking change to you!
We will definitely take this into consideration! I can't guarantee we will do something like this, but can absolutely understand how the name of this callback can be confusing. If you don't mind me asking, what do you typically use these callbacks for? I'm trying to gather feedback on how devs use these callbacks so we can better communicate how/when to use them. I appreciate the feedback and apologies again for what ended up as a breaking change to you! |
@sbassin apologies, just saw your reply as well. If you're still seeing different behavior in a 3.8.x release, do you mind opening a new issue with a reproduction? It's not clear to me what might be happening. Thanks! |
Hi @jerelmiller, thank you for your answer. I don't agree with the strategy that the documentation was correct but not the code (for - to my knowledge - at least 3 years), so the change is not a breaking change. It is still a breaking change in my opinion. As for the changelog, the commit was documented yes, but the commit was not only about As for how we use
|
Hey @adrienharnay, First off, again I want to apologize for the fact that you experienced a breaking change in your app due to this bug fix. It was not the intention, nor did I realize people relied on this behavior.
I'm not sure I agree, otherwise we'd never be able to fix bugs since a bug fix is a change in behavior from the perspective of the code. On top of that, devs aren't reading our code for correctness and behavior (typically), they are reading our documentation and I believe the documentation accurately represents the intention of the original API design. I also believe the documentation reflects the original intent because of the type of that function: onCompleted?: (data: TData, clientOptions?: BaseMutationOptions) => void; Note here how onCompleted: (data) => {
if (!data) {
console.log('this should be impossible, according to the type')
}
} This is further supported by this issue itself, which was opened in March 2022, and with plenty of followup comments describing that the expected behavior was that
I can absolutely understand why you feel this way from the outside looking-in. Given the amount of time this behavior existed, it appears as if we intentionally left this behavior in there. The unfortunate reality (or fortunate depending on how you look at it 😆) of maintaining a heavily utilized project such as Apollo Client, especially with a team that is as small is ours, is that things just can slip through the cracks unintentionally. A year ago we had over 600+ open issues and we've managed to bring that to ~470 today. It is just not possible to address every issue and move the project forward in a meaningful way, despite our best intentions.
This is a fair criticism. Given that I approved that PR, including the changelog verbiage, this one is on me. I'll see if I can make an update to the existing changelog entry that better reflects the underlying change to try and help others that may come across that changelog entry. At this point we are unlikely to reverse the behavior for the various reasons I've stated above. If the 3.8.x upgrade is too breaking for your app because of this change, I'd recommend staying on the latest 3.7.x version and update your use of Appreciate the response! |
Thank you for taking the time to answer, I appreciate the work you are doing on Apollo, supporting many apps. I do agree that the types were wrong for some time now (we actually patched them in our codebase). |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Intended outcome:
I have an
onCompleted
callback defined on the options ofuseMutation
. I only wantonCompleted
to execute when no errors are present; so, I've setdefaultOptions: { query: { errorPolicy: 'all' }, mutate: { errorPolicy: 'all' } }
on theApolloClient
.This is the expected functionality that is described on the docs
Actual outcome:
When a GraphqlError occurs, the
onCompleted
function is still executed with null data.How to reproduce the issue:
This is the gist of our setup. I'm working on reproducing the issue on a small app as well, and will post the links on here once that is up and running.
Versions
"@apollo/client": "^3.5.6"
The text was updated successfully, but these errors were encountered: