【发布时间】:2018-07-08 01:41:51
【问题描述】:
我想使用“endCursor”通过分页向 Github GraphQL API 发出多个 POST 请求。
var unirest = require ('unirest');
var async = require('async');
const endpoint="https://api.github.com/graphql"
const token = "sometoken";
var search_query={
"query": 'query($name: String!, $after: String){\
search(query:$name, type: USER, first: 2, after: $after){\
userCount\
pageInfo{endCursor}\
nodes{\
...on User{\
id \
bio \
html_url:url \
}\
}\
}\
}',
"variable": {"name":"somename", "after":null}
};
unirest.post(endpoint)
.headers({"Content-Type": "text/html" , "Authorization": "bearer "+token, 'user-agent': 'node.js'})
.send(JSON.stringify(search_query)) //creating requests
.end(function(response, request){
console.log(response.body.data.search.pageInfo.endCursor);
});
我想多次迭代这个 POST 请求。每次使用 $after 作为最后一个请求的 endCursor。我该怎么做?谢谢!
【问题讨论】:
标签: node.js post pagination graphql