Building an E-commerce site with Shopify
In this tutorial, you will set up a new Gatsby website that fetches product data from Shopify. The site displays a list of all products on a product listing page, and a page for every product in the store.
If you’re already comfortable with Gatsby and Shopify, you might want to check out our Shopify Starter Demo, a proof of concept showcasing 10,000 products and 30,000 SKUs (variants). You can clone the starter, host it on Gatsby and connect it to your own Shopify data to develop your own proof of concept in as little as an hour.
- Create a new Shopify account and store if you don’t have one.
- Create a private app in your store by navigating to
Manage private apps.
- Create a new private app, with any “Private app name” and add the following under the
Active Permissions for this Appsection:
Product listingsif you want to use Shopify’s Product Collections in your Gatsby site
Ordersif you want to use order information in your Gatsby site
Locationsif you want to use location information in your Gatsby site
- Enable the Shopify Storefront API by checking the box that says “Allow this app to access your storefront data using Storefront API”. Make sure to also grant access to
Read product tags,
Read and modify checkouts, and
Read customer tagsby checking their corresponding boxes.
- Copy the password, you’ll need it to configure your plugin below.
If you do not already have one ready, create a Gatsby site.
- Enable and configure the plugin in your
gatsby-config.jsfile, replacing [app-password] with the password you copied above and [yourstore.myshopify.com] with the canonical address of your store.
Note: You will likely not want to put your
storeUrl directly in your
gatsby-config.js file but rather, use an environment variable. Check out the Gatsby Shopify starter for an example of how to do that.
gatsby developand make sure the site compiles successfully.
Open the Gatsby GraphiQL interface by visiting
http://localhost:8000/___graphql. With at least one example product added into Shopify you should see several new types of nodes in the Explorer tab, like
allShopifyProduct. To query all products in your store sorted by title, try running the query:
To add a simple page listing all products, add a new file at
You can programmatically create pages in Gatsby for every product in your Shopify store.
Create a template for your product pages by adding a new file,
gatsby-node.js file and add the following code. This queries all Shopify products with GraphQL, then creates a page using the template in
product.js. Each page gets assigned a URL in the format of