1.4.0 • Published 6 months ago

gatsby-source-shopify-admin v1.4.0

Weekly downloads
85
License
MIT
Repository
github
Last release
6 months ago

Gatsby Source Shopify Admin

This is a Gatsby source plugin to pull data from Shopify using the Admin APIs.

This plugin was recently (Q1 2020) re-written to utilize the Shopify Bulk API.

Updated in 2022 for Gatsby v4.

Installation

yarn add gatsby-source-shopify-admin

Config

Configuration is relatively limited at the moment, if you come across a good use case for a new config option (that other people may actually use) please let me know so we can add it. For example, not everyone will need 'metafields' for products, we could add an option that would allow us to ignore metafields when querying Shopify, thus making a slightly lighter (and hopefully quicker) request to Shopify.

{
  resolve: 'gatsby-source-shopify-admin',
  options: {
    storeName: ‘YOUR_STORE_NAME',
    apiKey: ‘YOUR_ADMIN_API_KEY',
    storefrontApiKey: null,
    onlyPublished: false, // only show products that are currently published on the 'publication' aka the private app
    pollInterval: 1000 * 10,
    imagesMetafields: {
      product: null,
      collection: null
    },
    relatedCollectionMetafields: null,
    verbose: false,
    restrictQueries: false, // Adds "(first: 1)" to collections query (then ONLY creates nodes for that collections product). Probably avoid using 'onlyPublished' at the same time, incase the 'first' collection returned isn't published on your sales channel (private app). This setting aims to help when builds are slow due to lots of images but you are happy to development with limited data; be warned this may create issues with data parity to Shopify (i.e. relatedCollectionMetafields would not have data if the selected collection isn't the 1 collection we have queried)
  },
},

Image metafields

Experimental (not tested on other Shopify Plugins): If you use a custom fields plugin to store additional data on products/collections, such as AirFields, then we can parse the image URLs to return a ShopifyImage object with a localFile field, that can then be manipluated by gatsby-image. The plugin expects the Shopify metafield key to match the provided value (i.e. with the config below the key would be 'preview'), it then takes the metafield's value attribute as the originalSrc. The field name will be camelCased when assigned to the object hover_img becomes hoverImg when in use.

{
  ...yourDefaultConfigOptions,
  imageMetafields: {
    product: ['preview'],
    collection: ['hover_img'],
  },
}

Usage:

shopifyProduct {
  preview {
    localFile {
      childImageSharp {
        fluid(maxWidth: 1800) {
          ...GatsbyImageSharpFluid_withWebp_noBase64
        }
      }
    }
  }
}

shopifyCollection {
  hoverImg {
    localFile {
      childImageSharp {
        fluid(maxWidth: 1800) {
          ...GatsbyImageSharpFluid_withWebp_noBase64
        }
      }
    }
  }
}

Related collections metafields

Similar to Image metafield, you can pass an array of metafield keys that will be look up against a Product's metafields. If a match is found we will use the return 'collection handle' to connected to the Collection object. This is currently built with Airfield's Relationship field as the standard output.

{
  ...yourDefaultConfigOptions,
  relatedCollectionMetafields: ['similar', 'might_like'],
}

Usage:

shopifyProduct {
  similar {
    title
    handle
    products {
      id
      handle
    }
  }
}

Shipping rates

We have added the ability to fetch shipping rates, this works using the Storefront API to create a checkout using the given address and the first product returned from the other queries. It will then fetch shipping rates available to that address

{
  ...yourDefaultConfigOptions,
  storefrontApiKey: 'XXXXXXXXXXXXXXXXXXXXXXX',
  shippingRatesAddress: {
    address1: '1337 Pawnee Street',
    city: 'Jeffersonville',
    province: 'IN',
    country: 'United States',
  },
}

Timeout issues

We've had issues when trying to download any substantial amount of images from Shopify. If you run into connection issues or timeouts there are two things to try:

  • By default gatsby-source-filesystem will try to download 200 files concurrently, you can change this by adjusting the GATSBY_CONCURRENT_DOWNLOAD environment variable:

    GATSBY_CONCURRENT_DOWNLOAD=25 gatsby develop
  • There is currently no way to modify the timeout of 30 seconds in gatsby-source-filesystem, if you want to test locally you can manually override this by modifying your ./node_modules/gatsby-source-filesystem/create-remote-file-node.js file:

    //const CONNECTION_TIMEOUT = 30000;
    const CONNECTION_TIMEOUT = 120000;
1.4.0

6 months ago

1.3.6

6 months ago

1.2.0

8 months ago

1.3.5

7 months ago

1.3.4

7 months ago

1.3.3

7 months ago

1.3.2

7 months ago

1.3.1

8 months ago

1.3.0

8 months ago

1.0.0

2 years ago

1.1.0

2 years ago

0.1.27

3 years ago

0.1.28

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.23

4 years ago

0.1.22

4 years ago

0.1.20

4 years ago

0.1.21

4 years ago

0.1.18

4 years ago

0.1.19

4 years ago

0.1.17

4 years ago

0.1.16

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago