This commit is contained in:
cond0r
2021-02-04 16:03:52 +02:00
parent 67ed55d114
commit 32184ecdbd
6 changed files with 42 additions and 105 deletions

View File

@@ -11,25 +11,23 @@ type Variables = {
slug: string
}
type Options = {
variables: Variables
config: ShopifyConfig
preview?: boolean
}
type ReturnType = {
product: any
}
const getProduct = async (options: Options): Promise<ReturnType> => {
let { config, variables = { first: 250 } } = options ?? {}
const getProduct = async (options: {
variables: Variables
config: ShopifyConfig
preview?: boolean
}): Promise<ReturnType> => {
let { config, variables } = options ?? {}
config = getConfig(config)
const { data }: GraphQLFetcherResult = await config.fetch(getProductQuery, {
variables,
})
const product = data?.productByHandle?.product
const product = data?.productByHandle
return {
product: product ? normalizeProduct(product) : null,