Skip to content

Commit

Permalink
SSG all products
Browse files Browse the repository at this point in the history
  • Loading branch information
paales committed Oct 4, 2023
1 parent 7374742 commit 76de862
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@ export async function getProductStaticPaths(
) {
const query = client.query({
query: ProductStaticPathsDocument,
variables: {
currentPage: 1,
pageSize: 100,
},
variables: { currentPage: 1, pageSize: 100 },
})
const pages: Promise<ApolloQueryResult<ProductStaticPathsQuery>>[] = [query]

const { data } = await query
const totalPages = data.products?.page_info?.total_pages ?? 1

if (totalPages > 1 && import.meta.graphCommerce.limitSsg !== true) {
for (let i = 2; i <= totalPages; i++) {
pages.push(
client.query({
query: ProductStaticPathsDocument,
variables: { currentPage: i, pageSize: 100 },
}),
)
}
}

const paths: Return['paths'] = (await Promise.all(pages))
.map((q) => q.data.products?.items)
.flat(1)
Expand Down

0 comments on commit 76de862

Please sign in to comment.