Open tdeedlesATX opened 4 years ago
While I see this as a bug, I'd understand if the team would want to categorize as a feature request. Please advise whether you'd need me to file in feature requests: https://github.com/apollographql/apollo-feature-requests
Hi 👋 ! A team of us are working on transitioning a production application to Apollo with use of hooks in React. We have the following use case:
error
anddata
may both have value)onError
,onCompleted
attributes to perform some side effectsIntended outcome:
I'd expect to be able to perform "completed" and "errored" functionality (one possibility: access
data
in myonError
callback if the errorPolicy="all"), since this would be a congruent outcome of thedata, error, loading
pattern commonly used when bothdata
anderror
may be populated.Actual outcome:
If there is a partial error from one of the fields, only
onError
is ever called. I think issue can be found in this either/or method (here in react-apollo, or here in apollographql/apollo-client). I'd wonder ifonError
could receivedata
as a 2nd ordinal argument in the event that there is both anerror
anddata
?How to reproduce the issue:
I've reproduced here: https://codesandbox.io/s/inspiring-surf-pcrgj?file=/src/App.js
Possible Solution
Possible solution 1: provide
data
as a 2nd ordinal argument toonError
One might also argue additionally (or alternatively) that
error
in theonCompleted
callback should be made available. Hence, in the case of errorPolicy="all" this dichotomy between "completed" and "errored" is somewhat difficult to discern. Hence:Possible Solution 2: Perhaps if developer does not define
onError
and errorPolicy is all, thenonCompleted
is always called with bothdata
anderror
?Possible Solution 3: Alternatively, and more generally it should just always call "onCompleted" with access to both
error
anddata
and we could remove the notion of onError entirely?**Many solutions to this perceived bug. These three solution proposals above are ranked in order from least to most invasive.
Version
@apollo/react-components@3.1.5