过滤多种类型的内容graphql

问题描述 投票:0回答:1

我使用GatsbyJS,这是我的第一次冒险与反应和graphql。我想混一个单页的内容同时包含“博客,帖子”类型的内容,以及“回购后”类型的内容,但我不知道如何将它添加到查询过滤它。

另外;我知道什么是frontmatter(RE:降价),但我不知道是什么templateKey,而“EQ”在此背景下。我不知道有足够的了解什么,我看就知道它叫什么,开始寻找解释。

export const pageQuery = graphql`
  query IndexQuery {
    allMarkdownRemark(
      sort: { order: DESC, fields: [frontmatter___date] },
      filter: { frontmatter: { templateKey: { eq: "blog-post" } }}
    ) {
      edges {
        node {
          excerpt(pruneLength: 400)
          id
          fields {
            slug
          }
          frontmatter {
            title
            templateKey
            date(formatString: "MMMM DD, YYYY")
          }
        }
      }
    }
  }
`
reactjs graphql gatsby
1个回答
3
投票

这里eq意味着equals和templateKey在你降价frontmatter只是另一个关键。你定的过滤器基本上是说:“如果templateKeyfrontmatter值等于博客员额”。

你可以改变从过滤器

filter: { frontmatter: { templateKey: { eq: "blog-post" } }}

filter: { frontmatter: { templateKey: { in: ["blog-post", "repo-post"] } }}

你应该看看docs on graphql。它也有一个叫做GraphiQL伟大的工具,以查询玩耍。

© www.soinside.com 2019 - 2024. All rights reserved.