arnaudambro
arnaudambro

Reputation: 2653

Shopify StoreFront API GraphQL query returns nothing

I am trying for a client to build his Shopify store with Gatsby. I use for that gatsby-source-shopify2 plugin, and I always had error messages like that :

{
  "errors": [
    {
      "message": "Cannot query field \"allShopifyProduct\" on type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

So I investigated a bit to know what was happening, and I went on Shopify help center, followed this quick tuto and reproduced it with my client's store and with my own freshly created free test-store. Here are the step I followed :

  1. Create a new store, called 'my-store'
  2. Create a new product
  3. Create a new private app
  4. Check the box Allow this app to access your storefront data using the Storefront API
  5. Copy the API key
  6. Double-check that the private app is checked in the Product Availability, just to be sure
  7. Open GraphiQL, and set the GraphQL Endpoint to be https://my-store.myshopify.com/api/graphql
  8. Set the only HTTP Header to be: X-Shopify-Storefront-Access-Token: <API key>

Then I typed in the query field :

{
  shop {
    name
  }
}

And surprisingly, no error happened, but the expected output didn't come. It should have been :

{
  "data": {
    "shop": {
      "name": "my-store",
    }
  }
}

I tried in gatsby too, and the same errors came again, obviously.

What is wrong with me ?

Upvotes: 1

Views: 1373

Answers (1)

arnaudambro
arnaudambro

Reputation: 2653

OK, my mistake, I went to fast : in the private app you have many keys : <API key>, <shared secret> and <API Storefront access token>. I used the <API key> instead of the <API Storefront access token>. Now everything is OK...

Upvotes: 1

Related Questions