-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache.write warns "Cache data may be lost" when removing properly normalized object from list in cache #6451
Comments
The test sandbox also shows the following error |
@yngwi Thanks for the reproduction! In this case, there's one more step you need, just before calling cache.evict({
// Often cache.evict will take an options.id property, but that's not necessary
// when evicting from the ROOT_QUERY object, as we're doing here.
fieldName: "notifications",
// No need to trigger a broadcast here, since writeQuery will take care of that.
broadcast: false,
}); This eviction tells the cache that the existing Another way to remove elements from a list without having to do cache.modify({
notifications(list, { readField }) {
return list.filter(n => readField("id", n) !== id);
},
}); |
@benjamn Thank you for your reply, what you write makes perfect sense. So is there a drawback to cache.modify as it sounds much simpler than the read/write approach I used and also the additional cache.evict step? Regards, |
Well,
|
Thank you for your clarifications, this helps me very much. |
Thank you, this really helped me out! Isn't there a way to have the cache automatically update when items are added and deleted? Seems like this would be something very common using GQL |
Thanks @benjamn your responses were the best explanations I found and helped a lot. Thought I would add an updated version of the current cache.modify cache.modify({
fields: {
notifications(list, { readField }) {
return list.filter((n) => readField('id', n) !==id)
},
},
}) Could be good to use |
Although |
That would be helpful. |
This warning also appears when using the |
Intended outcome:
When resolving a @client mutation that removes an item from a list in the cache, the item should be removed without a warning.
Actual outcome:
The client reports the following error:
How to reproduce the issue:
I've created a sandbox illustrating the issue. Clicking on "add" adds a new notification that will remove itself after a short while by calling the
removeNotification
mutation (see thenotification
resolver and theNotification
component).As far as I can tell the object can be properly normalized and I followed the basic documentation on how to use
cache.writeQuery
.Versions
The text was updated successfully, but these errors were encountered: