React-apollo: Errors lost on cached results after errorPolicy: "all"

Created on 12 Mar 2018  路  6Comments  路  Source: apollographql/react-apollo

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

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?

Most helpful comment

Is there any updates about this issue?

All 6 comments

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.

Is there any updates about this issue?

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. https://github.com/apollographql/apollo-client/pull/4237

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?

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomitrescak picture tomitrescak  路  3Comments

bdouram picture bdouram  路  3Comments

borisyordanov picture borisyordanov  路  3Comments

reggi picture reggi  路  3Comments

voodooattack picture voodooattack  路  3Comments