我希望能够使用他们的 GraphQL API 从 GitHub 检索特定存储库的最新版本。为此,我需要获取最新版本,其中 isDraft 和 isPrerelease 为 false。我已经设法获得了第一部分,但无法弄清楚如何进行查询的“where”部分。
这是我得到的基本查询(https://developer.github.com/v4/explorer/):
{
repository(owner: "paolosalvatori", name: "ServiceBusExplorer") {
releases(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) {
nodes {
name
tagName
resourcePath
isDraft
isPrerelease
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
返回:
{
"data": {
"repository": {
"releases": {
"nodes": [
{
"name": "3.0.4",
"tagName": "3.0.4",
"resourcePath": "/paolosalvatori/ServiceBusExplorer/releases/tag/3.0.4",
"isDraft": false,
"isPrerelease": false
}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到一种方法来做到这一点。部分原因是我是 GraphQL 的新手(第一次尝试进行查询)并且我不确定如何构建我的问题。
只能基于支持参数的类型(例如下面的存储库和版本)“查询”吗?似乎应该有一种方法可以在字段值上指定过滤器。
存储库:https : //developer.github.com/v4/object/repository/
发布:https : //developer.github.com/v4/object/releaseconnection/
节点:https …
我正在尝试使用个人访问令牌来访问存储库的内容。
如果存储库是公共的,我可以使用 v3 和 v4 api 来实现这一点。以下两个请求都返回内容:
v3:
curl https://api.github.com/repos/w3c/webappsec/contents/
Run Code Online (Sandbox Code Playgroud)
v4:
query {
repository(owner: "w3c", name: "webappsec") {
object(expression: "master:") {
... on Tree {
entries{
name
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我已经生成了一个个人访问令牌,用于在我的一个私人存储库中执行此操作,但它永远不会返回任何内容:
v3(带有授权令牌):
curl -H "Authorization: bearer myauthorizationtoken" https://api.github.com/repos/myusername/myrepo/contents/
Run Code Online (Sandbox Code Playgroud)
结果:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/contents/#get-contents"
}
Run Code Online (Sandbox Code Playgroud)
v4(带有授权令牌):
query {
repository(owner: "myusername", name: "myrepo") {
object(expression: "master:") {
... on Tree {
entries{
name
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
{
"data": {
"repository": {
"object": …Run Code Online (Sandbox Code Playgroud) Github APIv4 GraphQL 有一些很好的功能,但我找不到使用分页来搜索问题的方法,例如
https://api.github.com/search/issues?q=repo:user/somerepo+is:open&page=10&per_page=100
Run Code Online (Sandbox Code Playgroud)
有办法解决吗?谢谢!