isaacs / github

Just a place to track issues and feature requests that I have for github
2.21k stars 129 forks source link

Searching GitHub repositories through API v4 gives unsure results even with the same query #1619

Open wonderbeyond opened 5 years ago

wonderbeyond commented 5 years ago

I'm trying to fetch a list of GitHub repositories using GraphQL API v4, sorted by stars count.

GraphQL query body:

query searchRepos($qstr: String!, $first: Int!, $after: String) {
    search(
        query: $qstr,
        type: REPOSITORY,
        first: $first,
        after: $after
    ) {
        repositoryCount
        nodes {
            ... on Repository {
                name
                stargazers {
                    totalCount
                }
            }
        }
    }
}

GraphQL query variables:

{
    "qstr": "is:public sort:stars-desc",
    "first": 5,
    "after": null
}

However, the first 5 items may not be the real most-starred repositories. If I do the same request repeatedly, the first item in the results seems random.

I've also written a Python script to reveal this issue: https://gist.github.com/wonderbeyond/4c294b3d865dd10767652acc22697ca3 (Also see its first comment)

So what's the problem behind, and how could I get the most starred repositories out of all?

wonderbeyond commented 5 years ago

Also see GitHub official search page. How could it be that the most popular Python project has only 1k stars?

github-list-python-repos-most-starred

And I know Django has more than 42k stars:

image

phc5 commented 4 years ago

I'm seeing this issue as well. There was some discussion here but it doesn't look like they are going to fix it 🤷🏼‍♂️. I had to resort to using the REST API since that at least returns the data I want consistently: https://api.github.com/search/repositories?sort=stars&order=desc&q=language:javascript

r13i commented 4 years ago

Found an interesting approach at this link. It gives the accurate ranking :clap: :) Kudos to @katopz...