GitHub GraphQL equivalent of the contents API

2019-01-31 22:04发布

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/

1条回答
ゆ 、 Hurt°
2楼-- · 2019-01-31 22:29

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:

查看更多
登录 后发表回答