Ad

GraphQL Products Query Access Denied

- 1 answer

I'm a little stuck with one GraphQL query.

{
  collectionByHandle(handle:"price") {
    products(first: 16, sortKey:PRICE, query:"title:Bracelet"){
      edges {
        cursor
        node {
          title
        }
      }
    }
  }
}

The error comes from the query parameter which is not supported on Custom collection, but it is on a Smart one.

query: String

This field is only used when the collection is smart. If the collection is custom it returns an error. Supported filter parameters:

  • title
  • product_type
  • vendor
  • gift_card
  • created_at
  • updated_at

So when I use a Custom

So when I use a Custom collection I get the expected error result:

{
  "data": {
    "collectionByHandle": null
  },
  "errors": [
    {
      "message": "Cannot filter by query if the collection is a custom collection.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "collectionByHandle",
        "products"
      ]
    }
  ]
}

But when I use a Smart collection I get Access Denied

{
  "data": {
    "collectionByHandle": null
  },
  "errors": [
    {
      "message": "access denied",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "collectionByHandle",
        "products"
      ]
    }
  ]
}

The error message from the front-end is this:

"Field 'products' doesn't accept argument 'query'"

So I don't see any reason why this request is not working properly if it is specified that the query parameter works only for Smart Collections and the collection is indeed setup as a smart one.

As to why I use collectionByHandle with products I need to sort the products by price and the products doesn't allow to be sorted by price if I don't include them in the collection.

Here is a video demo of the issue as well: https://streamable.com/sevtf

Any insight of the problem will be much appreciated.

Ad

Answer

If you're querying for the products connection under queryroot, you can use the query parameter:

{
    products(first: 16, sortKey:PRICE, query:"title:Bracelet"){
        edges {
            cursor
            node {
                title
            }
        }
    }
}

However, if you're in a Collection (as is the case in your code above), the products connection only has 6 supported parameters: after, before, first, last, reverse, and sortKeybut notquery.

The Shopify help page gives more information on this.

Ad
source: stackoverflow.com
Ad