mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 07:45:53 +00:00
* fix update cart item * update types * update checkout * update get-page, cleanup types * revert change to incorrect file * cleanup Co-authored-by: Greg Hoskin <greghoskin@Gregs-MacBook-Pro.local>
34 lines
829 B
TypeScript
34 lines
829 B
TypeScript
import { normalizeProduct } from '../../utils'
|
|
|
|
import { Product } from '@commerce/types/product'
|
|
import { OperationContext } from '@commerce/api/operations'
|
|
import { Provider, SwellConfig } from '../'
|
|
|
|
export default function getProductOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getProduct({
|
|
variables,
|
|
config: cfg,
|
|
}: {
|
|
query?: string
|
|
variables: { slug: string }
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
}): Promise<Product | {} | any> {
|
|
const config = commerce.getConfig(cfg)
|
|
|
|
const product = await config.fetch('products', 'get', [variables.slug])
|
|
|
|
if (product && product.variants) {
|
|
product.variants = product.variants?.results
|
|
}
|
|
|
|
return {
|
|
product: product ? normalizeProduct(product) : null,
|
|
}
|
|
}
|
|
|
|
return getProduct
|
|
}
|