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.

GraphQL Call Returns Error if Query Parameter Contains A Space - Potential Bug?

GraphQL Call Returns Error if Query Parameter Contains A Space - Potential Bug?

cavallo_dev
Visitor
2 0 0

I'm trying to run this GraphQL query:
{
     inventoryItems(first: 1, query:"sku:128 SDRAM") {
           edges {
                  node {
                        id
                  }
           }
     }
}
But I get a response with the error message "Query not supported". I think the the syntax is correct, because if I query products instead of inventoryItems, using the same "sku:128 SDRAM" parameter, it returns the expected item. The inventoryItems query works if I pass in an SKU that does not contain a space. It seems that if the SKU I pass in contains a space, I get the "query not supported" message, but only when querying the inventoryItems object. I'm also able to consistently recreate this in the graphQL explorer at https://shopify.dev/apps/tools/graphiql-admin-api. Is this possibly a bug, or am I doing something wrong?

Replies 3 (3)

awwdam
Shopify Staff
249 42 38

Hey @cavallo_dev 

Would you be able to share an x-request-id header value returned with the error, as well as one from a similiar query that was successful? With that info, I would have happy to take a closer look and share back my findings. 

- Cheers

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

cavallo_dev
Visitor
2 0 0

@awwdam , no problem, 
X-Request-ID returned with the error: 04b4abef-1580-4e6e-bbe6-27ea69309bd6
Query that produced the error:

X-Request-ID returned from a successful request (same query, but querying products instead of inventoryItems): c099b2d8-1ee1-4347-89d0-2cbdaf0938f9

Thank You, and let me know if you need anything else.

 

awwdam
Shopify Staff
249 42 38

Hey @cavallo_dev,

Thanks for the examples. After locating request logs to take a closer look and doing some testing with the API, there were a few insights found that are worth passing back. 

The most immediate method to resolve the error, 'query not supported', is using backslash escaping. The example parameter you share as a query on the inventoryItem request would look like this when escaped: "sku:\"128 SDRAM\"" -  there is more detailed info about search syntax in this documentation,

Another approach to explore would be a query on other objects such as productVariants, which will return the inventoryItem item field if requested as well as the data you are looking for. An example request would look something like this:

 

{
  productVariants(first:1, query:["parameter:VALUE"]) {
    edges {
      node {
        id
        inventoryItem {
          sku
          id
        }
      }
    }
  }

 

Lastly, running into differences in functionality between various APIs can happen from time to time. While these inconsistencies can contribute to confusion or even seem like unexpected behaviour, at this time everything is working as intended. I've made sure to log this as feedback on your behalf to pass on to our developers - though I can't provide any guarentees that all feedback will be actioned on.

I hope this helps provide some clarity and direction moving forward - Cheers!

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog