Using cache.writeFragment in a mutation update weird behavior #1663
-
Hi, Let me start by saying this might be my lack of understanding of how the @urql/exchange-graphcache works but let me explain what I am observing. I have a query "getTodo"
As expected when mutating using the "UpdateTodo" the update is reflected in the UI However, when using "LikeTodo" it does not. The LikeTodo's mutation update is very simple, cache.readFragment followed by a cache.writeFragment, incrementing a "like_count" and setting a field "liking" to true As a debugging step, I re-read the cache and it confirms my write has gone through ok. Is this expected? Or should the update using cache.writeFragment also update the query stream like the "automagical" one does for "UpdateTodo" Thanks in advance :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
It should definitely also update your entity and be reflected in the query; it's probably best if you'd return the entire entity in the mutation if possible since that caters more to your app then, but for the sake of ignoring the API since we're not talking about that, what does your code for that look like? And do you see any warnings in the console? |
Beta Was this translation helpful? Give feedback.
-
ok was kinda being a numpty on this one. As I had two version of the entity ("list" query was getting v2, "get" query was v1 ) updating one naturally didn't update the other. I can confirm if I update the correct entity then it is reflected in the query. Sorry for the time wasting 👎 |
Beta Was this translation helpful? Give feedback.
ok was kinda being a numpty on this one. As I had two version of the entity ("list" query was getting v2, "get" query was v1 ) updating one naturally didn't update the other.
I can confirm if I update the correct entity then it is reflected in the query.
Sorry for the time wasting 👎