对另一个结果执行GraphQL查询 [英] Executing GraphQL queries on the result of another one
本文介绍了对另一个结果执行GraphQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取Gatsby中的文件夹名称列表以及位于其中的文件的名称.
I'm trying to get a list of folders name in Gatsby, along with the name of the files located inside them.
这是我可以使用的两个查询:
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屋!
查看全文