Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github GraphQL to recursively list all files in the directory

I want to use the GraphQL Github API to recursively list all files contained in the directory. Right now my query looks 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 adjust the query, such that it recursively list the contents of tree again?

like image 830
Sleik Avatar asked Oct 10 '17 14:10

Sleik


2 Answers

There is no way to recursively iterate in GraphQL. However, you can do so 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 a value of null and go from there.

like image 169
Scriptonomy Avatar answered Nov 16 '22 00:11

Scriptonomy


working example

More info: https://docs.sourcegraph.com/api/graphql/examples

But probably this will change in the near feature. For example latest github version is v4 https://developer.github.com/v4/explorer/

like image 2
FDisk Avatar answered Nov 15 '22 23:11

FDisk