npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-source-shopify-admin

v1.4.0

Published

Gatsby source plugin for building websites using Shopify's Storefront and Admin Graphql APIs.

Downloads

17

Readme

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;