I’m trying to find a way to effectively update newly created “second class” objects in the InMemoryCache. By “second class”, I mean objects that depend on a parent object. When I’m creating these types of objects, I’ve already selected the “parent” object ID and creating new ones with this ID.
My queries (and there several) all filter these types of objects based on the parent object ID. Sometimes, there more qualifications than just the parent ID. These other qualifications are simply values of scalar fields.
So my first attempt was to use the update field of useMutation. I used cache.modify and it was invoked for each list of objects of this (child) type. The result is that these new objects were add to all lists of objects of this type independent of the parent object ID.
Is there a way to writing a field modifier function correctly to determine which list the new object should go into? Do I have to have intimate knowledge of all other queries in my application?
After the update/cache.modify approach failed, I went to using refetchQueries in my mutation function. This works, but I only supplied the “GET” query of the current page. There are many pages in my application and it’s clear/feasible to list all of the ones that might be affected.
Finally, I tried using refetchQueries: ‘active’, but it has the inadvertent side-effect of flashing as it has to reload all active queries.
For the other mutations (UPDATE, DELETE), my “update” functions are working fine and cleanly.