Intended 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
@dallonf this should actually already be fixed with the 2.0 👍
@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.
Yup, here's a sandbox with the latest version of everything:
https://codesandbox.io/s/jplj2wp8l9
(Note the dependency on [email protected] - in the current production version of react-apollo, you'll instead observe https://github.com/apollographql/react-apollo/issues/1336, which masks this issue)
Confirmed on
[email protected]
[email protected]
ObservableQuery.currentResult() creates a new ApolloError on each return thus not allowing referential checks.
@danilobuerger if this is still an error, can you open a new issues instead please?
Most helpful comment
@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.