1
0
mirror of https://github.com/vercel/commerce.git synced 2025-08-09 18:31:23 +00:00
Files
.vscode
framework
commercejs
kibocommerce
ordercloud
saleor
api
catalog
customers
endpoints
operations
get-all-pages.ts
get-all-product-paths.ts
get-all-products.ts
get-page.ts
get-product.ts
get-site-info.ts
index.ts
login.ts
utils
cart.ts
checkout.ts
index.ts
wishlist.ts
auth
cart
checkout
customer
product
types
utils
wishlist
.env.template
README.md
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
shopify
spree
swell
vendure
packages
site
.editorconfig
.gitignore
.prettierignore
.prettierrc
README.md
license.md
package-copy.json
package-lock.json
package.json
commerce/framework/saleor/api/operations/get-product.ts
2021-11-25 09:17:13 -03:00

47 lines
976 B
TypeScript

import type { OperationContext } from '@commerce/api/operations'
import { normalizeProduct } from '../../utils'
import type { Provider, SaleorConfig } from '..'
import * as Query from '../../utils/queries'
type Variables = {
slug: string
}
type ReturnType = {
product: any
}
export default function getProductOperation({ commerce }: OperationContext<Provider>) {
async function getProduct({
query = Query.ProductOneBySlug,
variables,
config: cfg,
}: {
query?: string
variables: Variables
config?: Partial<SaleorConfig>
preview?: boolean
}): Promise<ReturnType> {
const { fetch, locale } = commerce.getConfig(cfg)
const { data } = await fetch(
query,
{ variables },
{
...(locale && {
headers: {
'Accept-Language': locale,
},
}),
}
)
return {
product: data?.product ? normalizeProduct(data.product) : null,
}
}
return getProduct
}