GitHub GraphQL equivalent of the contents API

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

Leave a Comment

tech