cache.modify INVALIDATE doesn't result in query refetching data

Author: vedraniCreated Sep 23, 2020Updated Sep 2, 2026
Labels💸 caching

Intended outcome:

My motivation is to invalidate data in cache, so that queries can refetch invalidated data. (For that reason I just return _id from mutation. I know I can return data with mutation, but this scenario has implication on invalidating data on mutations with side effects.)

For that purpose I'm using cache.modify and INVALIDATE flag to invalidate data in cache based on docs.

My expectation is that invalidation will result in query refetching data from server because data is not valid any more.

I also tried evict and it works, but my impression is that invalidate mechanism should allow us to refetch data based on dirty status. Did I miss something in code or did I misunderstood it? Thanks!

Codesandbox

Actual outcome:

Query that fetches all todos is reobserved but it doesn't refetch data.

I tried to debug it and it seems cache diff is non existent. After cache.modify invalidation, query is reobserved but data is resolved from cache instead refetched.

What I found is that INVALIDATE is translated into dirty status here, but Query when calculating diff doesn't see any difference here

How to reproduce the issue:

Open Codesandbox and try to change status of todo item.

It doesn't change.

Versions

System: OS: macOS 10.15.5 Binaries: Node: 14.2.0 - ~/.nvm/versions/node/v14.2.0/bin/node Yarn: 1.22.5 - ~/.yvm/versions/v1.22.5/bin/yarn npm: 6.14.4 - ~/.nvm/versions/node/v14.2.0/bin/npm Browsers: Chrome: 85.0.4183.121 Firefox: 75.0 Safari: 13.1.1 npmPackages: @apollo/client: 3.2.0 => 3.2.0

Source: apollographql/apollo-client