productVariants query - why does product_id query filter only accept numeric IDs?

Hi,

Looking at the productVariants GraphQL query, it appears that the “query” argument allows to filter by “product_id” (see productVariants - GraphQL Admin).
However, I find it surprising that the “product_id” filter only accepts IDs in the REST/numeric format, e.g.:

product_id:8474977763649

What is the best way to obtain this “numeric” product ID? Should we fetch the product and use its “legacyResourceId” property, or should we parse its “id” property (removing the “gid://shopify/Product/” prefix and using just the numeric part of it)?

Thank you!

Hello Piotr!

Your assumption here is spot on:

Remove the prefix from the GID to obtain an integer ID for querying.

Thanks for your question.

1 Like