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

Implement hub api --paginate #2169

Merged
merged 3 commits into from
Jun 15, 2019
Merged

Implement hub api --paginate #2169

merged 3 commits into from
Jun 15, 2019

Conversation

mislav
Copy link
Owner

@mislav mislav commented Jun 15, 2019

REST resources are paginated by following the <next> link in the "Link" response header.

A GraphQL query has to accept the optional endCursor string variable and output pageInfo:

pageInfo {
  hasNextPage
  endCursor
}

Full GraphQL example: find all repositories owned by USER:

hub api --paginate graphql -f owner="USER" -f query='
  query($owner: String!, $per_page: Int = 100, $endCursor: String) {
    repositoryOwner(login: $owner) {
      repositories(first: $per_page, after: $endCursor, ownerAffiliations: OWNER) {
        nodes {
          nameWithOwner
        }
        pageInfo {
          hasNextPage
          endCursor
        }
      }
    }
  }
'

https://developer.github.com/v3/#pagination
https://developer.github.com/v4/guides/resource-limitations/#node-limit

Repeated calls to `client.simpleApi()` will memoize its result and avoid
making multiple instances of `http.Client` and the associated Transport.
The GraphQL query has to accept the optional `endCursor` string variable
and output `pageInfo`:

    pageInfo {
      hasNextPage
      endCursor
    }
@mislav mislav merged commit 01429de into master Jun 15, 2019
@mislav mislav deleted the api-pagination branch June 15, 2019 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant