Skip to content
This repository was archived by the owner on Apr 26, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,17 @@ exports.sourceNodes = async (
}
}

const { data: brands } = await moltin.get('brands')
const { data: categories } = await getPaginatedResource('categories')
const { data: collections } = await getPaginatedResource('collections')
const {
data: products,
included: { main_images = {}, files = [] } = {}
} = await getPaginatedResource('products', {}, `?include=main_image,files`)
const [
{ data: brands },
{ data: categories },
{ data: collections },
{ data: products, included: { main_images = {}, files = [] } = {} }
] = await Promise.all([
moltin.get('brands'),
getPaginatedResource('categories'),
getPaginatedResource('collections'),
getPaginatedResource('products', {}, `?include=main_image,files`)
])

const createCategories = async ({ categories }) => {
categories.forEach(async category =>
Expand All @@ -226,39 +230,30 @@ exports.sourceNodes = async (
brands.forEach(async brand => createNode(await processBrand({ brand })))
}

const createProducts = async ({
products,
main_images,
categories,
collections,
brands,
files
}) => {
const createProducts = async ({ products, ...rest }) => {
products.forEach(async product =>
createNode(
await processProduct({
product,
main_images,
categories,
collections,
brands,
files
...rest
})
)
)
}

await createProducts({
products,
main_images,
categories,
collections,
brands,
files
})
await createCollections({ collections })
await createCategories({ categories })
await createBrands({ brands })
await Promise.all([
createProducts({
products,
main_images,
categories,
collections,
brands,
files
}),
createCollections({ collections }),
createCategories({ categories }),
createBrands({ brands })
])
}

exports.onCreateNode = async ({
Expand Down