mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
normalizations & missing files
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
import toCommerceProducts from '../utils/to-commerce-products'
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import { Product } from '../schema'
|
||||
import { Product, ProductEdge } from '../schema'
|
||||
import { getAllProductsQuery } from '../utils/queries'
|
||||
import { normalizeProduct } from '@framework/lib/normalize'
|
||||
|
||||
export type ProductNode = Product
|
||||
|
||||
@@ -28,8 +28,9 @@ const getAllProducts = async (options: {
|
||||
{ variables }
|
||||
)
|
||||
|
||||
const shopifyProducts = data.products?.edges
|
||||
const products = toCommerceProducts(shopifyProducts)
|
||||
const products = data?.products?.edges?.map(({ node: p }: ProductEdge) =>
|
||||
normalizeProduct(p)
|
||||
)
|
||||
|
||||
return {
|
||||
products,
|
||||
|
@@ -2,8 +2,8 @@ import { GraphQLFetcherResult } from '@commerce/api'
|
||||
|
||||
import { getConfig, ShopifyConfig } from '../api'
|
||||
import { Product } from '../schema'
|
||||
import { toCommerceProduct } from '../utils/to-commerce-products'
|
||||
import getProductQuery from '../utils/queries/get-product-query'
|
||||
import { normalizeProduct } from '@framework/lib/normalize'
|
||||
|
||||
export type ProductNode = Product
|
||||
|
||||
@@ -25,12 +25,14 @@ const getProduct = async (options: Options): Promise<ReturnType> => {
|
||||
let { config, variables = { first: 250 } } = options ?? {}
|
||||
config = getConfig(config)
|
||||
|
||||
const {
|
||||
data: { productByHandle: product },
|
||||
}: GraphQLFetcherResult = await config.fetch(getProductQuery, { variables })
|
||||
const { data }: GraphQLFetcherResult = await config.fetch(getProductQuery, {
|
||||
variables,
|
||||
})
|
||||
|
||||
const product = data?.productByHandle?.product
|
||||
|
||||
return {
|
||||
product: product ? toCommerceProduct(product) : null,
|
||||
product: product ? normalizeProduct(product) : null,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,4 @@
|
||||
import useCommerceSearch from '@commerce/products/use-search'
|
||||
|
||||
import toCommerceProducts from '@framework/utils/to-commerce-products'
|
||||
import getAllProductsQuery from '@framework/utils/queries/get-all-products-query'
|
||||
|
||||
import type { Product } from 'framework/bigcommerce/schema'
|
||||
@@ -14,10 +12,7 @@ import {
|
||||
} from '@framework/utils/get-search-variables'
|
||||
|
||||
import sortBy from '@framework/utils/get-sort-variables'
|
||||
|
||||
export type CommerceProductEdge = {
|
||||
node: Product
|
||||
}
|
||||
import { normalizeProduct } from '@framework/lib/normalize'
|
||||
|
||||
export type SearchProductsInput = {
|
||||
search?: string
|
||||
@@ -49,8 +44,10 @@ export const fetcher: HookFetcher<
|
||||
}).then(
|
||||
({ products }): SearchProductsData => {
|
||||
return {
|
||||
products: toCommerceProducts(products.edges),
|
||||
found: !!products.edges.length,
|
||||
products: products?.edges?.map(({ node: p }: ProductEdge) =>
|
||||
normalizeProduct(p)
|
||||
),
|
||||
found: !!products?.edges?.length,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user