如何从 Github Graphql API 获取 Readme.MD?
How to get Readme.MD from Github Graphql API?
v3 有一个特定的 API 用于检索 readme.md 文件。但是在新的 V4 GraphQL 中,Repository Object 中没有这个字段。
有谁知道如何检索自述文件?
谢谢!
尚无获取 README.md 文件的特定实体,但您可以像通常检索任何其他文件一样检索它:
{
repository(owner: "gitpoint", name: "git-point") {
object(expression: "master:README.md") {
... on Blob {
text
}
}
}
}
看起来因为 GitObject 实现了 Blob,您可以使用“... on”语法访问它的属性,其中将包含对象的内容。
为了访问相关对象,以 "branch:filename.ext" 格式传入分支和文件名以及扩展名,并从结果中检索 Blob,并从中检索文本。
可以同时检索多个对象,允许您检查备用大小写,例如小写 "readme.md" 名称。只需为对象提供别名。示例如下。
{
repository(owner: "owner", name: "name") {
upCase: object(expression: "master:README.md") {
... on Blob {
text
}
}
object(expression: "master:readme.md") {
... on Blob {
text
}
}
otherFile: object(expression: "master:index.js") {
... on Blob {
text
}
}
}
这可能有助于解释“... on”语法。
https://graphql.github.io/graphql-spec/June2018/#sec-Inline-Fragments
v3 有一个特定的 API 用于检索 readme.md 文件。但是在新的 V4 GraphQL 中,Repository Object 中没有这个字段。
有谁知道如何检索自述文件?
谢谢!
尚无获取 README.md 文件的特定实体,但您可以像通常检索任何其他文件一样检索它:
{
repository(owner: "gitpoint", name: "git-point") {
object(expression: "master:README.md") {
... on Blob {
text
}
}
}
}
看起来因为 GitObject 实现了 Blob,您可以使用“... on”语法访问它的属性,其中将包含对象的内容。
为了访问相关对象,以 "branch:filename.ext" 格式传入分支和文件名以及扩展名,并从结果中检索 Blob,并从中检索文本。
可以同时检索多个对象,允许您检查备用大小写,例如小写 "readme.md" 名称。只需为对象提供别名。示例如下。
{
repository(owner: "owner", name: "name") {
upCase: object(expression: "master:README.md") {
... on Blob {
text
}
}
object(expression: "master:readme.md") {
... on Blob {
text
}
}
otherFile: object(expression: "master:index.js") {
... on Blob {
text
}
}
}
这可能有助于解释“... on”语法。 https://graphql.github.io/graphql-spec/June2018/#sec-Inline-Fragments