1
0
mirror of https://github.com/vercel/commerce.git synced 2025-08-13 20:31:23 +00:00
Files
.vscode
assets
components
config
framework
bigcommerce
commerce
commercejs
kibocommerce
local
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
lib
pages
public
.editorconfig
.env.template
.eslintrc
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package-lock.json
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.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
}