-
Hi everyone. I have a very interesting and non-trivial situation regarding subscriptions to queries to be able to get an optimistic response. I'm using client.query API for it Basically, I have a react app and I don't use hooks so I must use the standard uqrl client API. I used the standard The most trickiest part in this setup it's the next problems I faced:
While the 1 problem could be easy solving by using some cache/registry with unique keys the second one was a real challenge for me. But, I have some feelings that it's too complicated and could potentially bring some issues in future. so my question: Is this solution correct or did I just made some unnecessary mess? Could someone help me, please, with that? I don't know if the code will be helpful because there is a lot of it and I just don't know if someone interested in it so I don't want to annoy nobody. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm not sure if you'll necessarily have to handle this for queries. If you check the The deduplication should be handled for you however 🤔
This is not a trivial question. Alternatively, you can use Graphcache's pagination resolver, which is basically a "lazy" solution to allow one pagination query to map to all of them, so you don't have to handle this in the UI/binding code.
I don't know your code, but unfortunately, part of subscriptions/streams is that you always have to clean up after yourself. The same goes for any urql bindings, or any UI library effects. If you start an effect, you also need to define when it ends 😅 I have no suggestion for this and that's just how it is. At the very worst, you could just not care about pagination unsubscriptions and just bite the bullet and always keep them active indefinitely. Not efficient, but also, if you know something will never become inactive it's ok to skip unsubscriptions in some cases. I think the problem here is that you may have to think of coding patterns that remove some of the pressure and constraints you're dealing with. For example, if you unsubscribe from a page that becomes inactive to replace it with two pages, is it possible for you to unsubscribe, then replace the source with a combined one, and then subsequently resubscribe? |
Beta Was this translation helpful? Give feedback.
I'm not sure if you'll necessarily have to handle this for queries. If you check the
Client
, it basically already does a lot of deduplication and you only have to make sure you unsubscribe when you don't need results anymore.The deduplication should be handled for you however 🤔
This is not a trivial question.
In theory, you'll have to combine and keep multiple sources …