Idiomatic way of doing infinite-scroll mutations

I’m new to GraphQL and i’ve been implementing the “Relay Connection Specification” for doing cursor-based pagination on my backend. This works very well and I have easily achieved an “infinite scroll” using Apollo Client’s fetchMore but there is one catch: mutations.

How are we, idiomatically, going to handle mutations such as an entry being deleted or updated? Do i have to do local mutations to the cache? Should i refetch that “page”, and if so, how do i know which cursor it was using? I just know the ID of the object being deleted.

A Facebook feed is a good example. If i go to my own feed and scroll far, far down and delete a post it will disappear. Same goes for edits, it just works. Doing local mutations to the cache seems repetetive & error-prone to me, but what are the alternatives (if any)?

1 Like

For now i’m just doing cache.evict & cache.gc to remove the item from the local cache. Seems to work fine, but i wonder how it will be when it comes to updating…

Generally updating the cache with the results from a mutation is good for keeping things in sync.

You could also use subscriptions, but typically that’s for a pub/sub style of getting updates, which isn’t really necessary if your application is performing mutations and no other clients need to see that updated data immediately.

1 Like