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

Viewed 1976

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

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

Related