GitHub GraphQL 等价于内容 API [英] GitHub GraphQL equivalent of the contents API

查看:20
本文介绍了GitHub GraphQL 等价于内容 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GitHub 的 GraphQL API 是否与 contents API?

我似乎无法提出接受 repo 所有者、repo 名称和文件路径并返回文件内容的查询.我猜它与 tree 对象有关?>

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

解决方案

经过一番挖掘,找到了:

查询{存储库(名称:repoName",所有者:repoOwner"){对象(表达式:分支:路径/到/文件"){...在 Blob {文本}}}}

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

文档:

Does GitHub's GraphQL API have an equivalent to the contents API?

I can't seem to come up with a query that accepts repo owner, repo name and file path and returns the contents of the file. I'm guessing it has something to do with the tree object?

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

解决方案

After some digging, found it:

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

The argument passed to expression on the object field is actually a git revision expression suitable for rev-parse, so I guess you can have fun with it to do advanced querying.

Documentation:

这篇关于GitHub GraphQL 等价于内容 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆