如何使用github graphql v4 API查询组织中的所有存储库?

Jin*_*Lee 7 github graphql

我想在github上查询我组织中的所有存储库,我尝试使用

query {

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

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

    }

  }
}
Run Code Online (Sandbox Code Playgroud)

但是它返回

{
  "data": {
    "organization": {
      "id": "MDEyOk*********************U4ODUw",
      "name": "my-org-name",
      "url": "https://github.com/my-org-name",
      "repositories": {
        "nodes": []
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

找不到任何存储库。我在Github Developer上进行了测试,https://developer.github.com/v4/explorer/

jcr*_*ada 9

您可以使用search端点实现(您需要进行身份验证)

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

带查询变量

{
  "queryString": "org:my_org"
}
Run Code Online (Sandbox Code Playgroud)

请注意,正如预期的那样,您没有获得组织的列表存储库,而是获得了您有权访问的组织列表的列表


oso*_*kit 5

GraphQL Explorer 是一个 OAuth 应用程序,需要获得访问组织数据的权限。

您可以直接为GraphQL API Explorer授予此访问权限,或者从“设置”->“应用程序”->“授权 OAuth 应用程序”导航至该访问权限

oauth 应用程序

请注意个人访问令牌(PAT) 没有此限制,因此使用您的令牌的应用程序不需要这样做。