Query repo contents with GraphQL API


#1

Does the 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?

Here’s my stackoverflow question with bounty:
https://stackoverflow.com/questions/44137710/github-graphql-equivalent-of-the-contents-api


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

Get submodules in a repository
#3

Any idea how to do this for a gist? Doesn’t seem to have the object connection.


#4

Thanks for posting your solution @jdanyow :bowing_man:.

@7footmoustache, it looks like we don’t have a way of accessing the contents of Gists right now. I’ve added this as a feature request in our internal tracker.


#5

Thanks!


#6

Is there a way to always query the default branch of the repository without knowing the exact name beforehand?

If i want to search for a certain file through a list of repositories, there is no possible expression I could use without
knowing the default branch name :confused:

Something like

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

for example…


#7

Accessing content of a gist would be great.


#8

Is there a way to get binary content? text only returns textual content, not binary blobs.