allow requests in getStaticProps to execute in parallel

This commit is contained in:
Tobias Koppers
2021-06-14 19:41:18 +02:00
parent d23da23dc0
commit f8fca2dd4d
9 changed files with 43 additions and 25 deletions

View File

@@ -15,20 +15,23 @@ export async function getStaticProps({
preview,
}: GetStaticPropsContext<{ slug: string }>) {
const config = { locale, locales }
const { pages } = await commerce.getAllPages({ config, preview })
const { categories } = await commerce.getSiteInfo({ config, preview })
const { product } = await commerce.getProduct({
const pagesPromise = commerce.getAllPages({ config, preview })
const siteInfoPromise = commerce.getSiteInfo({ config, preview })
const productPromise = commerce.getProduct({
variables: { slug: params!.slug },
config,
preview,
})
const { products: relatedProducts } = await commerce.getAllProducts({
const allProductsPromise = commerce.getAllProducts({
variables: { first: 4 },
config,
preview,
})
const { pages } = await pagesPromise
const { categories } = await siteInfoPromise
const { product } = await productPromise
const { products: relatedProducts } = await allProductsPromise
if (!product) {
throw new Error(`Product with slug '${params!.slug}' not found`)