mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Add Reaction Commerce provider
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
42
framework/reactioncommerce/product/get-all-products.ts
Normal file
42
framework/reactioncommerce/product/get-all-products.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
import { getConfig, ReactionCommerceConfig } from '../api'
|
||||
import { CatalogItemEdge } from '../schema'
|
||||
import { catalogItemsQuery } from '../utils/queries'
|
||||
import { normalizeProduct } from '../utils/normalize'
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
type Variables = {
|
||||
first?: number
|
||||
shopIds?: string[]
|
||||
}
|
||||
|
||||
type ReturnType = {
|
||||
products: CatalogItemConnection[]
|
||||
}
|
||||
|
||||
const getAllProducts = async (options: {
|
||||
variables?: Variables
|
||||
config?: ReactionCommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data }: GraphQLFetcherResult = await config.fetch(catalogItemsQuery, {
|
||||
variables: {
|
||||
...variables,
|
||||
shopIds: [config.shopId],
|
||||
},
|
||||
})
|
||||
|
||||
const catalogItems =
|
||||
data.catalogItems?.edges?.map(({ node: p }: CatalogItemEdge) =>
|
||||
normalizeProduct(p)
|
||||
) ?? []
|
||||
|
||||
return {
|
||||
products: catalogItems,
|
||||
}
|
||||
}
|
||||
|
||||
export default getAllProducts
|
Reference in New Issue
Block a user