forked from crowetic/commerce
Fix product paths
This commit is contained in:
parent
de80a9edd1
commit
4d9b9f77b2
@ -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 type { RecursivePartial, RecursiveRequired } from '../utils/types'
|
||||||
import filterEdges from '../utils/filter-edges'
|
import filterEdges from '../utils/filter-edges'
|
||||||
import { BigcommerceConfig, getConfig } from '..'
|
import { BigcommerceConfig, getConfig } from '..'
|
||||||
|
|
||||||
export const getAllProductPathsQuery = /* GraphQL */ `
|
export const getAllProductPathsQuery = /* GraphQL */ `
|
||||||
query getAllProductPaths {
|
query getAllProductPaths($first: Int = 100) {
|
||||||
site {
|
site {
|
||||||
products {
|
products(first: $first) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
path
|
path
|
||||||
@ -23,11 +26,14 @@ export type ProductPath = NonNullable<
|
|||||||
|
|
||||||
export type ProductPaths = ProductPath[]
|
export type ProductPaths = ProductPath[]
|
||||||
|
|
||||||
|
export type { GetAllProductPathsQueryVariables }
|
||||||
|
|
||||||
export type GetAllProductPathsResult<
|
export type GetAllProductPathsResult<
|
||||||
T extends { products: any[] } = { products: ProductPaths }
|
T extends { products: any[] } = { products: ProductPaths }
|
||||||
> = T
|
> = T
|
||||||
|
|
||||||
async function getAllProductPaths(opts?: {
|
async function getAllProductPaths(opts?: {
|
||||||
|
variables?: GetAllProductPathsQueryVariables
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
}): Promise<GetAllProductPathsResult>
|
}): Promise<GetAllProductPathsResult>
|
||||||
|
|
||||||
@ -36,14 +42,17 @@ async function getAllProductPaths<
|
|||||||
V = any
|
V = any
|
||||||
>(opts: {
|
>(opts: {
|
||||||
query: string
|
query: string
|
||||||
|
variables?: V
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
}): Promise<GetAllProductPathsResult<T>>
|
}): Promise<GetAllProductPathsResult<T>>
|
||||||
|
|
||||||
async function getAllProductPaths({
|
async function getAllProductPaths({
|
||||||
query = getAllProductPathsQuery,
|
query = getAllProductPathsQuery,
|
||||||
|
variables,
|
||||||
config,
|
config,
|
||||||
}: {
|
}: {
|
||||||
query?: string
|
query?: string
|
||||||
|
variables?: GetAllProductPathsQueryVariables
|
||||||
config?: BigcommerceConfig
|
config?: BigcommerceConfig
|
||||||
} = {}): Promise<GetAllProductPathsResult> {
|
} = {}): Promise<GetAllProductPathsResult> {
|
||||||
config = getConfig(config)
|
config = getConfig(config)
|
||||||
@ -51,7 +60,7 @@ async function getAllProductPaths({
|
|||||||
// required in case there's a custom `query`
|
// required in case there's a custom `query`
|
||||||
const { data } = await config.fetch<
|
const { data } = await config.fetch<
|
||||||
RecursivePartial<GetAllProductPathsQuery>
|
RecursivePartial<GetAllProductPathsQuery>
|
||||||
>(query)
|
>(query, { variables })
|
||||||
const products = data.site?.products?.edges
|
const products = data.site?.products?.edges
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
4
lib/bigcommerce/schema.d.ts
vendored
4
lib/bigcommerce/schema.d.ts
vendored
@ -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' } & {
|
export type GetAllProductPathsQuery = { __typename?: 'Query' } & {
|
||||||
site: { __typename?: 'Site' } & {
|
site: { __typename?: 'Site' } & {
|
||||||
|
@ -27,6 +27,7 @@ export async function getStaticPaths() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
paths: products.map((product) => `/product${product.node.path}`),
|
paths: products.map((product) => `/product${product.node.path}`),
|
||||||
|
// If your store has tons of products, enable fallback mode to improve build times!
|
||||||
fallback: false,
|
fallback: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user