Skip to content

Commit

Permalink
feat(gatsby-source-shopify): add configurable 'paginationSize' parame…
Browse files Browse the repository at this point in the history
…ter (gatsbyjs#14470)

* Add configurable 'first' parameter to cache building queries

* Rename batch size parameter to paginationSize
  • Loading branch information
cj2 authored and pieh committed Jun 3, 2019
1 parent 27b814d commit b07dcc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/gatsby-source-shopify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
]
Expand Down
7 changes: 4 additions & 3 deletions packages/gatsby-source-shopify/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -48,6 +48,7 @@ export const sourceNodes = async (
formatMsg,
verbose,
imageArgs,
paginationSize,
}

// Message printed when fetching is complete.
Expand Down Expand Up @@ -96,15 +97,15 @@ 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.
const msg = formatMsg(`fetched and processed ${endpoint}`)

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)
Expand Down

0 comments on commit b07dcc0

Please sign in to comment.