GitHub API v4:如何遍历分页? (GraphQL)
问题描述:
我正在使用Github API v4来运行搜索查询.
I'm using Github API v4 to run search query.
从API文档中,我可以理解以下查询为我提供了pageInfo,但我不知道如何使用它来遍历.
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
}
}
}
}
响应是:
{
"data": {
"search": {
"pageInfo": {
"startCursor": "Y3Vyc29yOjE=",
"hasNextPage": true,
"endCursor": "Y3Vyc29yOjEwMA=="
},
...
}
答
根据 graphql文档是一个以上的分页模型.
According to graphql documentation there are more than one pagination model.
GitHub正在使用完整的连接模型
GitHub is using complete connection model
在此模型中,您可以在搜索查询后添加:"Y3Vyc29yOjEwMA ==" .
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
}
}
}
}