Errors from `ObservableQuery.currentResult` are not referentially equal
See original GitHub issueIntended outcome:
Using react-apollo
(although I think the issue is in apollo-client
, see below), I would like to trigger an imperative action (show an error notification) when a load error occurs. The most straightforward path to me is to compare props.data.error
with nextProps.data.error
, and if they are different, show the notification for the new error.
Actual outcome:
The data.error
prop is actually a new ApolloError
instance every time the component renders. Based on the stack trace, it appears to be created in ObservableQuery.currentResult
, which in turn is called by GraphQL.render
.
Because these errors are new for every render, the error notification will appear repeatedly. To get my intended behavior, I would have to compare error.networkError
and error.graphQLErrors
(which do seem to be referentially stable), which couples my generic error handling to implementation details of Apollo Client.
How to reproduce the issue:
Here is a sandbox:
https://codesandbox.io/s/9jon77z484
Note that whenever the graphql
wrapper is re-rendered (with any new props, to bypass the componentShouldUpdate
check), the error instance is new and so logs a new message, even though it is logically the same error.
Version
- apollo-client@1.9.3
- react-apollo@1.4.16
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
@jbaxleyiii I’m still seeing this issue in 2.2.7 - either it regressed or was never fixed. Let me try to recreate the sandbox with the latest version.
@dallonf this should actually already be fixed with the 2.0 👍