GitHub API v4:我如何遍历分页? (GraphQL)

时间:2018-01-05 15:38:02

标签: 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=="
            },
    ...
}

1 个答案:

答案 0 :(得分:3)

根据graphql documentation,有一个以上的分页模型。

GitHub正在使用完整连接模型

在此模型中,您可以在搜索查询后添加:“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
      }
    }
  }
}