mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
Added basis setup and type generation for the products queries
This commit is contained in:
@@ -7,17 +7,17 @@ const getAllCollections = async (options?: {
|
||||
config: SaleorConfig
|
||||
preview?: boolean
|
||||
}) => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
let { config, variables = { first: 100 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data } = await config.fetch(getAllCollectionsQuery, { variables })
|
||||
const edges = data.collections?.edges ?? []
|
||||
|
||||
const categories = edges.map(
|
||||
({ node: { id: entityId, title: name, handle } }: CollectionEdge) => ({
|
||||
({ node: { id: entityId, name, slug } }: CollectionEdge) => ({
|
||||
entityId,
|
||||
name,
|
||||
path: `/${handle}`,
|
||||
path: `/${slug}`,
|
||||
})
|
||||
)
|
||||
|
||||
|
@@ -21,7 +21,7 @@ const getAllProductPaths = async (options?: {
|
||||
config?: SaleorConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
let { config, variables = { first: 100 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const products = await fetchAllProducts({
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
import { getConfig, SaleorConfig } from '../api'
|
||||
import { ProductEdge } from '../schema'
|
||||
import { Product as SaleorProduct } from '../schema'
|
||||
import { getAllProductsQuery } from '../utils/queries'
|
||||
import { normalizeProduct } from '../utils/normalize'
|
||||
import { Product } from '@commerce/types'
|
||||
@@ -19,7 +19,7 @@ const getAllProducts = async (options: {
|
||||
config?: SaleorConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
let { config, variables = { first: 100 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const { data }: GraphQLFetcherResult = await config.fetch(
|
||||
@@ -28,7 +28,7 @@ const getAllProducts = async (options: {
|
||||
)
|
||||
|
||||
const products =
|
||||
data.products?.edges?.map(({ node: p }: ProductEdge) =>
|
||||
data.products?.edges?.map(({ node: p }: SaleorProduct) =>
|
||||
normalizeProduct(p)
|
||||
) ?? []
|
||||
|
||||
|
@@ -22,7 +22,7 @@ const getProduct = async (options: {
|
||||
variables,
|
||||
})
|
||||
|
||||
const { productByHandle: product } = data
|
||||
const { product } = data
|
||||
|
||||
return {
|
||||
product: product ? normalizeProduct(product) : null,
|
||||
|
Reference in New Issue
Block a user