Hi,
I am having an issue while modifying cache depending on a mutation’s results.
Here is the related mutation:
const [mutationTrigger, mutationResult] = useMutation(MARK_MESSAGES_AS_READ, {
fetchPolicy: 'no-cache',
onCompleted({ mark_messages_as_read }) {
mark_messages_as_read.forEach(({ message_uuid, user_uuid }) => {
getGraphClient().cache.modify({
id: message_uuid,
fields: {
MESSAGES_READBY_USERs() {
return [{ user_uuid }]
},
},
})
})
},
})
I don’t want to cache the results, but I want to update other objects in cache depending on those results.
The issue I have is that the cache update does succeed, I get the updated values for half a second, and then it goes back to old value (an empty array).
As per the warning below, the cache data has been updated (the existing value), and a new incoming array is being merged. I can’t figure out where this empty array comes from, and according to docs modify
function should not trigger any merge function.
Defining the requested merge function doesn’t change anything.
I have tried several things, first with the 'network-only'
fetch policy and the cache’s type policies merge functions, then with the update
function of the mutation trigger returned by useMutation
, with the update
function of the hook’s options and finally with a 'no-cache'
policy, as per the example above.
It always leads to same result.
Any idea where it could come from?
Thanks,
Martin