Cache Redirect not causing query to run on partial data when using lists
See original GitHub issueIntended outcome: Query should be sent to the server to receive the missing reference
Actual outcome: Query not sent to server and I get no data
How to reproduce the issue:
- Create a query that fetches a list of items based on a condition:
items(where: { id: $id }) {
...CoreItemFields
}
This will return [item]
- Create a cache redirect to the query
new InMemoryCache({
typePolicies: {
Query: {
fields: {
items: {
read(_, { args, toReference }) {
if (!!args.where?.id) {
return [toReference({ __typename: "Item", id: args.where.id })];
}
}
}
}
}
}
}
If you run a query that queries items that do not exist in the cache, the read function will run, returning a list of 1 reference as expected. But since the reference references to something that does not exist in cache, the query should run. But it doesn’t.
Versions System: OS: macOS 12.0.1 Binaries: Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node Yarn: 1.22.15 - ~/.yarn/bin/yarn npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm Browsers: Chrome: 95.0.4638.69 Safari: 15.1 npmPackages: apollo-server-express: ^3.3.0 => 3.4.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Advanced topics on caching in Apollo Client
Cache redirects In some cases, a query requests data that already exists in the cache under a different reference. For example, your...
Read more >Apollo Client - Cache Redirects for sub-types - Stack Overflow
I would like to configure cacheRedirects so that when I demand the Book.CoverColor or Cup.CoverColor (via allBooks for instance ); it will first ......
Read more >React Query 3: A Guide to Fetching and Managing Data
For every API endpoint, you'll need to deal with state management, synchronization, caching and error handling. In this article, you'll learn ...
Read more >Cache-Control - HTTP - MDN Web Docs
If you want caches to always check for content updates while reusing stored content, no-cache is the directive to use.
Read more >How can I make Chrome stop caching redirects? - Super User
It's not a perfect solution, but I was able to prevent Chrome from using the cached redirect by passing a bogus query string,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same here since we upgraded to 3.x (no issue in 2.x), but I use a workaround. If one ref is missing from cache, I disable the cache redirect to trigger the query.
Something like that :
I hope this can help.
I think I ran into this same problem here: https://community.apollographql.com/t/apollo-inmemory-cache-type-policy-for-query-with-list-of-ids-as-argument/1989