Fix product paths

This commit is contained in:
Luis Alvarez 2020-10-22 21:38:03 -05:00
parent de80a9edd1
commit 4d9b9f77b2
3 changed files with 17 additions and 5 deletions

View File

@ -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<GetAllProductPathsResult>
@ -36,14 +42,17 @@ async function getAllProductPaths<
V = any
>(opts: {
query: string
variables?: V
config?: BigcommerceConfig
}): Promise<GetAllProductPathsResult<T>>
async function getAllProductPaths({
query = getAllProductPathsQuery,
variables,
config,
}: {
query?: string
variables?: GetAllProductPathsQueryVariables
config?: BigcommerceConfig
} = {}): Promise<GetAllProductPathsResult> {
config = getConfig(config)
@ -51,7 +60,7 @@ async function getAllProductPaths({
// required in case there's a custom `query`
const { data } = await config.fetch<
RecursivePartial<GetAllProductPathsQuery>
>(query)
>(query, { variables })
const products = data.site?.products?.edges
return {

View File

@ -1827,7 +1827,9 @@ export type ProductConnnectionFragment = {
>
}
export type GetAllProductPathsQueryVariables = Exact<{ [key: string]: never }>
export type GetAllProductPathsQueryVariables = Exact<{
first?: Maybe<Scalars['Int']>
}>
export type GetAllProductPathsQuery = { __typename?: 'Query' } & {
site: { __typename?: 'Site' } & {

View File

@ -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,
}
}