Skip to content
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

Feature: GraphQL Pagination #112

Closed
tisonkun opened this issue Jun 19, 2024 · 4 comments · Fixed by #121
Closed

Feature: GraphQL Pagination #112

tisonkun opened this issue Jun 19, 2024 · 4 comments · Fixed by #121
Labels
enhancement New feature or request GraphQL

Comments

@tisonkun
Copy link

Something like https://github.com/octokit/plugin-paginate-graphql.js

@yanyongyu yanyongyu added the enhancement New feature or request label Jun 19, 2024
@yanyongyu yanyongyu changed the title Pagination for GraphQL interface Feature: GraphQL Pagination Jun 19, 2024
@yanyongyu
Copy link
Owner

I'm not familiar with GraphQL pagination queries, but I can give it a try 😄

@tisonkun
Copy link
Author

@yanyongyu The main design of the SDK above is a convention:

        pageInfo {
          hasNextPage
          endCursor
        }

that the GraphQL query must have the pageInfo section. And it will extract the related fields to fulfill after: $cursor.

It should be possible for users to handle this iteration logic manually but an out-of-the-box API can help.

@tisonkun
Copy link
Author

And here is the related GitHub docs: https://docs.github.com/en/graphql/guides/using-pagination-in-the-graphql-api

@yanyongyu
Copy link
Owner

yanyongyu commented Jun 23, 2024

After a deep understanding of octokit plugin paginate graphql, I'll record some key points and notes here:

  • graphql pagination relies on the pageInfo object, and should be defined by user in the query.
  • graphql pagination should define an input cursor variable and octokit supports create cursor var name dynamically.
  • octokit does not support nested pagination and it seems hard to achieve.
  • octokit finds the pageInfo key of dicts recursively to detect pagination. [Ref]
  • octokit finds the path of the pageInfo object and merges the nodes and edges [Ref]
  • the main logic of iteration is here.
  • octokit supports both forward and backward page iteration by detecting the hasNextPage/endCursor and hasPreviousPage/startCursor key of the page info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request GraphQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants