Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo isn't caching errors #4806

Closed
KevinHewson opened this issue May 13, 2019 · 4 comments
Closed

Apollo isn't caching errors #4806

KevinHewson opened this issue May 13, 2019 · 4 comments

Comments

@KevinHewson
Copy link

KevinHewson commented May 13, 2019

After navigating in my React app, I'm noticing that the errors that occurred after a successful query are not getting cached.

I'm using errorPolicy: "all". According to the documentation here, I would expect that it "saves both data and errors into the Apollo Cache"

Intended outcome
When GraphQL returns

{
  data: { ... },
  errors: [...]
}

I would expect Apollo to cache both data and errors.

Actual outcome
Apollo will pull data from the cache, but not errors. error ends up being undefined.

How to reproduce the issue
Create a query that results in an error and data. Navigate away from component and then back and notice that the data will get pulled from cache, but errors will not.

Version
apollo-client version 2.5.1
react-apollo version 2.5.2

@KevinHewson
Copy link
Author

I did some more digging through the reported issues, and I think I have found a related issue #4644. This appears to be a pretty critical bug, especially since the documentation specifically states that it should be caching both data and errors.

@hwillson
Copy link
Member

Please open a feature request for this in https://github.com/apollographql/apollo-feature-requests. Thanks!

@KevinHewson
Copy link
Author

I just want to make sure I understand this correctly. Are you saying the documentation is incorrect when it says

all: Using the all policy is the best way to notify your users of potential issues while still showing as much data as possible from your server. It saves both data and errors into the Apollo Cache so your UI can use them.

If that's true, then I guess I agree that this should be a feature request. But if not, this is clearly a bug that should be fixed because the errors are not saved to the cache.

@hwillson
Copy link
Member

It saves both data and errors into the Apollo Cache so your UI can use them.

@KevinHewson the above used to be technically accurate, but is unfortunately a bit misleading. When people read this they think that errors are saved into the in-memory based normalized cache itself, as in what you see if you dump out window.__APOLLO_CLIENT__.cache.data.data in your browser console. This doesn't happen. Instead, the previous error is saved in memory, so it can be sent back to the UI. The saving of this error in memory used to be part of the Apollo Cache codebase, which is where the wording of the above came from. Apollo Cache is being used here to represent all of the Apollo Cache functionality, not just the actual data store. A lot of this has changed in Apollo Client 3, but errors are still not stored in the cache itself. This is something we would like to consider doing though, so a feature request to track this would be great. I'll also update the docs to be more clear. Thanks!

hwillson added a commit that referenced this issue Aug 16, 2020
Errors are saved in memory for use by an application's UI, but they
are not stored in the actual cache itself. The original wording here
leads people to believe they are, so this PR tweaks the wording a
bit.

Related to: #4806
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants