How to filter product collections by tags using GraphQL?

How to filter product collections by tags using GraphQL?

Michael_Coombes
Shopify Partner
1 0 0

Hi There,

 

Was wondering if we could grab some help, the problem is we're looking into how to filter a collection by product tags, we're currently using GraphQL to grab the products from the Storefront API and the issue we're running into is  if we use the collections query which we're currently using this allows us to use the filters field on the products connection e.g.


{
	collection(handle: "shop") {
		products(first: 25) {
			filters {
				label
				type
				values {
					label
					count
					input
				}
			}
			edges {
				node {
					handle
				}
			}
		}
	}
}


Will give us a list of filters and we can then use the input field back to build our query up to filter the products.

However the ProductFilter doesn't accept tags as an input as per here: https://shopify.dev/api/storefront/2022-10/input-objects/ProductFilter despite showing us the input field back.

Now we can use the products query and that allows us to use the query input where we can specify the tag to query however then we lose the filters which we need to show for example Jackets (12) 


So it seems we're somewhat between a rock and a hard place where there's a way to do each of the things we want but not both, it's especially odd as the filters give us the input but then we can't actually filter on the tags as far as I can see. 

Replies 4 (4)

Leysam
Shopify Partner
147 17 50

@Michael_Coombes I feel your pain. This should be available by default since most of the client will migrate from the old version of shopify that uses tag filtering.


UPDATE: filtering by tags is now supported with the release of Storefront API 2023-01 (its about damn time!)

 

Screenshot 2023-01-03 at 9.21.45 PM.png

Screenshot 2023-01-03 at 9.22.35 PM.png

Screenshot 2023-01-03 at 9.25.20 PM.png

Leysam | The Shopify Guy  

 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
revo_dicky28
Shopify Partner
2 0 0

@Leysam  Hi, about the filter tag, Why filter tag is not working? I already make the GraphQL like yours

Leysam
Shopify Partner
147 17 50

@revo_dicky28 make sure you are using 

Storefront API version 2023-01

Leysam | The Shopify Guy  

 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
revo_dicky28
Shopify Partner
2 0 0

@Leysam I already use that version, but I know whats wrong with the API, on my Shopify, there is no filter for tag, Thank you for replied