-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Cache.evict triggering an unintended network query #6746
Comments
I am attempting to migrate our project to Apollo Client 3 and seeing similar unwanted behavior when attempting to use |
Ahhh I see. I'll try that. Thanks for the response! |
You're welcome, @HummingBird24. I did a bit more work on this in our project and found that the
|
@KeithGillette This indeed prevents automatic network refetches, but it also prevents you from doing an actual network refetch. I'm not sure how to work around this behavior. |
@KeithGillette @gbilodeau See #6893 for some relevant improvements coming for |
This should no longer be an issue in |
Hi, I'm trying to delete a comment from a list in the cache by filtering out the comment and then using cache evict. I'd expect this to all be done without an additional query to the network. However, that is not the case. Calling cache.evict() triggers a network query for the comment list. If I don't call cache.evict() and instead only filter the comment out of the list, an additional network call is not triggered. When I look at APOLLO_CLIENT.cache.data.data, I can see that the comment was actually filtered from the list.
Intended Outcome: Filter Comment from comment list and use cache.evict() to delete comment from cache without additional network query to retrieve the comment list (without deleted comment).
Actual Outcome: Filter Comment from comment list and use cache.evict() to delete comment from cache and also query the new comment list from the network as a safety check
Here's what my update function looks like:
update(cache, { data: { manageComment } }) {
const data = cache.readQuery({
query: FETCH_COMMENTS,
variables: {post_id},
})
}
To reproduce the issue, I assume you can just call cache evict and see if a network query is called. I believe this is a bug because I don't see the point of messing with the cache if we're going to refetch as a safety check anyway but maybe I'm wrong. Thanks Apollo team for everything you've done! I appreciate it!
I also tried to filter out the comment in the typePolicies like so but that did not seem to help:
Query: {
fields: {
comments(existingComments, { canRead }) {
return existingComments
? existingComments.filter(canRead)
: []
},
comments: {
keyArgs: ['post_id'],
},
},
},
Versions
System:
OS: macOS Mojave 10.14.6
Binaries:
Node: 11.12.0 - /usr/local/bin/node
Yarn: 1.2.1 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Browsers:
Chrome: 84.0.4147.105
Safari: 13.1.2
npmPackages:
@apollo/client: ^3.0.2 => 3.0.2
The text was updated successfully, but these errors were encountered: