GitHub API v4 Graphql:获取当前授权的用户组织及其存储库

Hen*_*uno 5 github github-api graphql octokit-js

在具有repo用户授权范围的GitHub API v3 中,我可以使用GET /user/orgshttps://developer.github.com/v3/orgs/#list-organizations-for-the-authenticated-user,使用 Octokit REST JS,octokit.orgs.listForAuthenticatedUser()) 并且对于每个组织,获取我可以访问的存储库,GET /orgs/:org/repos( https://developer.github.com/v3/repos/#list-organization-repositories,与 Octokit octokit.repos.listForOrg({ org: orgs.data[i].login }))。

但是,使用相同的身份验证范围(用户和存储库),运行此 Graphql 查询

query getOrgsRepos {
  viewer {
    organizations(first: 10) {
      nodes {
        repositories(first: 10) {
          nodes {
            name
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

退货

{
  "data": {
    "viewer": {
      "organizations": {
        "nodes": []
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Graphql Explorer 结果(https://developer.github.com/v4/explorer/),但在我的 JS authed(用户repo范围)应用程序上运行返回相同的空结果

如何与 API v4具有相同的行为,而无需提供进一步的权限

Ste*_*man 0

我认为您的查询存在缺少组织的问题login

query getOrgsRepos {
  viewer {
    organizations(first: 10) {
      nodes {
        login
        repositories(first: 10) {
          nodes {
            name
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我只收到这些范围的回复。