-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide a flowFromPaginatedQuery
on ApolloClient
to get all pages from a paginated query
#4180
Comments
Hi! This could be convenient but could also be a bit dangerous as this will potentially make a lot of network requests in a loop if there are many pages. For this maybe we could add some kind of a limit parameter, but overall this also feels a bit too specific to reside in the library and since it is only a few lines I think it's OK to keep it in your project? On a related note, we are looking at improving pagination scenarios related to the Normalized Cache, if you're interested you can monitor issue #3807. |
this would make at most 3 requests.
Regarding
that is a risk of any code that loops over multiple pages. :) Also, the flow won't trigger another request until the "collection" of the previous items is complete. e.g. this will make at most 1 request per second, because each collect takes at least one second.
maybe |
Hi! Sorry for the long delay! I think for now a separate artifact would be overkill but we could add this to the main artifact (apollo-runtime) as an |
Hi 👋 We've decided to not implement this for now as it can be done at the callsite. If anyone feels strongly this should be included by default, feel free to send a pull request. |
Use case
Would like get to have function to get a
Flow
of all pages from a paginated query.Describe the solution you'd like
Add something like the
flowFromPaginatedQuery
function below.Provide
extractCursorFromResponse
that describe how to get the cursor out of the response.And provide
queryFactory
that describes how to construct a new query given a cursor.Using the example from the tutorial you would do something like this:
The text was updated successfully, but these errors were encountered: