Skip to content

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

@NimrodK-GD

Description

@NimrodK-GD

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsIssues that are ready to be worked on by anyoneType: BugSomething isn't working as documentedType: SupportAny questions, information, or general needs around the SDK or GitHub APIshacktoberfestIssues for participation in Hacktoberfest

    Type

    No type

    Projects

    Status

    🔥 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions