我正在尝试使用 GitHub v4 (GraphQL) API 从 GitHub 读取一些数据。我已经编写了一个 Java 客户端,该客户端运行良好,直到我开始用 GraphQL 片段替换一些查询。
我最初使用 GraphiQL 来测试我的查询,并且在其中添加片段非常简单。但是,在转换为 JSON 时,我还没有弄清楚正确的格式。我试过了:
{ "query": "{ ... body_of_query ... } fragment fragname on Blob { byteSize text }" }
{ "query": "{ ... body_of_query ... }, fragment fragname on Blob { byteSize text }" }
{ "query": "{ ... body_of_query ... }", "fragment": "{fragname on Blob { byteSize text } }" }
编辑:添加@Scriptonomy:
{
query {
search(first:3, type: REPOSITORY, query: \"language:HCL\") {
edges {
node {
... on Repository {
name
descriptionHTML
object(expression: \"master:\") {
... on Tree {
...recurseTree
}
}
}
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
fragment recurseTree on Tree {
entries {
name
type
}
}
I'm sure继续对此进行随机变化会很有趣,而且我早上在片段上搜索各种 GraphQL 文档和博客非常有趣,我什至可能实际上猜到了正确的答案,但括号不匹配(我只是使用硬编码 JSON 直到我知道格式——回想起来也许不是最明智的选择)。
我希望有人能知道正确的格式,并在我因 GraphQL-doc 过度暴露而崩溃之前让我走上正确的道路。