-
I am trying to implement a bookmarking button, so that when a user bookmarks (or de-bookmarks) a recipe, then it is added to their bookmarked recipe lists and when they navigate to the my recipe section in my React Native app they see their newely bookmarked recipe. I can successfully add and remove the bookmark from the server, AND directly write to cache if the bookmark button is bookmarked or not, but I am struggling to update the local cache on the my recipe view list. This is a list on a separate screen and the bookmarked recipes are queried through their user profile, instead of by each recipe. I have been trying to use cache.invalidate, but I just can't get it to evict the recipe_bookmark! I can successfully resolve the bookmark object, but when I change 'cache.resolve' to 'cache.invalidate', then nothing happens:
Works and returns:
I have created a custom key for the recipe_bookmarks using both the user_id and the recipe_id:
I can even use cache.resolve to see all the bookmarks that the user has:
Returns correctly:
But how do I specify that I want to evict specifically for example the third bookmark: "recipe_bookmarks:d78d39ed-8c94-4f11-aed7-e326338dc593:418" If I write cache.invalidate("recipe_bookmarks:d78d39ed-8c94-4f11-aed7-e326338dc593:418") then nothing happens either... Sorry a bit confused, hope someone can help me. Here is a screenshot of my urql devtool. As you can see, each recipe_bookmark is under Query (this is for the button) but then also correctly found under the users_by_pk (to display the list of all the users bookmarks) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
To add some additional information after debugging, I have also tried to just cache.invalidate the recipe_bookmark that is on the toplevel in 'Query'. But even when I can correctly get the cache.keyOfEntity and then pass it into cache.invalidate - it is not removed from the cache nor is the list of bookmarks for a user (that should be referencing the same objects) updated...
This is the query I am using to get the recipe_bookmark lists for each user:
And this is the query that gets the recipe_bookmark status for the 'Query' level, I assume that they should be referencing the same object as I set the keys to be the same for recipe_bookmarks?
|
Beta Was this translation helpful? Give feedback.
-
For people that might run into the same problem, I solved this by instead using a writeQuery and writing an empty array / object into the place I wanted to delete. I guess the cache.invalidate does not work in nested places or on root objects as they werent removed properly.
|
Beta Was this translation helpful? Give feedback.
For people that might run into the same problem, I solved this by instead using a writeQuery and writing an empty array / object into the place I wanted to delete. I guess the cache.invalidate does not work in nested places or on root objects as they werent removed properly.