Fetch only first 100 best selling products (#310)

* Fetch only first 250 best selling products

* Update get-all-product-paths.ts

* Update use-customer.tsx
This commit is contained in:
cond0r
2021-05-24 19:44:38 +03:00
committed by GitHub
parent a4f56d1549
commit 800ba45fae
3 changed files with 22 additions and 20 deletions

View File

@@ -1,6 +1,4 @@
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'
@@ -21,21 +19,22 @@ const getAllProductPaths = async (options?: {
config?: ShopifyConfig
preview?: boolean
}): Promise<ReturnType> => {
let { config, variables = { first: 250 } } = options ?? {}
let { config, variables = { first: 100, sortKey: 'BEST_SELLING' } } =
options ?? {}
config = getConfig(config)
const products = await fetchAllProducts({
config,
query: getAllProductsPathsQuery,
const { data } = await config.fetch(getAllProductsPathsQuery, {
variables,
})
return {
products: products?.map(({ node: { handle } }: ProductEdge) => ({
node: {
path: `/${handle}`,
},
})),
products: data.products?.edges?.map(
({ node: { handle } }: ProductEdge) => ({
node: {
path: `/${handle}`,
},
})
),
}
}