How to filter product by variants metafields in graphql
Topic summary
Issue: A user is trying to filter products by variant metafields in Shopify’s GraphQL API.
Current Limitation:
- According to one response, the GraphQL API doesn’t natively support filtering products by variant metafields
- The suggested workaround is to retrieve all results first, then filter them in custom code
- A comprehensive list of supported variant query fields was provided (including barcode, SKU, inventory quantities, product status, options, etc.)
Potential Solution:
- Another user suggests it may be possible using a specific GraphQL query structure that targets variant metafields directly
- A code snippet was shared showing a query pattern:
productVariants(first: 5, query:"metafield...")
Status: The discussion remains open with conflicting information about whether variant metafield filtering is achievable through GraphQL queries.
1 Like
Unfortunately, it doesn’t look like it’s possible to filter products by variant metafield.
You’d have to do the filtering in your own code after getting the full set of results.
The full list of fields you can query variants on is here as part of the documentation:
available_quantitybarcodecollectioncommitted_quantitydelivery_profile_idexclude_compositegift_cardincoming_quantityinventory_quantitylocation_idmanagedmanaged_byon_hand_quantityoption1option2option3product_idproduct_statusproduct_typepublishable_statuspublished_statusreserved_quantityskutagtag_nottaxabletitleupdated_atvendor
Hi,
Looks like it might be possible to use this:
{ productVariants(first: 5, query:"(metafield:namespace.key:value) and (availableForSale:true)") { edges { node { id, product { id } } } } }