How to handle Pagination and cache edition at the same time
Hello,
I am requesting paginated elements from my back-end. To get the refetched result, I use the same method as the one shown in the doc (editing the vars and setting the updateResult)
On the same page, I can also create new elements. After their creation, I add them to the cache (using the same method as the doc).
My issue is that adding elements to the cache using 'writeQuery' executes the 'updateResult' function I set when fetching more data. This means that the refetched data is added once again to the combined results, and is therefore shown twice on my page.
Is there a simple way to prevent 'writeQuery' from executing 'updateResult'? It would be cleaner than changing my 'updateResult' to make sure I am not adding already existing data.
What FetchPolicy are you using?
If you're using a FetchPolicy that involes the cache, writeQuery will cause a new result from the cache, meaning that updateResult will be called with the previous and current query results. This is the expected behavior, even if it doesn't work for your use case.
The easiest approach would be to use a FetchPolicy that avoids the cache. Obviously, that may not be viable.
We probably could update the updateResult method to include the entire OperationResponse object instead of just the data. That way, you could only concatenate the results if 1) the response is coming from DataSource.Link and 2) the requests have different variables.
Is there any update for updateResult method?
This mechanism is still blocking pagination and cache work together.
As a workaround.. I added ID field for each XXXConnection (page) types.
So when fetching new pages, each pages can be cached separately and updated separately too.
It made caching and pagination by updateResult work together.
Even It fixed above issues but still I don't feel it is a fine solution.