mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
latest
This commit is contained in:
parent
bb9cfa0cd1
commit
3e0a185f84
@ -1,42 +0,0 @@
|
|||||||
import { Product } from '@commerce/types'
|
|
||||||
import { getConfig, ShopifyConfig } from '../api'
|
|
||||||
import fetchAllProducts from '../api/utils/fetch-all-products'
|
|
||||||
import { ProductEdge } from '../schema'
|
|
||||||
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
|
|
||||||
|
|
||||||
type ProductPath = {
|
|
||||||
path: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ProductPathNode = {
|
|
||||||
node: ProductPath
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReturnType = {
|
|
||||||
products: ProductPathNode[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const getAllProductPaths = async (options?: {
|
|
||||||
variables?: any
|
|
||||||
config?: ShopifyConfig
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<ReturnType> => {
|
|
||||||
let { config, variables = { first: 250 } } = options ?? {}
|
|
||||||
config = getConfig(config)
|
|
||||||
|
|
||||||
const products = await fetchAllProducts({
|
|
||||||
config,
|
|
||||||
query: getAllProductsPathsQuery,
|
|
||||||
variables,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
products: products?.map(({ node: { handle } }: ProductEdge) => ({
|
|
||||||
node: {
|
|
||||||
path: `/${handle}`,
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default getAllProductPaths
|
|
@ -1,40 +0,0 @@
|
|||||||
import { GraphQLFetcherResult } from '@commerce/api'
|
|
||||||
import { getConfig, ShopifyConfig } from '../api'
|
|
||||||
import { ProductEdge } from '../schema'
|
|
||||||
import { getAllProductsQuery } from '../utils/queries'
|
|
||||||
import { normalizeProduct } from '../utils/normalize'
|
|
||||||
import { Product } from '@commerce/types'
|
|
||||||
|
|
||||||
type Variables = {
|
|
||||||
first?: number
|
|
||||||
field?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReturnType = {
|
|
||||||
products: Product[]
|
|
||||||
}
|
|
||||||
|
|
||||||
const getAllProducts = async (options: {
|
|
||||||
variables?: Variables
|
|
||||||
config?: ShopifyConfig
|
|
||||||
preview?: boolean
|
|
||||||
}): Promise<ReturnType> => {
|
|
||||||
let { config, variables = { first: 250 } } = options ?? {}
|
|
||||||
config = getConfig(config)
|
|
||||||
|
|
||||||
const { data }: GraphQLFetcherResult = await config.fetch(
|
|
||||||
getAllProductsQuery,
|
|
||||||
{ variables }
|
|
||||||
)
|
|
||||||
|
|
||||||
const products =
|
|
||||||
data.products?.edges?.map(({ node: p }: ProductEdge) =>
|
|
||||||
normalizeProduct(p)
|
|
||||||
) ?? []
|
|
||||||
|
|
||||||
return {
|
|
||||||
products,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default getAllProducts
|
|
@ -1,32 +0,0 @@
|
|||||||
import { GraphQLFetcherResult } from '@commerce/api'
|
|
||||||
import { getConfig, ShopifyConfig } from '../api'
|
|
||||||
import { normalizeProduct, getProductQuery } from '../utils'
|
|
||||||
|
|
||||||
type Variables = {
|
|
||||||
slug: string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReturnType = {
|
|
||||||
product: any
|
|
||||||
}
|
|
||||||
|
|
||||||
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 { productByHandle } = data
|
|
||||||
|
|
||||||
return {
|
|
||||||
product: productByHandle ? normalizeProduct(productByHandle) : null,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default getProduct
|
|
Loading…
x
Reference in New Issue
Block a user