Apollo client 3 evict object from cache

Viewed 3543

Using apollo client 3. Queried all countries and want to remove one country from cache and re-render UI.

Codesandbox

Tried like below;

onClick={() => {
 cache.evict({ id: `Country:${country.code}` });
 cache.gc();
}}

But didn't work. How to evict a country?

1 Answers

Eviction should be used this way;

onClick={() => {
   cache.evict({ id: cache.identify(country) });
   cache.gc();
}}

Now the country removed and page rerendered. Sandbox updated

Related