Jini Gary Lee
Jini Gary Lee

Reputation: 181

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

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/

Upvotes: 15

Views: 11348

Answers (4)

Maciej Banaś
Maciej Banaś

Reputation: 11

Try this (type your org instead of your_org):

    {
  repositoryOwner(login: "your_org") {
    ... on Organization {
      repositories(first: 100) {
        totalCount
        pageInfo {
          endCursor
          hasNextPage
        }
        nodes {
          id
          name
          stars: stargazerCount
          forks: forkCount
          created_at: createdAt          
          organization: owner {
            login
          }
          repo_url: url
        }
      }
    }
  }
}

Upvotes: 0

Max
Max

Reputation: 437

Here my example.

You have to be Authenticated to do this request.

url: https://api.github.com/graphql

header: Authorization bearer token

method: POST

query {
    viewer {
        avatarUrl
        login
        resourcePath
        url
        bio
        company
        createdAt
        location
        followers(first: 100) {
            nodes {
                name
                url
            }
        }
        repositories(first: 100) {
            nodes {
                name
                description
                url
                createdAt
                collaborators(first: 5) {
                    nodes {
                        name  
                    }
                    totalCount
                }
            }
            totalCount
        }
    }
}

Upvotes: 1

Juan Rada
Juan Rada

Reputation: 3786

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

Upvotes: 9

osowskit
osowskit

Reputation: 6344

The GraphQL Explorer is an OAuth Application that needs to be given permission to access your organization data.

You can grant this access directly for the GraphQL API Explorer or navigate to it from your Settings -> Applications -> Authorized OAuth Apps

oauth apps

Note that a personal access token (PAT) does not have this restriction, so this isn't required for an application using your token.

Upvotes: 5

Related Questions