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

编程入门 行业动态 更新时间:2024-10-27 12:32:33
本文介绍了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 递归列出目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 02:04:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/674851.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:递归   文件   目录中   Github   GraphQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!