4
0
forked from crowetic/commerce
commerce/framework/swell/product/get-product.ts
2021-04-04 14:45:48 -06:00

29 lines
622 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)
return {
product: product ? normalizeProduct(product) : null,
}
}
export default getProduct