[Graphql Products] Query Products within Collections

Topic summary

Goal: Fetch products within Shopify collections via GraphQL, with filtering (by multiple collections and price range) and sorting.

Approach shared: Query the collection first, then its products connection (collectionByHandle → products). A code snippet demonstrates this pattern.

Key limitation: The products connection under a collection does not support a query argument, so server-side filtering by price (or other query-based filters) is not available there. As a workaround, either:

  • Fetch all products in the collection and filter client-side (e.g., by price), or
  • Fetch products by price range first, then filter client-side by collection (less efficient for large catalogs).

Scalability note: Both client-side strategies are not ideal for large catalogs; using Liquid (Shopify’s templating) is recommended for better server-side handling in Online Store contexts.

Outcome: The requester will implement client-side price filtering using Flutter with a GraphQL client.

Current status: Limitation remains unresolved at the API level. Another participant confirms losing the query parameter on the nested products connection and questions why it’s not allowed; no official workaround or reason provided.

Summarized with AI on February 4. AI used: gpt-5.

Hello!

I’m trying to get products within collections. Reading the docs I don’t know if possible via GraphQL

My idea is some sort of

products(first:10, query:‘collections_id or something to join with the collection’){
{ }
}

my approach is probably the wrong one but I hope you get the point.

Hi @Aoliver98

Think about it the other way around. What collection do I want to show products for? So first query the collection, then its products connection.

{
  collectionByHandle(handle: "casual-things") {
    products(first: 10) {
    	edges {
        node {
          id
          handle
        }
      }
    }
  }
}
1 Like

Hi, thanks for the quick reply. @KarlOffenberger

I will give you an idea of the application

I have a list of products, those products can be filtered by multiple collections and price range and can also be sorted alphabetically or by price.

Is there a possibility for this function “collectionByHandle” to search for products by price range?

Not that I am aware of. The products connection doesn’t have a query argument.

You’re basically left with fetching all products within that collection and then filtering them client side using JS. Alternatively, query all products within a price range as shown below, then filter client side by collection they’re in though that might be less efficient given the products > collection search space is much larger than if you’d go collection > products. Also note that any of these aren’t really suited for large catalogs.

This is where you’re better off using Liquid.

Thanks for the help.

I’m using Flutter with Graphql Client.

So I’ll to filter the price range in the client side and I’ll see how it works

Have a nice day

1 Like

yes working with filter collection but lost the query parameter on product connect I do not know why shopify not allowed the query parameter in second connection.