Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github GraphQL API: How can I gather specific user's repositories?

I'm trying to get repositories of user with login name "somelogin".

It returns all repositories but I'm trying to get repositories owned by him only. Because new API uses GraphQL I couldn't did it.

Currently I'm using:

{
   "query": "query { user(login:\"furknyavuz\") {repositories(first: 50) { nodes { name url }}}}"
}
like image 641
Furkan Yavuz Avatar asked Nov 10 '17 21:11

Furkan Yavuz


People also ask

How do I use GraphQL on GitHub?

You can use the GitHub GraphQL API to create precise and flexible queries for the data you need to integrate with GitHub. Learn about the GitHub GraphQL API, previews for upcoming changes, breaking changes, and limitations. You can also use the GraphQL Explorer to interact with the API on real GitHub data.

What is the difference between GitHub GraphQL API and REST API?

To create integrations, retrieve data, and automate your workflows, use the GitHub GraphQL API. The GitHub GraphQL API offers more precise and flexible queries than the GitHub REST API.

How to add a comment to an issue in GitHub GraphQL?

The GitHub GraphQL API supports several mutation operations to change data on the server. We will use the addComment mutation to add a comment to the issue. In the GitHub API, elements such as issues, pull requests, and users are nodes.

What is a GitHub repository?

Basically a repository is the place for application source code that can be shared with others. I encourage you to put a few of your projects into GitHub repositories, so you can access them all later with what you've learned about their GraphQL API.


2 Answers

You can use isFork: false to exclude fork. In the explorer :

{
  user(login: "furknyavuz") {
    repositories(first: 50, isFork: false) {
      nodes {
        name
        url
      }
    }
  }
}

With curl :

curl -H "Authorization: bearer token" -d '
 {
   "query": "query { user(login: \"furknyavuz\") { repositories(first: 50, isFork: false) { nodes { name url } } } }"
 }
' https://api.github.com/graphql
like image 110
Bertrand Martel Avatar answered Oct 16 '22 20:10

Bertrand Martel


It's super easy to build graph QL using the Github GraphQL explorer. Please refer to the attached screenshot. https://docs.github.com/en/graphql/overview/explorer

{ user(login: "leerob") { name email company bio followers { totalCount } following { totalCount } repositories(first: 50, isFork: false) { nodes { name url stargazerCount primaryLanguage { id name } } } } }

enter image description here

like image 1
Chamath Jeevan Avatar answered Oct 16 '22 21:10

Chamath Jeevan