【问题标题】:GitHub GraphQL API v4 vs REST API v3GitHub GraphQL API v4 与 REST API v3
【发布时间】:2018-03-10 01:14:51
【问题描述】:

是否可以像使用 REST API v3 一样使用 GitHub GraphQL API v4 列出所有 github 的组织?

按照有限的示例调用:

$ curl https://api.github.com/organizations?since=32358551
[
  {
    "login": "NxtReader",
    "id": 32358576,
    "url": "https://api.github.com/orgs/NxtReader",
    "repos_url": "https://api.github.com/orgs/NxtReader/repos",
    "events_url": "https://api.github.com/orgs/NxtReader/events",
    "hooks_url": "https://api.github.com/orgs/NxtReader/hooks",
    "issues_url": "https://api.github.com/orgs/NxtReader/issues",
    "members_url": "https://api.github.com/orgs/NxtReader/members{/member}",
    "public_members_url": "https://api.github.com/orgs/NxtReader/public_members{/member}",
    "avatar_url": "https://avatars3.githubusercontent.com/u/32358576?v=4",
    "description": null
  },
  {
    "login": "fokkmandag",
    "id": 32358602,
    "url": "https://api.github.com/orgs/fokkmandag",
    "repos_url": "https://api.github.com/orgs/fokkmandag/repos",
    "events_url": "https://api.github.com/orgs/fokkmandag/events",
    "hooks_url": "https://api.github.com/orgs/fokkmandag/hooks",
    "issues_url": "https://api.github.com/orgs/fokkmandag/issues",
    "members_url": "https://api.github.com/orgs/fokkmandag/members{/member}",
    "public_members_url": "https://api.github.com/orgs/fokkmandag/public_members{/member}",
    "avatar_url": "https://avatars2.githubusercontent.com/u/32358602?v=4",
    "description": null
  }
]

【问题讨论】:

    标签: api github graphql github-api github-graphql


    【解决方案1】:

    您可以使用带有type:org 的搜索查询,因为SearchResultItem 可以包含Organization 对象:

    {
      search(first: 100, type: USER, query: "type:org") {
        userCount
        pageInfo {
          hasNextPage
          endCursor
        }
        edges {
          node {
            ... on Organization {
              login
              name
              description
            }
          }
        }
      }
    }
    

    对于分页,如果hasNextPagetrue,则可以使用after 参数作为最后一个endCursor 值获取下一个请求,例如:

    search(after: "Y3Vyc29yOjEwMA==", first: 100, type: USER, query: "type:org")
    

    【讨论】:

      猜你喜欢
      • 2020-01-12
      • 2018-08-21
      • 2023-03-08
      • 2018-10-01
      • 2019-10-12
      • 2020-11-02
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      相关资源
      最近更新 更多