diff --git a/framework/saleor/api/utils/fetch-all-products.ts b/framework/saleor/api/utils/fetch-all-products.ts index 152fc1d44..1cfb3157c 100644 --- a/framework/saleor/api/utils/fetch-all-products.ts +++ b/framework/saleor/api/utils/fetch-all-products.ts @@ -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 => { +}): Promise => { 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) diff --git a/framework/saleor/common/get-all-pages.ts b/framework/saleor/common/get-all-pages.ts index 27993b552..4aa90fce5 100644 --- a/framework/saleor/common/get-all-pages.ts +++ b/framework/saleor/common/get-all-pages.ts @@ -1,5 +1,5 @@ import { getConfig, SaleorConfig } from '../api' -import { PageEdge } from '../schema' +import { PageCountableEdge } from '../schema' import { getAllPagesQuery } from '../utils/queries' type Variables = { diff --git a/framework/saleor/product/get-all-collections.ts b/framework/saleor/product/get-all-collections.ts index 0356ea6ec..22e242495 100644 --- a/framework/saleor/product/get-all-collections.ts +++ b/framework/saleor/product/get-all-collections.ts @@ -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}`, diff --git a/framework/saleor/product/get-all-product-paths.ts b/framework/saleor/product/get-all-product-paths.ts index ea4867092..71bd7fd27 100644 --- a/framework/saleor/product/get-all-product-paths.ts +++ b/framework/saleor/product/get-all-product-paths.ts @@ -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}`, }, diff --git a/framework/saleor/product/get-all-products.ts b/framework/saleor/product/get-all-products.ts index 0acb3b8da..f4b6ea2c3 100644 --- a/framework/saleor/product/get-all-products.ts +++ b/framework/saleor/product/get-all-products.ts @@ -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) ) ?? [] diff --git a/framework/saleor/product/use-search.tsx b/framework/saleor/product/use-search.tsx index bf812af3d..31d72263a 100644 --- a/framework/saleor/product/use-search.tsx +++ b/framework/saleor/product/use-search.tsx @@ -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, } },