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

Cannot fetch more than 100 branches, even when using pagination #468

Open
NimrodK-GD opened this issue May 9, 2023 · 0 comments
Open

Cannot fetch more than 100 branches, even when using pagination #468

NimrodK-GD opened this issue May 9, 2023 · 0 comments
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@NimrodK-GD
Copy link

NimrodK-GD commented May 9, 2023

Hi,
I'm trying to fetch all of the branches in a selected repository, as well as their last commit date. I use the commit date in order to programmatically sort the branches in a descending chronological order. The repository currently has more than 300 branches.

I've tried multiple solutions and queries, but I cannot fetch more than 100 branches, even when using multiple requests, and the hasNextPage flag is set to false once the 100th ref is reached.
When the first variable is set to a number lower than 100, the pagination seems to work, but still stops at 100 branches. For example, if first is set to 20, then 5 pages will be fetched with 100 branches in total.

I've also tried using https://github.com/octokit/plugin-paginate-graphql.js but I got the same results.
Here is the query I'm currently using:

query branches(
    $owner: String = "github_user",
    $repositoryName: String!,
    $prefix: String = "refs/heads/",
    $refQuery: String = "",
) {
    repository(name: $repositoryName, owner: $owner) {
        defaultBranchRef {
            name
        }
        refs(first: 100, query: $refQuery, refPrefix: $prefix, after: $endCursor) {
            edges {
                node {
                    name,
                    ref: target {
                        ... on Commit {
                            oid,
                            authors(first: 1) {
                                nodes {
                                    date
                                }
                            }
                        }
                    }
                }
                cursor
            }
            pageInfo {
                hasNextPage
                endCursor
            }
        }
    }
}

Thanks in advance!

@kfcampbell kfcampbell added Type: Bug Something isn't working as documented Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs Priority: Normal labels May 15, 2023
@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

3 participants