apollo-client: pollInterval not working with offset-based fetchMore pagination
I’m using fetchMore
to implement offset-based pagination as suggested in the docs, and that works. But when I add pollInterval
to refresh the data, it wipes out all the newly loaded data every time the interval triggers.
What am I doing wrong?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 34 (14 by maintainers)
Wouldn’t this issue actually be solvable when a
poll
used anupdateQuery
similar tofetchMore
? IfupdateQuery
had a parameter that told us if it was triggered by a poll, or a fetchMore request, we could update theprevResult
withfetchMoreResult
/pollResult
accordingly.I have an infinite list that uses
fetchMore
, but needs to be polled for items (think twitter). So basically same problem as y’all. This is how I solved it:My API is already implementing the cursor approach where I send the id of the latest item and it’ll give me the next 10.
firstItemId
to my api where instead of sending the next 10, it returns all newer itemsfirstItemId
every 2 secondsonCompleted
to manually add the new items to the cacheSo far it works. I can’t quite decide if it’s a clever solution or just a giant hack. Maybe it’s both 😄
@smeijer 's suggestion would 💯 fix this problem. Hope it gets implemented some time!
A little late, but one case for the
fetchMore
+polling
is on infinite lists.Just changing one variable doesn’t work, as the start of the list is than being removed. And polling is wished for to update information along the way.
It can for example happen that an item moves from “page 2” to “page 1” when sorting on a
modifiedAt
.After reading this issue, I’m still unsure what the way to go would be here.
My solution for this:
Workaround
Sure, but in that case you don’t get any benefit from using fetchMore to load the new page, since you’re going to reload the whole thing right afterwards anyway. I guess pagination is a misleading term - it should be something like “loading partial new data” or similar.
Sure I guess I just don’t consider this a case of pagination - since pagination is usually used to load only some data and not to reload everything. So IMO semantically pagination with polling doesn’t really make sense
@stubailo I believe that’s the approach @tmeasday was suggesting. And I really don’t know where I could’ve gotten this weird idea to use
fetchMore
from… 😉