GitHub GraphQL 等价于内容 API

编程入门 行业动态 更新时间:2024-10-26 18:28:15
本文介绍了GitHub GraphQL 等价于内容 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GitHub 的 GraphQL API 是否与 contents API?

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

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

解决方案

经过一番挖掘,找到了:

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

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

文档:

GitHub API 上的存储库对象rev-parse

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/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:

Repository object on GitHub API rev-parse

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

更多推荐

[db:关键词]

本文发布于:2023-03-27 02:21:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/674160.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   GitHub   GraphQL   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!