graphql response wrong

Solved
Highlighted
Tourist
16 0 0

I have the following graphql query that I am using in the Shopify GraphiQL App and the response I am getting is correct...

Screen Shot 2020-09-08 at 11.43.59 AM.png

However when I am actually making that post in code it's not returning the correct data, matter of fact it's returning the EXACT same product no matter which SKU I am filtering on

Screen Shot 2020-09-08 at 11.47.49 AM.pngScreen Shot 2020-09-08 at 11.47.55 AM.png

0 Likes
Highlighted
Tourist
16 0 0

I'm using JavaScript to make the graphql post.

 

 

const query = `{
  products(first: 1, query: "sku:${sku}") {
    edges {
      node {
        id
        handle
        onlineStoreUrl
        title
        images(first: 1) {
          edges {
            node {
              transformedSrc(maxWidth: 100, maxHeight: 100)
            }
          }
        }
      }
    }
  }
}`;

fetch("https://dummystore.myshopify.com/api/2020-07/graphql", {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/graphql",
    "X-Shopify-Storefront-Access-Token": [SHOPIFY_ACCESS_TOKEN],
  },
  body: query,
})
.then((response) => response.json())
.then((response) => {
  console.log(response);
})
.catch((error) => console.error(error));

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1040 140 165

Hey @CWSites 

Where is sku defined? Can you confirm it's the same value as used in GraphiQL App?

0 Likes
Highlighted
Tourist
16 0 0

I have a function that is looping through a number of products and passing in a SKU as an argument. I have verified in the network tab of my browser that the correct SKU is being passed for each of the requests. Also the product that is shown is not in the list of SKUs that I'm looping over. This is also the same SKU that is in my screenshot from the Shopify Graph QL App above.

Screen Shot 2020-09-09 at 8.31.45 AM.png

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1040 140 165

This is an accepted solution.

The Shopify GraphiQL App queries the Admin API, your JavaScript is querying the Storefront API.

The Storefront API doesn't have an sku filter, here are the supported filters: https://shopify.dev/docs/storefront-api/reference/queryroot#products-2020-07

0 Likes
Highlighted
Tourist
16 0 0

Thanks for the info so far. Two things... 

1. Is there anything I could write that CAN query using SKU using Storefront API?

2. Can I make a request that this gets added to the API?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1040 140 165

1. I don't think so. One work around would be to proxy the requests through your own app + Admin API, although rate limiting might get in the way.

2. I've noted your feedback internally.

1 Like