Github GraphQL for recursively listing all files in a directory

I want to use the GraphQL Github API to recursively list all the files contained in a directory. Right now my request is like this:

{
  search(first:1, type: REPOSITORY, query: "language:C") {
    edges {
      node {
        ... on Repository {
          name
          descriptionHTML
          stargazers {
            totalCount
          }
          forks {
            totalCount
          }
          object(expression: "master:") {
            ... on Tree {
              entries {
                name
                type
              }
            }
          }
        }
      }
    }
  }
}

However, this only gives me only the first level of directory contents, in particular, some of the resulting objects are again trees. Is there a way to tune the query so that it recursively lists the contents of the tree again?

+7
source share
2 answers

There is no recursive iteration possible in GraphQL. However, you can do this programmatically using a query variable:

query TestQuery($branch: GitObjectID) {
 search(first: 1, type: REPOSITORY, query: "language:C") {
    edges {
      node {
        ... on Repository {
          object(expression: "master:", oid: $branch) {
            ... on Tree {
              entries {
                oid
                name
                type
              }
            }
          }
        }
      }
    }
  }
}

Start with value nulland go from there.

+4
source
{
  search(first: 1, type: REPOSITORY, query: "language:C") {
    edges {
      node {
        ... on Repository {
          name
          descriptionHTML
          stargazers {
            totalCount
          }
          forks {
            totalCount
          }
          object(expression: "master:") {
            ... on Tree {
              entries {
                name
                object {
                  ... on Tree {
                    entries {
                      name
                      object {
                        ... on Tree {
                          entries {
                            name
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

0
source

Source: https://habr.com/ru/post/1687239/


All Articles