Replies: 1 comment 2 replies
-
I wish I could tell you that live queries were already a thing — but unfortunately they're not 🥲 Anyway, can you expand on this please? It sounds like you've got a good handle of what's going wrong, but unfortunately I'm not quite sure here what the full story and issue re. this:
This should basically work and I'd expected it to work (with some limitations). If you have a notifications query, and I'm assuming once the notification comes back, the API is expected to also contain that new notification if you were to query it, your update is somehow being erased? Is that right? Basically, let's say you fetch your query data once, and then the subscription updates it,
So, let's make sure that none of the above is happening first 🤔 |
Beta Was this translation helpful? Give feedback.
-
I'm working on a reddit clone app and have set up a newNotification subscription which is triggered whenever a user votes on a post. I am trying to combine the accumulated results from the newNotification subscription with a (paginated) notifications query.
Initially I tried to do this the way it is recommended in the docs as below:
The issue with the above implementation is that if I then navigate to another page and reopen my notifications, I lose the subNotifsData and since the cached notifications query wasn't updated - this results in outdated notifications (displaying only those from the original query result).
I tried to get around this by first updating the notifications query with the cache.updateQuery fn inside my urql-client cacheExchange by appending the below to the updates object, and then just using notifsQueryData as my displayedNotifs however this produces a different bug where the first time I trigger the newNotification subscription it works as expected, however after the 1st trigger I occasionally only see the most recent newNotification (as well as the initial query results before updates) displayed since the data variable in my update query function is incorrectly reading the original notifications query rather than the one which has just been updated via the previous subscriptions.
I've tried invalidating the cache each time the newNotification subscription is triggered however this doesn't integrate with pagination.
The ideal solution would be either ensuring that when I update the cache I am updating the most recently updated version of the cache rather than the initial cached query result. Alternatively another ideal solution would be a way to invalidate the notifications query cache when I lose access to my subscription data.
Beta Was this translation helpful? Give feedback.
All reactions