rest - GitHub API v4 : How can I traverse with pagination?(GraphQL)

标签 rest github graphql github-api github-graphql

我正在使用 Github API v4 来运行搜索查询。

从API文档中我可以了解到以下查询为我提供了pageInfo,但我不知道如何使用它来遍历。

query {
  search(first: 100, type:USER, query:"location:usa repos:>0 language:java") {
    pageInfo {
      startCursor
      hasNextPage
      endCursor
    }
    userCount
    nodes {
        ... on User {
        bio
        company
        email
        id
        isBountyHunter
        isCampusExpert
        isDeveloperProgramMember
        isEmployee
        isHireable
        isSiteAdmin
        isViewer
        location
        login
        name
        url
        websiteUrl
      }
    }
  }
}

响应是:

{
    "data": {
        "search": {
            "pageInfo": {
                "startCursor": "Y3Vyc29yOjE=",
                "hasNextPage": true,
                "endCursor": "Y3Vyc29yOjEwMA=="
            },
    ...
}

最佳答案

根据graphql documentation分页模型不止一种。

GitHub 使用完整连接模型

在此模型中,您可以通过在搜索查询中添加 after:"Y3Vyc29yOjEwMA==" 来进行遍历。

query {
  search(first: 100, after:"Y3Vyc29yOjEwMA==", type:USER, query:"location:usa repos:>0 language:java") {
    pageInfo {
      startCursor
      hasNextPage
      endCursor
    }
    userCount
    nodes {
        ... on User {
        bio
        company
        email
        id
        isBountyHunter
        isCampusExpert
        isDeveloperProgramMember
        isEmployee
        isHireable
        isSiteAdmin
        isViewer
        location
        login
        name
        url
        websiteUrl
      }
    }
  }
}

关于rest - GitHub API v4 : How can I traverse with pagination?(GraphQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48116781/

相关文章:

github - 我可以从私有(private) github 存储库公开发布吗?

asp.net-mvc - 带有 ASP.NET MVC 的 RESTful Web 服务

python - Django 的 Querydict 异常行为 : bunches POST dictionary into a single key

java - POST : Accessing the HTTPRequest to find the logged on user 周围的 Spring 方面

python-3.x - 如何使用 gitignore 隐藏机器人 Telegram token ?

github - 如何从 GitHub 拉取请求触发 Jenkins 2.0 Pipeline 作业

javascript - 使用 fetch 时请求正文为空

graphql - 使用 GraphQL 检索包含具有不同架构的对象数组的对象

javascript - 使用 graphql-ruby 生成一个 schema.json

javascript - Dynamics crm 2016 - Web API 查询 - 动态值