Apollo-client: Concat data on refetch (e.g: For infinite scroll)

Created on 14 Jun 2016  路  5Comments  路  Source: apollographql/apollo-client

Hi,

I am trying to make an infinite scroll, the problem is actually when you refetch a query old data are erased. Maybe It can be good to pass some options on refetch ?
Something like that ? data.refetch({ newArgs }, { concat: true });

Most helpful comment

I am not sure that this belongs on refetch, personally - I'd be in favor of similar but alternative approaches, for example:

  1. A fetchMore method in addition to refetch
  2. A way to assemble an array of queries with different variables programmatically

I don't think refetch should be overloaded to do more than simply rerun a single query maybe with different variables.

All 5 comments

I asked pradel to open this issue so that we can discuss a minimal viable design for infinite scroll pagination, let's see if we can come up with something simple!

@pradel @stubailo I like the simplicity of data.refetch(<variables>, <settings>). The second argument can be expanded to control other aspects of refetching we may want to add in. To take it a step further, should we add concat on the WatchQueryOptions and the second arg of refetch allows overwriting of existing query options? This would allow polling changes as well as other additions to WatchQueryOptions

I am not sure that this belongs on refetch, personally - I'd be in favor of similar but alternative approaches, for example:

  1. A fetchMore method in addition to refetch
  2. A way to assemble an array of queries with different variables programmatically

I don't think refetch should be overloaded to do more than simply rerun a single query maybe with different variables.

Ok, I have the same needs and I would be interested to take on that issue and implement a fetchMore(variables) method. If you are open to that, I could start working on a PR.

Done thanks to @Slava and @rricard

Was this page helpful?
0 / 5 - 0 ratings