question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors from `ObservableQuery.currentResult` are not referentially equal

See original GitHub issue

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

  • apollo-client@1.9.3
  • react-apollo@1.4.16

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dallonfcommented, Mar 20, 2018

@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.

1reaction
jbaxleyiiicommented, Oct 11, 2017

@dallonf this should actually already be fixed with the 2.0 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

apollographql/apollo-client | Coveralls - Test Coverage History ...
Return errors from `currentResult`. Fixes an issue where `currentResult` would return `loading: true` if the query had errored out.
Read more >
Handling operation errors - Apollo GraphQL Docs
These are errors encountered while attempting to communicate with your GraphQL server, usually resulting in a 4xx or 5xx response status code (and...
Read more >
@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components...
Read more >
apollo-client - Awesome JS
Make queries with a pollInterval respect the no-cache fetch policy, instead of writing ... will be referentially equal ( === ) if they...
Read more >
https://raw.githubusercontent.com/bendenoz/apollo-...
will be referentially equal (`===`) if they are deeply equal. ... `QueryManager#startQuery` - `ObservableQuery#currentResult` - Apollo Client now supports ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found