对另一个结果执行 GraphQL 查询 [英] Executing GraphQL queries on the result of another one

查看:28
本文介绍了对另一个结果执行 GraphQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取 Gatsby 中文件夹名称的列表,以及位于其中的文件的名称.

I'm trying to get a list of folders name in Gatsby, along with the name of the files located inside them.

这是我可以使用的 2 个查询:

Here are the 2 queries I can use :

query fetchDirectories {
  allDirectory(filter: {
    relativeDirectory: {
      regex: "/documentation/"
    }
  }) {
    edges {
      node {
        name
      }
    }
  }
}

query fetchFilesByDirectory($directory: String) {
  allFile(filter: {
    internal: {
      mediaType: {
        eq: "text/markdown"
      }
    }
    relativePath: {
      regex: $directory
    }
  }) {
    edges {
      node {
        name
      }
    }
  }
}

另外,查询工作正常,我可以获得很好的结果.

Separately, the queries are working, and I can get the good results.

在我的代码中,我想对第一个查询返回的每个目录执行第二个查询.

In my code, I'd like to execute that second query for each directories returned by the first query.

知道怎么做吗?

推荐答案

根据您的用例,如果您只是想获取 /documentation/ 中的所有 MD 文件,这可能是有用

Depending on your use case, if you're just trying to get all the MD files in /documentation/, this might be useful

{
  allFile(filter: {
    internal: {
      mediaType: {
        eq: "text/markdown"
      }
    }
    relativeDirectory: {
      regex: "/documentation/"
    }
  }) {
    edges {
      node {
        relativePath
        name
      }
    }
  }
}

这篇关于对另一个结果执行 GraphQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆