Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use github graphql v4 api to query all repositories in my organization?

Tags:

github

graphql

I wanna query all repositories in my organization on github private, i try to use

query {

  organization(login:"my-org-name") {
    id
    name
    url

    repositories(first:100) {
        nodes {
        id
        name
      }

    }

  }
}

However it returns

{
  "data": {
    "organization": {
      "id": "MDEyOk*********************U4ODUw",
      "name": "my-org-name",
      "url": "https://github.com/my-org-name",
      "repositories": {
        "nodes": []
      }
    }
  }
}

can't find any repositories. I test it on Github Developer, https://developer.github.com/v4/explorer/

like image 668
Jini Gary Lee Avatar asked Oct 15 '17 09:10

Jini Gary Lee


1 Answers

you can achieve using search end point (you need to be authenticated)

query myOrgRepos($queryString: String!) {
  search(query: $queryString, type: REPOSITORY, first: 10) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          name
        }
      }
    }
  }
}

with query variables

{
  "queryString": "org:my_org"
}

Note that as expected you do not get the list repositories of your organization, you get the list of your organization list that you have access

like image 65
Juan Rada Avatar answered Oct 10 '22 03:10

Juan Rada