mirror of
https://github.com/vercel/commerce.git
synced 2025-03-31 01:05:53 +00:00
32 lines
722 B
TypeScript
32 lines
722 B
TypeScript
import { GraphQLFetcherResult } from '@commerce/api'
|
|
import { getConfig, SwellConfig } from '../api'
|
|
import { normalizeProduct, getProductQuery } from '../utils'
|
|
|
|
type Variables = {
|
|
slug: string
|
|
}
|
|
|
|
type ReturnType = {
|
|
product: any
|
|
}
|
|
|
|
const getProduct = async (options: {
|
|
variables: Variables
|
|
config: SwellConfig
|
|
preview?: boolean
|
|
}): Promise<ReturnType> => {
|
|
let { config, variables } = options ?? {}
|
|
config = getConfig(config)
|
|
|
|
const product = await config.fetchSwell('products', 'get', [variables.slug])
|
|
if (product.variants) {
|
|
product.variants = product.variants?.results
|
|
}
|
|
// console.log('product', product)
|
|
return {
|
|
product: normalizeProduct(product),
|
|
}
|
|
}
|
|
|
|
export default getProduct
|