3
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 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.
1
2 Answers
Reset to default
4
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 sortKey
but not query
.
The Shopify help page gives more information on this.
1
-
But, What if I want to filter the products of the particular collection ? This only be done with
query
. Can you have solution for this ?– Kishan BhardaJul 2, 2020 at 6:42
0
You use the wrong API endpoint.
I assumed you use the storeFront API, please try this: /api/2019-10/graphql.json
What do you mean that "the products doesn't allow to be sorted by price"?
May 20, 2019 at 20:47