mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
local
saleor
shopify
swell
vendure
api
endpoints
operations
get-all-pages.ts
get-all-product-paths.ts
get-all-products.ts
get-customer-wishlist.ts
get-page.ts
get-product.ts
get-site-info.ts
login.ts
utils
index.ts
auth
cart
customer
product
types
utils
wishlist
.env.template
README.md
codegen.json
commerce.config.json
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
lib
pages
public
.editorconfig
.env.template
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.json
yarn.lock
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { OperationContext, OperationOptions } from '@commerce/api/operations'
|
|
import type { GetAllProductPathsQuery } from '../../schema'
|
|
import { Provider } from '../index'
|
|
import { getAllProductPathsQuery } from '../../utils/queries/get-all-product-paths-query'
|
|
import { GetAllProductPathsOperation } from '@commerce/types/product'
|
|
import { BigcommerceConfig } from '../../../bigcommerce/api'
|
|
|
|
export type GetAllProductPathsResult = {
|
|
products: Array<{ node: { path: string } }>
|
|
}
|
|
|
|
export default function getAllProductPathsOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getAllProductPaths<
|
|
T extends GetAllProductPathsOperation
|
|
>(opts?: {
|
|
variables?: T['variables']
|
|
config?: BigcommerceConfig
|
|
}): Promise<T['data']>
|
|
|
|
async function getAllProductPaths<T extends GetAllProductPathsOperation>(
|
|
opts: {
|
|
variables?: T['variables']
|
|
config?: BigcommerceConfig
|
|
} & OperationOptions
|
|
): Promise<T['data']>
|
|
|
|
async function getAllProductPaths<T extends GetAllProductPathsOperation>({
|
|
query = getAllProductPathsQuery,
|
|
variables,
|
|
config: cfg,
|
|
}: {
|
|
query?: string
|
|
variables?: T['variables']
|
|
config?: BigcommerceConfig
|
|
} = {}): Promise<T['data']> {
|
|
const config = commerce.getConfig(cfg)
|
|
// RecursivePartial forces the method to check for every prop in the data, which is
|
|
// required in case there's a custom `query`
|
|
const { data } = await config.fetch<GetAllProductPathsQuery>(query, {
|
|
variables,
|
|
})
|
|
const products = data.products.items
|
|
|
|
return {
|
|
products: products.map((p) => ({ path: `/${p.slug}` })),
|
|
}
|
|
}
|
|
|
|
return getAllProductPaths
|
|
}
|