Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub

Description

This is in alpha - use at your own risk

This source plugin aims to improve over the existing gatsby-source-shopify by supporting incremental data fetching. This means that your first build will be just as long but subsequent builds will only need to fetch data that has changed. In my testing on a store with 1024 products, initial builds take around 90s and subsequent are around 10s.

This plugin also supports incremental builds. In order to try out incremental builds, ensure the GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES environment variable is true.

GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true yarn build --log-pages

Currently only products and collections are incrementally fetched. I have plans to support pages, blogs, and articles as well but they are lower priority (and use a completely different method).

Changes from gatsby-source-shopify

  1. No longer import article comments
  2. Product options are no longer their own node
  3. No support for running images through sharp - plan to support in future
  4. Added deprecated messages to fields deprecated in storefront api
  5. Added some new fields that are not yet in gatsby-source-shopify
  6. Rate limit storefront api requests (still testing - but consistent)
  7. Verbose logs can now be seen by adding the --verbose cli option
  8. Added more relationships between nodes (product from variant)
  9. Incremental data fetching (obviously)

How to install

npm install gatsby-source-shopify-incremental
# or
yarn add gatsby-source-shopify-incremental

TODO

Available options

interface Config {
  /**
   * The *.myshopify.com domain of your Shopify store
   * Required filed
   * Example `my-shop.myshopify.com`
   */
  myshopifyDomain: string;

  /**
   * A valid admin access token for your Shopify store
   * It must be created by the same sales channel as the
   * storefrontAccessToken
   * Required scopes (Read access):
   * - Products
   * - Product listings
   * - Resource feedback
   * - Store content
   * - Online Store pages
   */
  adminAccessToken: string;

  /**
   * A valid storefront access token for your Shopify store
   * It must be created by the same sales channel as the
   * adminAccessToken
   */
  storefrontAccessToken: string;

  /**
   * If your storefront domain is not the default
   * *.myshopify domain
   * Example `my-shop.com`
   */
  storefrontShopDomain: string;

  /**
   * Shopify api version to use
   * Optional - defaults to 2020-04
   */
  apiVersion: ApiVersion;

  /**
   * Import Shopify collections
   * Optional - defaults to true
   */
  includeCollections: boolean;

  /**
   * Import Shopify pages
   * Optional - defaults to false
   */
  includePages: boolean;

  /**
   * Import Shopify blogs
   * Optional - defaults to false
   */
  includeBlogs: boolean;

  /**
   * Indicate if you are Shopify plus
   * This will change the rate limits
   * Optional - defaults to false
   */
  shopifyPlus: boolean;
}

How to query for data

For now please reference the gatsby-source-shopify plugin. Querying should be essentially the same.

How to run tests

yarn install
yarn test

How to develop locally

  1. Install dependencies
    yarn install
  2. Link the repo
    yarn link
  3. Start the file watcher
    yarn watch
  4. From a configured gatsby site
    yarn link "gatsby-source-shopify-incremental"

Your gatsby site will now use the local version of this plugin

Additional commands:

  • Run prettier
    yarn format
  • Update generated graphql types
    yarn gen
  • Build a release
    yarn build

How to contribute

TODO

© 2023 Gatsby, Inc.