mirror of
https://github.com/vercel/commerce.git
synced 2025-08-13 20:31:23 +00:00
.vscode
assets
components
config
framework
bigcommerce
commerce
local
saleor
shopify
swell
api
cart
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
login.ts
utils
wishlist
customer.ts
index.ts
auth
cart
customer
product
types
utils
wishlist
.env.template
commerce.config.json
const.ts
fetcher.ts
index.tsx
next.config.js
provider.ts
schema.d.ts
schema.graphql
types.ts
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.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.json
yarn.lock
* fix update cart item * update types * update checkout * update get-page, cleanup types * revert change to incorrect file * cleanup Co-authored-by: Greg Hoskin <greghoskin@Gregs-MacBook-Pro.local>
34 lines
829 B
TypeScript
34 lines
829 B
TypeScript
import { normalizeProduct } from '../../utils'
|
|
|
|
import { Product } from '@commerce/types/product'
|
|
import { OperationContext } from '@commerce/api/operations'
|
|
import { Provider, SwellConfig } from '../'
|
|
|
|
export default function getProductOperation({
|
|
commerce,
|
|
}: OperationContext<Provider>) {
|
|
async function getProduct({
|
|
variables,
|
|
config: cfg,
|
|
}: {
|
|
query?: string
|
|
variables: { slug: string }
|
|
config?: Partial<SwellConfig>
|
|
preview?: boolean
|
|
}): Promise<Product | {} | any> {
|
|
const config = commerce.getConfig(cfg)
|
|
|
|
const product = await config.fetch('products', 'get', [variables.slug])
|
|
|
|
if (product && product.variants) {
|
|
product.variants = product.variants?.results
|
|
}
|
|
|
|
return {
|
|
product: product ? normalizeProduct(product) : null,
|
|
}
|
|
}
|
|
|
|
return getProduct
|
|
}
|