GraphQL递归列出目录中的所有文件

GraphQL递归列出目录中的所有文件

本文介绍了Github GraphQL递归列出目录中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GraphQL Github API递归列出目录中包含的所有文件.现在,我的查询看起来像这样:

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?

推荐答案

在GraphQL中没有递归迭代的方法.但是,您可以使用查询变量以编程方式执行此操作:

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
              }
            }
          }
        }
      }
    }
  }
}

以值 null 开头,然后从那里开始.

Start with a value of null and go from there.

这篇关于Github GraphQL递归列出目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 07:23