From b07dcc0515588d09cda6e075616b4d013524b41c Mon Sep 17 00:00:00 2001 From: CJ Date: Mon, 3 Jun 2019 04:03:28 -0600 Subject: [PATCH] feat(gatsby-source-shopify): add configurable 'paginationSize' parameter (#14470) * Add configurable 'first' parameter to cache building queries * Rename batch size parameter to paginationSize --- packages/gatsby-source-shopify/README.md | 5 +++++ packages/gatsby-source-shopify/src/gatsby-node.js | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-shopify/README.md b/packages/gatsby-source-shopify/README.md index 71bd5d4fedd3a..3d7258c4a19fe 100644 --- a/packages/gatsby-source-shopify/README.md +++ b/packages/gatsby-source-shopify/README.md @@ -52,6 +52,11 @@ plugins: [ // much time was required to fetch and process the data. // Defaults to true. verbose: true, + + // Number of records to fetch on each request when building the cache + // at startup. If your application encounters timeout errors during + // startup, try decreasing this number. + paginationSize: 250, }, }, ] diff --git a/packages/gatsby-source-shopify/src/gatsby-node.js b/packages/gatsby-source-shopify/src/gatsby-node.js index dc0451d6c10b1..ac01f6c1edccf 100644 --- a/packages/gatsby-source-shopify/src/gatsby-node.js +++ b/packages/gatsby-source-shopify/src/gatsby-node.js @@ -26,7 +26,7 @@ import { export const sourceNodes = async ( { actions: { createNode, touchNode }, createNodeId, store, cache }, - { shopName, accessToken, verbose = true } + { shopName, accessToken, verbose = true, paginationSize = 250 } ) => { const client = createClient(shopName, accessToken) @@ -48,6 +48,7 @@ export const sourceNodes = async ( formatMsg, verbose, imageArgs, + paginationSize, } // Message printed when fetching is complete. @@ -96,7 +97,7 @@ const createNodes = async ( endpoint, query, nodeFactory, - { client, createNode, formatMsg, verbose, imageArgs }, + { client, createNode, formatMsg, verbose, imageArgs, paginationSize }, f = async () => {} ) => { // Message printed when fetching is complete. @@ -104,7 +105,7 @@ const createNodes = async ( if (verbose) console.time(msg) await forEach( - await queryAll(client, [`shop`, endpoint], query), + await queryAll(client, [`shop`, endpoint], query, paginationSize), async entity => { const node = await nodeFactory(imageArgs)(entity) createNode(node)