If you are looking for any metafields at the variant level then you need to iterate through products, and then drill into the variants to get to them. Like this stripped-down example below. I just pull the first 5 products, iterate through each product’s first 5 variants, and finally iterate through each variant’s first 5 metafields. Does this work for you?
{
products(first: 5) {
edges {
node {
id
title
variants(first: 5) {
edges {
node {
id
title
metafields(first: 5) {
edges {
node {
description
value
valueType
}
}
}
}
}
}
}
}
}
}
I haven’t defined any product variant metafields, so I didn’t see anything coming back in the response. If I get a chance today I’ll add some metafield values and see what comes back…
Just ran a quick test in the GraphiQL app. Added a metafield value to a product variant and then queried against it. It seemed to work fine. Specifics below!
@Gregarican
Thank you so much for your response!
If I loop all products variants to get metafields that not good about performance and limit “requestedQueryCost”. Right?
If you need to retrieve a large amount of records using GraphQL, it’s usually best to try bulk operations → https://shopify.dev/tutorials/perform-bulk-operations-with-admin-api. I did a test of this, and pulled over 49K products using this mechanism. And the results were available in 11 minutes. Using the REST API it would’ve taken awhile to iterate through each paginated query response.
@Gregarican Thanks for your answer. I have one question about product variants metafields in shopify theme liquid, i get the all meta filed but i want show only the active variants meta field.