diff --git a/lib/bigcommerce/api/operations/get-all-product-paths.ts b/lib/bigcommerce/api/operations/get-all-product-paths.ts index 483160f6b..9aea42126 100644 --- a/lib/bigcommerce/api/operations/get-all-product-paths.ts +++ b/lib/bigcommerce/api/operations/get-all-product-paths.ts @@ -1,12 +1,15 @@ -import type { GetAllProductPathsQuery } from 'lib/bigcommerce/schema' +import type { + GetAllProductPathsQuery, + GetAllProductPathsQueryVariables, +} from 'lib/bigcommerce/schema' import type { RecursivePartial, RecursiveRequired } from '../utils/types' import filterEdges from '../utils/filter-edges' import { BigcommerceConfig, getConfig } from '..' export const getAllProductPathsQuery = /* GraphQL */ ` - query getAllProductPaths { + query getAllProductPaths($first: Int = 100) { site { - products { + products(first: $first) { edges { node { path @@ -23,11 +26,14 @@ export type ProductPath = NonNullable< export type ProductPaths = ProductPath[] +export type { GetAllProductPathsQueryVariables } + export type GetAllProductPathsResult< T extends { products: any[] } = { products: ProductPaths } > = T async function getAllProductPaths(opts?: { + variables?: GetAllProductPathsQueryVariables config?: BigcommerceConfig }): Promise @@ -36,14 +42,17 @@ async function getAllProductPaths< V = any >(opts: { query: string + variables?: V config?: BigcommerceConfig }): Promise> async function getAllProductPaths({ query = getAllProductPathsQuery, + variables, config, }: { query?: string + variables?: GetAllProductPathsQueryVariables config?: BigcommerceConfig } = {}): Promise { config = getConfig(config) @@ -51,7 +60,7 @@ async function getAllProductPaths({ // required in case there's a custom `query` const { data } = await config.fetch< RecursivePartial - >(query) + >(query, { variables }) const products = data.site?.products?.edges return { diff --git a/lib/bigcommerce/schema.d.ts b/lib/bigcommerce/schema.d.ts index 361d45a30..cf7168992 100644 --- a/lib/bigcommerce/schema.d.ts +++ b/lib/bigcommerce/schema.d.ts @@ -1827,7 +1827,9 @@ export type ProductConnnectionFragment = { > } -export type GetAllProductPathsQueryVariables = Exact<{ [key: string]: never }> +export type GetAllProductPathsQueryVariables = Exact<{ + first?: Maybe +}> export type GetAllProductPathsQuery = { __typename?: 'Query' } & { site: { __typename?: 'Site' } & { diff --git a/pages/product/[slug].tsx b/pages/product/[slug].tsx index 94acc2445..7d73b859c 100644 --- a/pages/product/[slug].tsx +++ b/pages/product/[slug].tsx @@ -27,6 +27,7 @@ export async function getStaticPaths() { return { paths: products.map((product) => `/product${product.node.path}`), + // If your store has tons of products, enable fallback mode to improve build times! fallback: false, } }