apollographql / reason-apollo

Reason binding for Apollo Client and React Apollo
MIT License
548 stars 108 forks source link

How to create infinite loading component #35

Closed thangngoc89 closed 6 years ago

thangngoc89 commented 6 years ago

I've been looking for create an infinite loading component. But it's very hard to do it with the current declarative API. I ended up cloning reason-apollo (again) to implement such feature. So I want to open an issue to discuss with you guys first before working on a PR. I see 2 possible ways to solve this:

  1. Implement fetchMore like react-apollo. This adds complexity to the project
  2. Provide an imperative API so this kind of feature could be implemented in userland
Gregoirevda commented 6 years ago

fetchMore is probably the way to go, but it would be interesting to see a Component based approach... We are currently calling query on the ApolloClient, which returns a promise. If we want to have the update fetchMore ... functions back from the query we should call watchQuery which returns an ObservableQuery

Since Reason React has a Subscriptions helper now, we should find a nice way to implement it

thangngoc89 commented 6 years ago

I guess I need to do my homework to see how React Apollo does this. I'm using RR's state as a store for storing all the fetched data. It's hacky and probably inefficient because Apollo client already has its cache store.

Gregoirevda commented 6 years ago

yep, Apollo Client does all that work. We should just bind all the things

thangngoc89 commented 6 years ago

Thank you for the tip. I'm gonna work on it.

jeffutter commented 6 years ago

Any update on this? I'm converting a react project that uses fetchMore and am wondering how to implement this.

Gregoirevda commented 6 years ago

We're binding react apollo 2.1 Query and Mutations components, so it will be fixed at that moment. Should be released very soon

Gregoirevda commented 6 years ago

bindings to react-apollo 2.1 have been published 🎉 It contains the fetchMore prop, as react-apollo 2.1 does: https://github.com/apollographql/reason-apollo/blob/master/src/graphql-types/ReasonApolloQuery.re#L19