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

徘徊边缘 提交于 2020-11-26 14:32:39

问题


I'm using Github API v4 to run search query.

From the API documentation I can understand that the following query gives me pageInfo but I don't know how to use it to traverse.

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
      }
    }
  }
}

And response is:

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

回答1:


According to graphql documentation there are more than one pagination model.

GitHub is using complete connection model

In this model you can traverse with adding after:"Y3Vyc29yOjEwMA==" to your search query.

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
      }
    }
  }
}


来源:https://stackoverflow.com/questions/48116781/github-api-v4-how-can-i-traverse-with-pagination-graphql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!