mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 06:01:21 +00:00
31 lines
657 B
TypeScript
31 lines
657 B
TypeScript
import { GraphQLFetcherResult } from '@commerce/api'
|
|
import { getConfig, SaleorConfig } from '../api'
|
|
import { normalizeProduct, getProductQuery } from '../utils'
|
|
|
|
type Variables = {
|
|
slug: string
|
|
}
|
|
|
|
type ReturnType = {
|
|
product: any
|
|
}
|
|
|
|
const getProduct = async (options: {
|
|
variables: Variables
|
|
config: SaleorConfig
|
|
preview?: boolean
|
|
}): Promise<ReturnType> => {
|
|
let { config, variables } = options ?? {}
|
|
config = getConfig(config)
|
|
|
|
const { data }: GraphQLFetcherResult = await config.fetch(getProductQuery, {
|
|
variables,
|
|
})
|
|
|
|
return {
|
|
product: data?.product ? normalizeProduct(data.product) : null,
|
|
}
|
|
}
|
|
|
|
export default getProduct
|