Hey Shopify devs,
We have a combined listing for tier pricing—data is stored as metafields on both products and variants. We fetch both types using Admin GraphQL queries, then merge and display in our app. Now we want to add search, filter, and sorting (e.g. by product name A→Z), and need this entirely on Shopify’s Admin API (no server-side custom code), scaling to large catalogs.
Here’s how we handle this:
-
Use
titleand other built-in product/variant attributes for search and filter right in the query. -
Use
sortKey: TITLEandreversefor A→Z/Z→A sorting. -
For filtering by metafield (tier pricing rules), make sure metafields are indexed so they’re searchable via
query. -
Pagination (
first,after,hasNextPage,endCursor) works great for handling thousands of items.
Has anyone successfully filtered by metafields on large data sets, or found advanced techniques for this using only the GraphQL Admin API? Tips or example queries appreciated!
Product query:
query ($cursor: String) {
products(first: 100, after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
id
title
handle
metafield(namespace: "product", key: "test") {
value
}
}
}
}
}
ProductVariant query:
query ($cursor: String) {
productVariants(first: 100, after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
id
title
product {
id
title
}
metafield(namespace: "variant", key: "test") {
value
}
}
}
}
}
`;
Would love to hear best practices from the community!