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?
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With