【发布时间】:2019-08-20 12:01:16
【问题描述】:
我正在尝试通过 GitHub 的 GraphQL API v4 查询对 GitHub 上指定存储库的所有提交。
我只想提取他们提交的日期,以便估计贡献给该存储库的总时间(类似于git-hours)
这是我的初始查询:(注意:您可以尝试在Explorer 中运行它)
{
repository(owner: "facebook", name: "react") {
object(expression: "master") {
... on Commit {
history {
nodes {
committedDate
}
}
}
}
}
}
不幸的是,由于 API 的 resource limitations,它只返回最新的 100 次提交:
节点限制
要通过架构验证,所有 GraphQL API v4 调用都必须符合以下标准:
- 客户端必须在任何连接上提供第一个或最后一个参数。
- first 和 last 的值必须在 1-100 之间。
- 单个调用请求的节点总数不能超过 500,000 个。
因此,由于我没有提供 first 或 last 参数,API 假定我正在查询 history(first: 100)。而且我不能在单个连接中查询超过 100 个节点。
但是,总节点限制要高得多(500,000),我应该能够以 100 个为一组查询提交,直到我拥有所有提交。
我能够使用此查询查询最新的 200 次提交:
{
repository(owner: "facebook", name: "react") {
object(expression: "master") {
... on Commit {
total: history {
totalCount
}
first100: history(first: 100) {
edges {
cursor
node {
committedDate
}
}
}
second100: history(after: "700f17be6752a13a8ead86458e343d2d637ee3ee 99") {
edges {
cursor
node {
committedDate
}
}
}
}
}
}
}
但是我必须手动输入我在第二个连接中传递的光标字符串:second100: history(after: "cursor-string") {}。
如何递归地运行此连接,直到查询到存储库中所有 committedDates 的提交?
【问题讨论】:
标签: github graphql github-api