Furkan Yavuz
Furkan Yavuz

Reputation: 2024

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 }}}}"
}

Upvotes: 10

Views: 2814

Answers (2)

Chamath Jeevan
Chamath Jeevan

Reputation: 5172

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

Upvotes: 1

Bertrand Martel
Bertrand Martel

Reputation: 45473

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

Upvotes: 6

Related Questions