Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Errors lost on cached results after errorPolicy: "all" #1781

Closed
dumaron opened this issue Mar 12, 2018 · 6 comments · Fixed by #2753
Closed

Errors lost on cached results after errorPolicy: "all" #1781

dumaron opened this issue Mar 12, 2018 · 6 comments · Fixed by #2753

Comments

@dumaron
Copy link

dumaron commented Mar 12, 2018

I'm using apollo and react to call a query that returns mixed results: error(s) and some data.
In order to handle the errors, but still be able to use the information given, I'm using the errorPolicy: "all" option in the query.

<Query query={query} variables={variables as any} errorPolicy='all'>
    {({loading, error, data}) => { ... }}
</Query>

The first time I mount the component data is populated with the partial informations and error with the errors returned by the query. If I change the route (unmounting the component) and then return on it, it shows the cached partial data but no errors, so I'm not able to handle errors anymore and detect that these are partial informations.

Intended outcome:
The component shows me the original errors along with the cached data.

Actual outcome:
The props error is undefined, the partial data are passed as if the query didn't return any error.

How to reproduce the issue:
I don't know how to reproduce a query that returns both data and error; anyone can help me with that so I can show you some working code?

Version

  • apollo-client@2.2.6
  • react-apollo@2.1.0-rc.3

Initially I tought that issue #1389 could related to this problem, but after all I think these are 2 different things. Maybe it's something related with the RC version I'm using?

@adamesque
Copy link

We have a similar issue which manifests during SSR; getDataFromTree runs our app's queries and caches them. With errorPolicy: "none", this function throws an exception if any query errors out, but with errorPolicy: "all", the null (or partial) result is cached and no exception is thrown. According to the docs, I'd expect errors for the queries to be cached as well.

However, if I set a breakpoint in my wrapped component during renderToString on the server, I see the cached null data, but data.error is undefined.

The wild thing is that if I set a breakpoint inside react-apollo's Query component, in getQueryResult, I can see that the error is present in this.queryObservable.queryManager.queryStore.store:
screen shot 2018-04-24 at 6 29 51 pm

The role of the queryStore isn't clear to me; I'm not sure if that's where errors are intended to be cached/retrieved from when the errorPolicy is "all", but they definitely don't seem to be supplied to Query's render prop children at the moment.

@marcogigliarano
Copy link

Is there any updates about this issue?

@tobobo
Copy link

tobobo commented Dec 14, 2018

I've opened a PR to fix the Apollo docs with respect to this issue as it doesn't seem like Apollo will support error cacheing anytime soon. apollographql/apollo-client#4237

@joepuzzo
Copy link

Can someone please explain the actual solve for the OG issue? I am not using any SSR, simply using apollo-cache-inmemory. It sounds like the fix is only if you decide to use SSR?

@joepuzzo
Copy link

joepuzzo commented Mar 27, 2019

@0xMarkian
Copy link

any updates on this @hwillson ?
The issue still exists for the apollo@3 - error isn't cached.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants