Impossible to search with a " symbol in SKU using GraphQL Admin API

Hi community,

Shopify allows " symbols in SKU:

But when I try to search for that SKU using GraphQL Admin API, it looks like that it does not allow " symbol in search condition:

When it works without " symbol:

Is there an elegant way to avoid this problem in general and using Remix template?

Very much appreciate any help.

You don’t need to wrap the string after the sku in double quotes so this query should work:

query myQuery {
  productVariants(first: 1, query: "sku:AMS\"FG1WHCM") {
    edges {
      node {
        id
        title
      }
    }
  }
}

And for what it’s worth you can also use unicode where " translates to \u0022 resulting in:

query myQuery {
  productVariants(first: 1, query: "sku:AMS\u0022FG1WHCM") {
    edges {
      node {
        id
        title
      }
    }
  }
}

You could replace any " in the original string with " or \u0022 explicitly, or find a more fully fledged solution in whatever programming language or tool you’re using to make this request!

And finally if you really prefer to have quotes around the query you can just use single quotes to avoid the escaping nightmare:

query myQuery {
  productVariants(first: 1, query: "sku:'AMS\"FG1WHCM'") {
    edges {
      node {
        id
        title
      }
    }
  }
}

All three of the above gave me the same results when testing on my shop!

This looks great. Thank you!

I have to surround a SKU with " because a SKU may have a space besides " symbol:

So looks like the third option works for me.

But there is an issue with the third option - it does not allow ’ symbol :sweat_smile:

Because I am construction a search condition with provided SKUs, I do not know exactly what is inside:

const queryCondition = batch
        .map(
          (id: any) =>
            `${filterCheckedValue === "sku" ? "sku" : "barcode"}:\\"${id}\\"`
        )
        .join(" OR ");

So I am not sure whether there is a universal solution for any allowed for SKUs symbols.