question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[gatsby-source-shopify] — Limit products in ShopifyCollection

See original GitHub issue

Summary

Wouldn’t it be great to limit the number of products pulled in when querying a collection in the gatsby-source-shopify plugin? This would reduce the size of the generated page-data.json files, making page load and prefetching even faster.

Basic example

myCollection: shopifyCollection(handle: { eq: "kitchen" }) {
  handle
  products(limit: 18) {
    edges {
      node {
        id
      }
    }
  }
}

Motivation

Speed. And thrift.

Right now the plugin pulls in all the products in a collection. Say you only want to tease a collection by showing two or three products on a shop overview page and give the user the option to drill deeper. Right now i get rather largish page-data.json files that include all the queried data, although i will never use it.

We could do the same for images as well. Sometimes i don’t need more than one image of a product or category.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
angeloashmorecommented, May 12, 2020

As an aside, it would be nice to have generic resolvers that allowed limit, sort, skip, etc. on array values. Something like a @listOperators directive:

type ShopifyCollection {
  products: [ShopifyProduct] @listOperators
}

Something like that could benefit other source plugins.

0reactions
connordowsoncommented, Oct 8, 2021

I got this to work using this

exports.createResolvers = ({ createResolvers }) => {
  createResolvers({
    ShopifyCollection: {
      // Add products from the selected section(s)
      products: {
        args: {
          limit: `Int`,
        },
        resolve: async (root, args, context, info) => {
          const allProductsInCollection =
            (await info.originalResolver(root, args, context, info)) || []

          return args.limit
            ? allProductsInCollection.slice(0, args.limit)
            : allProductsInCollection
        },
      },
    },
  })
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-source-shopify-incremental
Currently only products and collections are incrementally fetched. I have plans to support pages, blogs, and articles as well but they are lower...
Read more >
How does salesChannel work? I want to filter products that are ...
Basically, I have several different sites, each using a private app to limit each site's "inventory" to just the inventory that is specified...
Read more >
Query multiple collections from Shopify in GatsbyJS
I want to display groups of Shopify products based on what collections they're associated with, using gatsby-source-shopify.
Read more >
Headless Shopify: Lessons Learned Building with Gatsby, Part 2
A “document” is an instance of a type (e.g., my type is “Product” and my document is “Blue Dress”). Gatsby has a source...
Read more >
GraphQL Storefront API - Shopify.dev
The API offers a full range of commerce options making it possible for customers to view products and collections, add products to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found