为什么我的 graphql 查询 return 都是产品?

Why is my graphql query return all product?

我正在 Shopify GraphiQL Explorer 上测试 graphql 查询以过滤 Storefront 上的产品 API。

我的查询是这样的:

query ProductType {
  collectionByHandle(handle: "pants") {
    handle
    products(first: 10, filters: {
      productType: "pants"
    }) {
      edges {
        node {
          handle
          productType
        }
      }
    }
  }
}

得到这样的结果:

{
  "data": {
    "collectionByHandle": {
      "handle": "pants",
      "products": {
        "edges": [
          {
            "node": {
              "handle": "my-test-product-pants",
              "productType": "pants"
            }
          },
          {
            "node": {
              "handle": "pleated-straight-pants-mens-fashion-elastic-waist-casual-pants-men-streetwear-loose-ice-silk-trousers-mens-wide-leg-pants-s-2xl",
              "productType": ""
            }
          },
          ...

基本上,结果包含该系列的所有产品。有人可以帮我吗?这实际上是我从 shopify website

获得的代码

在教程中我们可以看到filters是一个数组

{
  "product_filters": [
    {
      "productType": "shoes"
    },
    {
      "productVendor": "bestshop"
    },
    {
      "variantOption": {
        "name": "color",
        "value": "blue"
      }
    }
  ]
}

那么,试试这个吧


query ProductType {
  collectionByHandle(handle: "pants") {
    handle
    products(first:10, filters: [{ productType: "pants" ]}) {
            ...
    }
  }
}