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
}
}
}
}
}
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.
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.
GraphQL is a query language and execution engine tied to any backend service.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With