How can I search through 2,000 variants in a product?

jam_chan
Shopify Partner
908 23 179

I'm building a variant picker. Users can input a keyword to search through all variants of a product. Previously, I could search for the product with a similar query (e.g. products(first: 50, query: "*black*").

 

My query:

{
            product(id: "gid://shopify/Product/1234") {
                id
                title
                handle
                featuredImage {
                    originalSrc
                }
                variants(first: 100, query: "*black*") {
                    edges {
                        node {
                            id
                            title
                        }
                    }
                }
                updatedAt
                }
 }

 

When I run the query, Shopify gives me the error like this:


result = {'errors': [{'message': "Field 'variants' doesn't accept argument 'query'", 'locations': [{'line': 9, 'column': 38}], 'path': ['query', 'product', 'variants', 'query'], 'extensions': {'code': 'argumentNotAccepted', 'name': 'variants', 'typeName': 'Field', 'argumentName': 'query'}}]}

 

If variants cannot accept this query, how can I support users to find the variants in a product?

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview
Replies 2 (2)

AsafGitai
Shopify Staff
47 8 11

Hi @jam_chan ,

Thanks for asking this question.

>Previously, I could search for the product with a similar query (e.g. products(first: 50, query: "*black*").
To be sure, what is the reason you can't do this now?

> When I run the query, Shopify gives me the error like this:
This is true, even from 2023-07 we did not support this capability
https://shopify.dev/docs/api/admin-graphql/2023-07/objects/Product#connection-variants

> If variants cannot accept this query, how can I support users to find the variants in a product?
We agree that this is an issue with 2K variants, we will look into this and come back with a solution

jam_chan
Shopify Partner
908 23 179

Yes, I can search for the product with a keyword. This is working well now. I assumed it worked for variants as well. Thanks for getting back to me. Hope Shopify can come up with something.

 

In other words, the current way only supports users to scroll through the 2,000 variants in order to select some of them?

BYOB - Build Your Own Bundles, SPO - SEO App to research keywords & edit social link preview