Add Reaction Commerce provider

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux
2021-03-30 20:07:48 +04:00
parent 9b71bd77fc
commit 09249045eb
99 changed files with 24980 additions and 25 deletions

View File

@@ -0,0 +1,51 @@
import { Product } from '@commerce/types'
import { getConfig, ReactionCommerceConfig } from '../api'
import fetchAllProducts from '../api/utils/fetch-all-products'
import { ProductEdge } from '../schema'
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
type ProductPath = {
path: string
}
export type ProductPathNode = {
node: ProductPath
}
type ReturnType = {
products: ProductPathNode[]
}
const getAllProductPaths = async (options?: {
variables?: any
config?: ReactionCommerceConfig
preview?: boolean
}): Promise<ReturnType> => {
let { config, variables = { first: 250 } } = options ?? {}
config = getConfig(config)
const products = await fetchAllProducts({
config,
query: getAllProductsPathsQuery,
variables: {
...variables,
shopIds: [config.shopId],
},
})
return {
products: products?.map(
({
node: {
product: { slug },
},
}: CatalogItemEdge) => ({
node: {
path: `/${slug}`,
},
})
),
}
}
export default getAllProductPaths