Products graphQL metafield querying can be tricky

Just an advisory that querying on metafield values can provide some very odd results if you trip up on the syntax.

Querying like this got me 1857 results: products(query: “status:ACTIVE,metafields.custom.disabled_on_herring:<1”, first: 200)

Querying like this only got me 431: products(query: “status:ACTIVE,metafields.custom.disabled_on_herring:0”, first: 200)

The actual result is 1563.

That metafield only has two possible values for active products: 0 or 1. Therefore these queries should be functionally equivalent. I was confused.

The separator needs to be AND/OR, not a comma - but (the tricky part) it won’t fail with a syntax error, it will just return weird results. I’d raised this issue and done tests to confirm before I noticed what I’d done.

An error or userError in the response would be useful here.

G

PS: not even the first time I’ve made this mistake: Possible bug: querying products tagged with 'trainers' returns products tagged with 'not-trainers' - #8 by dartacus

1 Like

Hey @dartacus, thanks for sharing this.

For anyone hitting queries that aren’t being parsed as expected, it’s worth including the Shopify-Search-Query-Debug: 1 request header. It enables the search debug extension on any query, which can surface how the query is being interpreted.

I’ve noted this additional context internally as well.

1 Like

Will use that next time, many thanks.

G