Skip to content

Instantly share code, notes, and snippets.

@johndevs
Last active March 19, 2022 20:54
Show Gist options
  • Save johndevs/8bfd1c5338be0e753e56a3794fb0cc3a to your computer and use it in GitHub Desktop.
Save johndevs/8bfd1c5338be0e753e56a3794fb0cc3a to your computer and use it in GitHub Desktop.
Github GraphQL - Get all file contents in repository
# Provide $query as a variable.
# The query is the same as you would enter into the search field e.g. "org:johndevs in:name feedreader"
query GetFilesQuery($branch: GitObjectID, $query: String!) {
search(first: 1, type: REPOSITORY, query: $query) {
edges {
node {
... on Repository {
object(expression: "master:", oid: $branch) {
... on Tree {
entries {
name
object {
... on Blob {
text
}
}
}
}
}
}
}
}
}
}
@MichaelCurrin
Copy link

I can't find anything suitable like master: *.

But I did find a way to get an extra level down using nesting in my query.

    object(expression: "master:") {
      ... on Tree {
        entries {
          name
  
          object {
            ... on Tree {
              entries {
                name
              }
            }
       }

@fregante
Copy link

Don't use master: but HEAD:

Not every repo has master: as the default branch

@elprl
Copy link

elprl commented Mar 15, 2022

How would one grab the updated date or committedDate for each of these TreeEntries?

@MichaelCurrin
Copy link

I tried using Commit instead of Blob and that didn't work. Got all empty objects. {}

              object {
                  ... on Commit {
                    committedDate
                    authoredDate
                  }
                }

@elprl
Copy link

elprl commented Mar 17, 2022

I couldn't figure it out either. Put a stackoverflow question on it:
https://stackoverflow.com/questions/71499519/getting-commit-data-on-file-list-github-graphql-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment