mirror of
https://github.com/vercel/commerce.git
synced 2025-03-28 16:25:53 +00:00
* Updated core types for commerce provider * Updated bigcommerce provider * Added util method for provider creation * Removed unrequired code from saleor * Updated shopify provider * Updated providers and local setup * Updated saleor setup * Updated swell * Updated vendure * Updated swell-js usage * Removed unrequired import from saleor
39 lines
996 B
TypeScript
39 lines
996 B
TypeScript
import type { OperationContext } from '@commerce/api/operations'
|
|
import { ProductCountableEdge } from '../../schema'
|
|
import type { Provider, SaleorConfig } from '..'
|
|
|
|
import { getAllProductsPathsQuery } from '../../utils/queries'
|
|
import fetchAllProducts from '../utils/fetch-all-products'
|
|
|
|
export type GetAllProductPathsResult = {
|
|
products: Array<{ path: string }>
|
|
}
|
|
|
|
export default function getAllProductPathsOperation({ commerce }: OperationContext<Provider>) {
|
|
async function getAllProductPaths({
|
|
query,
|
|
config,
|
|
variables,
|
|
}: {
|
|
query?: string
|
|
config?: SaleorConfig
|
|
variables?: any
|
|
} = {}): Promise<GetAllProductPathsResult> {
|
|
config = commerce.getConfig(config)
|
|
|
|
const products = await fetchAllProducts({
|
|
config,
|
|
query: getAllProductsPathsQuery,
|
|
variables,
|
|
})
|
|
|
|
return {
|
|
products: products?.map(({ node: { slug } }: ProductCountableEdge) => ({
|
|
path: `/${slug}`,
|
|
})),
|
|
}
|
|
}
|
|
|
|
return getAllProductPaths
|
|
}
|