-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Pagination helper for sync scripts #856
Comments
Github's octokit has nice interface for pagination including iterators. That would really improve the DX 📈 for await (const response of octokit.paginate.iterator(
octokit.rest.issues.listForRepo,
{
owner: "octokit",
repo: "rest.js",
},
)) {
// do whatever you want with each response, break out of the loop, etc.
} |
Pretty elegant approach, thanks for sharing! If we want to keep it wrapping we could do something like this:
But this might make changing the pagination strategy for a specific API request more difficult. Another approach could be to build it entirely into
This last one would have the advantage that overwriting the pagination strategy for a specific endpoint is pretty easy, e.g.
I think this would be important because many APIs have different pagination strategies for some of their endpoints. |
You're right there's a need for different pagination strategies (page, cursor,..), which Github doesn't need. Personaly, I prefer the composition approach, but without a strong opinion. You could also add pagination params to the paginate function const requestParams = {
endpoint: '/xyz',
params: { 'abc': 'def' }
};
for await (const response of nango.paginate(nango.get(requestParams), {
strategy: nango.paginationStrategy.Cursor,
nextCursorParamName: 'abc',
nextCursorResponsePath: 'pages.next'
})) {
// do whatever you want with each response, break out of the loop, etc.
} |
No description provided.
The text was updated successfully, but these errors were encountered: