Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
When filtering on metafields, I don't see a clear way of reducing the variants returned, that match the filter(metafield) applied to that variant. For example -
collection(handle: "all") {
handle
products(first: 10, filters: {variantMetafield:{namespace: "filter", key: "colour", value: "Black"}}") {
edges {
node {
id
variants(first: 10) {
id
}
}
}
}
}
In this case I would expect to get all the products AND variants that match the above criteria? Or is there a way I can determine which variants match the criteria? This is important in order to display the correct image in a collection view. The default liquid templates do this but I can't find a sample using the storefront API.
This is the available docs on filters, for reference.
https://shopify.dev/api/examples/filter-products