mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 21:51:21 +00:00
refactor: adjust the types
This commit is contained in:
parent
b5e21a54b3
commit
1e946c8b47
@ -1,4 +1,4 @@
|
||||
import { ProductEdge } from '../../schema'
|
||||
import { ProductCountableEdge } from '../../schema'
|
||||
import { SaleorConfig } from '..'
|
||||
|
||||
const fetchAllProducts = async ({
|
||||
@ -10,15 +10,15 @@ const fetchAllProducts = async ({
|
||||
}: {
|
||||
config: SaleorConfig
|
||||
query: string
|
||||
acc?: ProductEdge[]
|
||||
acc?: ProductCountableEdge[]
|
||||
variables?: any
|
||||
cursor?: string
|
||||
}): Promise<ProductEdge[]> => {
|
||||
}): Promise<ProductCountableEdge[]> => {
|
||||
const { data } = await config.fetch(query, {
|
||||
variables: { ...variables, cursor },
|
||||
})
|
||||
|
||||
const edges: ProductEdge[] = data.products?.edges ?? []
|
||||
const edges: ProductCountableEdge[] = data.products?.edges ?? []
|
||||
const hasNextPage = data.products?.pageInfo?.hasNextPage
|
||||
acc = acc.concat(edges)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { getConfig, SaleorConfig } from '../api'
|
||||
import { PageEdge } from '../schema'
|
||||
import { PageCountableEdge } from '../schema'
|
||||
import { getAllPagesQuery } from '../utils/queries'
|
||||
|
||||
type Variables = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CollectionEdge } from '../schema'
|
||||
import { CollectionCountableEdge } from '../schema'
|
||||
import { getConfig, SaleorConfig } from '../api'
|
||||
import getAllCollectionsQuery from '../utils/queries/get-all-collections-query'
|
||||
|
||||
@ -14,7 +14,7 @@ const getAllCollections = async (options?: {
|
||||
const edges = data.collections?.edges ?? []
|
||||
|
||||
const categories = edges.map(
|
||||
({ node: { id: entityId, name, slug } }: CollectionEdge) => ({
|
||||
({ node: { id: entityId, name, slug } }: CollectionCountableEdge) => ({
|
||||
entityId,
|
||||
name,
|
||||
path: `/${slug}`,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Product } from '@commerce/types'
|
||||
import { getConfig, SaleorConfig } from '../api'
|
||||
import fetchAllProducts from '../api/utils/fetch-all-products'
|
||||
import { ProductEdge } from '../schema'
|
||||
import { ProductCountableEdge } from '../schema'
|
||||
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
|
||||
|
||||
type ProductPath = {
|
||||
@ -31,7 +31,7 @@ const getAllProductPaths = async (options?: {
|
||||
})
|
||||
|
||||
return {
|
||||
products: products?.map(({ node: { handle } }: ProductEdge) => ({
|
||||
products: products?.map(({ node: { slug } }: ProductCountableEdge) => ({
|
||||
node: {
|
||||
path: `/${handle}`,
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { GraphQLFetcherResult } from '@commerce/api'
|
||||
import { getConfig, SaleorConfig } from '../api'
|
||||
import { Product as SaleorProduct } from '../schema'
|
||||
import { ProductCountableEdge } from '../schema'
|
||||
import { getAllProductsQuery } from '../utils/queries'
|
||||
import { normalizeProduct } from '../utils/normalize'
|
||||
import { Product } from '@commerce/types'
|
||||
@ -28,7 +28,7 @@ const getAllProducts = async (options: {
|
||||
)
|
||||
|
||||
const products =
|
||||
data.products?.edges?.map(({ node: p }: SaleorProduct) =>
|
||||
data.products?.edges?.map(({ node: p }: ProductCountableEdge) =>
|
||||
normalizeProduct(p)
|
||||
) ?? []
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
|
||||
import { ProductEdge } from '../schema'
|
||||
import { ProductCountableEdge } from '../schema'
|
||||
import {
|
||||
getAllProductsQuery,
|
||||
getCollectionProductsQuery,
|
||||
@ -57,7 +57,9 @@ export const handler: SWRHook<
|
||||
}
|
||||
|
||||
return {
|
||||
products: edges.map(({ node }: ProductEdge) => normalizeProduct(node)),
|
||||
products: edges.map(({ node }: ProductCountableEdge) =>
|
||||
normalizeProduct(node)
|
||||
),
|
||||
found: !!edges.length,
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user