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

After removing cached field refetch doesn't hit the cache policy and behaves unpredictably #6896

Closed
ErkinKurt opened this issue Aug 25, 2020 · 3 comments

Comments

@ErkinKurt
Copy link

Intended outcome:
In the following reproduction, I'm managing pagination with fetch more and field policies. When the user wants to refetch the data, the refetch query will execute with the initial query variables which is pageNumber: 0 and I'm totally fine with that. What I want to achieve is, I would like to delete the cached fields by using cache.modify (or with writeQuery and custom handling in merge function) and refetch the first 10 again so that I can get the fresh data when I execute fetchMore. I would like to see cache deletes the data and when refetch is executed I would like to see the fresh data hit my custom merge function.

Actual outcome:
In this case, cache deletes the data, refetch hits the graphql resolver but not hit the field policy. I thought that this is because I delete the root query field not the cached data itself. So I even do cache.gc() to delete everything, but; but still couldn't get it.

How to reproduce the issue:
Here is a reproduction link: https://github.com/ErkinKurt/react-apollo-error-template/tree/delete-cache-and-refetch

1-> Click Change Status Type: 1
2-> Click Load More
3-> Click refetch
4-> You will see empty data

** The interesting flow that I think because of the variable change cache gets the data:
1-> Click Change Status Type: 1
2-> Click refetch
3-> Nothing happens in UI
4-> Click Load More
5-> The second page will be received

Thanks for all your hardwork, it's an awesome library with lots of benefits.

Versions

System:
    OS: Windows 10 10.0.18363
  Binaries:
    Node: 12.16.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 84.0.4147.135
    Edge: Spartan (44.18362.449.0)
  npmPackages:
    @apollo/client: ^3.1.0 => 3.1.0
@ErkinKurt ErkinKurt changed the title After removing cached field refetch doesn't hit the cache policy and behaves unpredictable After removing cached field refetch doesn't hit the cache policy and behaves unpredictabley Aug 25, 2020
@ErkinKurt ErkinKurt changed the title After removing cached field refetch doesn't hit the cache policy and behaves unpredictabley After removing cached field refetch doesn't hit the cache policy and behaves unpredictably Aug 25, 2020
benjamn added a commit that referenced this issue Aug 25, 2020
@benjamn benjamn self-assigned this Aug 25, 2020
@benjamn benjamn added this to the Post 3.0 milestone Aug 25, 2020
@benjamn
Copy link
Member

benjamn commented Aug 25, 2020

@ErkinKurt Thanks to your reproduction, I am reasonably confident that updating to @apollo/[email protected] will solve the problem, with no changes to your code. See #6898, #6817, and #6448 for more details if you're interested.

@ErkinKurt
Copy link
Author

I'll try and get back to you as soon as possible. Thanks.

@ErkinKurt
Copy link
Author

I'm closing the issue since the release fixed the bug. Thanks for your hard work.

@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.
Projects
None yet
Development

No branches or pull requests

2 participants