问题
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
}
}
}
}
and
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.
Any idea on how to do it ?
回答1:
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
}
}
}
}
来源:https://stackoverflow.com/questions/47313856/executing-graphql-queries-on-the-result-of-another-one