Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub GraphQL equivalent of the contents API

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/

like image 717
Jeremy Danyow Avatar asked May 23 '17 14:05

Jeremy Danyow


People also ask

How do I use GraphQL with GitHub API?

To communicate with GitHub's GraphQL API, fill in the header name with "Authorization" and the header value with "bearer [your personal access token]". Save this new header for your GraphiQL application. Finally, you are ready to make requests to GitHub's GraphQL API with your GraphiQL application.

What is GitHub GraphQL API?

To create integrations, retrieve data, and automate your workflows, use the GitHub GraphQL API. The GitHub GraphQL API offers more precise and flexible queries than the GitHub REST API. Overview.


1 Answers

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
like image 60
yachaka Avatar answered Oct 16 '22 15:10

yachaka