Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 2

GraphQL equivalent of /repos/:owner/:repo/git/trees/:tree_sha?recursive=1

Is there a way to recursively list all files of a repository?

 

https://developer.github.com/v3/git/trees/

1 Reply
Community Manager
Message 2 of 2

Re: GraphQL equivalent of /repos/:owner/:repo/git/trees/:tree_sha?recursive=1

Not exactly, no. While you can compose a query that recurses to a finite and specified depth, there is no support for unbounded recursion in GraphQL. So for example, you could write something like this:

 

{
  repository(owner: "atom", name: "atom") {
    defaultBranchRef {
      target {
        ... on Commit {
          tree {
            entries {
              name
              object {
                ... on Tree {
                  entries {
                    name
                  }
                }
              }
            }
          }          
        }
      }
    }
  }
}

To get the list of files of max depth 1. You could further write it out for max depth n, but you would have to do it manually (or generate it) to a known, finite depth.

 

I hope that helps!