Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I list Github's public repositories using GraphQL?

I am trying to list public repositories in Github using GraphQL as it allows me to choose exactly which information from an Object I want.

Using REST I could list public repositories simply by making requests to https://api.github.com/repositories. This is OK, but the response comes with a bunch of stuff I don't need. So, I was wondering if I could use GraphQL to do the same job.

The problem is, I couldn't find any high level repositories Object I could use to list public repositories using GraphQL. For me it seems I can only use GraphQL to list repositories from organizations or from users. For example, like doing so:

query{
    user(login: "someuser"){
        repositories(first: 50){
            nodes{
                name
            }
            pageInfo{
                hasNextPage
            }
        }
    }
}

So, how can I use (if at all) Github's GraphQL endpoint to list Github's public repositories?

I have also tried something on this line, using search, but I doubt Github has only 54260 repositories as the repositoryCount variable returned me.

query{
    search(query:"name:*", type:REPOSITORY, first:50){
        repositoryCount
        pageInfo{
            endCursor
            startCursor
        }
        edges{
            node{
                ... on Repository{
                    name
                }
            }
        }
    }
}
like image 734
FTM Avatar asked Jan 13 '18 22:01

FTM


People also ask

Is GitHub using GraphQL?

GitHub chose GraphQL because it offers significantly more flexibility for our integrators. The ability to define precisely the data you want—and only the data you want—is a powerful advantage over traditional REST API endpoints.

How to use GitHub API with GraphQL?

To communicate with GitHub's GraphQL API, fill in the header name with "Authorization" and the header value with "bearer [your personal access token]". Save this new header for your GraphiQL application. Finally, you are ready to make requests to GitHub's GraphQL API with your GraphiQL application.

What is GitHub GraphQL?

GraphQL is a query language and execution engine tied to any backend service.


1 Answers

You can use is:public in the search query :

{
  search(query: "is:public", type: REPOSITORY, first: 50) {
    repositoryCount
    pageInfo {
      endCursor
      startCursor
    }
    edges {
      node {
        ... on Repository {
          name
        }
      }
    }
  }
}

Try it in the explorer

like image 90
Bertrand Martel Avatar answered Sep 30 '22 23:09

Bertrand Martel