Executing GraphQL queries on the result of another one

廉价感情. 提交于 2019-12-06 10:26:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!