【问题标题】:GitHub GraphQL equivalent of the contents API与内容 API 等效的 GitHub GraphQL
【发布时间】:2017-10-23 13:52:09
【问题描述】:

GitHub 的 GraphQL API 是否与 contents API 等效?

我似乎想不出一个接受 repo 所有者、repo 名称和文件路径并返回文件内容的查询。我猜它与tree 对象有关?

https://developer.github.com/early-access/graphql/explorer/

【问题讨论】:

    标签: github github-api graphql


    【解决方案1】:

    经过一番挖掘,找到了:

    query {
      repository(name: "repoName", owner: "repoOwner") {
        object(expression: "branch:path/to/file") {
          ... on Blob {
            text
          }
        }
      }
    }
    

    object 字段上传递给expression 的参数实际上是一个适合rev-parse 的git 修订表达式,所以我想你可以用它来进行高级查询。

    文档:

    【讨论】:

    • base64 编码的二进制内容怎么样?我们在 v3 中有,但在 v4 中找不到方法。
    • “...”应该是什么?
    • @SW_user2953243 GraphQL 语法,不要替换点
    • @SW_user2953243 您正在查询GitObject,它可以是Blob(文件),也可以是CommitTagTree... on Blobinline fragment,如果返回的 GitObjectBlob,则允许您有条件地查询 text 字段。
    • @SamTolmay 我对 Tag GitObject 进行了同样的尝试,但得到了空响应。有什么想法吗?对于获取空对象的无效标签。对于有效标签,只有空的 json 对象。 { repository(owner: "gradle", name: "gradle") { url object(expression: "v5.3.0") { ... on Tag { oid id } } } }
    猜你喜欢
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 2018-04-09
    • 2018-04-11
    相关资源
    最近更新 更多