Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Search for null variant values using graphql and search syntax

Search for null variant values using graphql and search syntax

Rusty-Dev
Tourist
8 0 5

I'm trying to search for variants missing a taxCode and can't seem to get the query to return the correct results. I'm using the exists query:

 

query {
  productVariants(first:250, query:"-taxCode:*") {
    edges {
      node {
        title
        id
        taxCode
      }
    }
  }
}

Returns:

 

"data": {
  "productVariants": {
    "edges": [
      {
        "node": {
          "title": "Brown \/ Medium",
          "id": "gid:\/\/shopify\/ProductVariant\/13343879364660",
          "taxCode": "PC040129"
        }
      },
      ...
] } }

So obviously not a variant missing a taxCode 🙂

 

Replies 3 (3)

sd_
Shopify Staff (Retired)
51 10 7

Hi there,

 

TaxCode is not a field that you can filter product variant search results on. If you are looking for product variants that are missing a taxCode, you will have to do so manually. 

 

 

To learn more visit the Shopify Help Center or the Community Blog.

Menaka
Visitor
2 0 0

There seems to be some kind of bug. I am not able to query for taxCode now. 

 

Request:


query {
productVariants(first: 100) {
edges {
node {
title
id
taxCode
selectedOptions { name value }
}
}
}
}

 

 

Response:

 

{
"errors": [
{
"message": "Field 'taxCode' doesn't exist on type 'ProductVariant'",
"locations": [
{
"line": 8,
"column": 17
}
],
"path": [
"query",
"productVariants",
"edges",
"node",
"taxCode"
],
"extensions": {
"code": "undefinedField",
"typeName": "ProductVariant",
"fieldName": "taxCode"
}
}
]
}

Jroyce1180
Pathfinder
86 4 22

Surely there must be a workaround to get a result of all Products or ProductVariants that have an empty taxCode. Why not just take the results of the following query into an array and then loop through to find all the products without a taxCode. Wouldn't that work? 

{
    products(first: 50) {
      pageInfo {
        hasNextPage
        hasPreviousPage
      }
      edges {
        node {
          id
          title
          variants (first: 1) {
            edges {
              node {
                taxCode
              }
            }
          } 
        }
      }
    }
  }