Hi all,
seems that the productVariants query with wildcards on SKU it’s bugged.
To reproduce the bug, just create one product with 2 or 3 variants and assign the following skus:
- TST-DEL-S
- TST-DEL-M
- TST-DEL-L
Now, if I want to search a single product variants with one sku:
Query:
query ($query: String!) {
data: productVariants(query: $query, first: 10) {
nodes {
id
sku
}
}
}
Variables:
{
"query" : "sku:TST-DEL-S"
}
Result:
{
"data": {
"data": {
"nodes": [
{
"id": "gid://shopify/ProductVariant/50235666792748",
"sku": "TST-DEL-S"
}
]
}
},
"extensions": {
// cost omitted
"search": [
{
"path": [
"data"
],
"query": "sku:TST-DEL-S",
"parsed": {
"field": "sku",
"match_all": "TST-DEL-S"
}
}
]
}
}
I’ve use the search debug header to show how Shopify interpreted my query.
So far so good, but if I try to use wild card (same query, but different variable) to retrive all the SKU that start with “TEST-DEL”…
Variables:
{
"query" : "sku:TST-DEL*"
}
Result:
{
"data": {
"data": {
"nodes": []
}
},
"extensions": {
// cost omitted
"search": [
{
"path": [
"data"
],
"query": "sku:TST-DEL*",
"parsed": {
"field": "sku",
"match_prefix": "TST-DEL"
}
}
]
}
}
As you can see I’ve got no data, even if the search debug has correctly interpreted my query: notice the “match_prefix” instead of “match_all”.
The only way I found to obtain all the variants is to omit the field using the following variable:
{
"query" : "TST-DEL*"
}
Result:
{
"data": {
"data": {
"nodes": [
{
"id": "gid://shopify/ProductVariant/50235666792748",
"sku": "TST-DEL-S"
},
{
"id": "gid://shopify/ProductVariant/50235666825516",
"sku": "TST-DEL-M"
},
{
"id": "gid://shopify/ProductVariant/50235666858284",
"sku": "TST-DEL-L"
}
]
}
},
"extensions": {
// cost omitted
"search": [
{
"path": [
"data"
],
"query": "TST-DEL*",
"parsed": {
"field": "default",
"match_prefix": "TST-DEL"
}
}
]
}
}
But without the field, I’ve no control on which field shopify will search my string.
Any toughts?