0

在我的 gatsby 站点中看到查询 Prismic 数据源并按内容关系过滤的一些奇怪行为。我正在尝试创建一个页面,根据传递到此页面的类别过滤一些产品。阅读 Prismic 和 Gatsby 文档,我应该能够使用该where子句过滤数据,但是当我尝试构建时出现此错误

error    Unknown argument "where" on field "allPrismicModel" of type "Query"

以下是查询的相关部分

query getProducts($uid: String) {
    allPrismicModel(where: { system_category: $uid }) {
      edges {
        node {
          data {
            system_category {
              uid
            }
            ...other fields here...
          }
        }
      }
    }
  }

有人遇到过这种情况或知道如何解决吗?

4

2 回答 2

1

where在盖茨比中不存在。我强烈推荐使用 GraphiQL(在 localhost:8000/___graphql 下)来看看你能做什么。还有这个文档显示了所有可能性:https ://www.gatsbyjs.org/docs/graphql-reference/

它可能最终会出现(未经测试):

filter: { system_category: { eq: $uid } }
于 2019-10-30T09:30:03.213 回答
0

allPrismicModel(filter: { system_category : { eq: $uid } }) {  
edges {
        node {
          data {
            system_category {
              uid
            }
            ...other fields here...
          }
        }
      }
    }
  }

这是运行该查询的更常见方式

于 2020-01-23T23:43:46.857 回答