From ad1a3a11c3de78a9d83c72e8769a8dacd491cf1c Mon Sep 17 00:00:00 2001 From: l198881 <82917144+l198881@users.noreply.github.com> Date: Tue, 25 May 2021 19:06:09 -0300 Subject: [PATCH] get-all-products.ts --- framework/shopify/product/get-all-products.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/framework/shopify/product/get-all-products.ts b/framework/shopify/product/get-all-products.ts index 3915abebf..c05840d8e 100644 --- a/framework/shopify/product/get-all-products.ts +++ b/framework/shopify/product/get-all-products.ts @@ -1,37 +1,37 @@ -import { GraphQLFetcherResult } from '@commerce/api' -import { getConfig, ShopifyConfig } from '../api' -import { ProductEdge } from '../schema' -import { getAllProductsQuery } from '../utils/queries' -import { normalizeProduct } from '../utils/normalize' -import { Product } from '@commerce/types' + { GraphQLFetcherResult } '@commerce/api' + { getConfig, ShopifyConfig } '../api' + { ProductEdge } '../schema' + { getAllProductsQuery } '../utils/queries' + { normalizeProduct } '../utils/normalize' + { Product } '@commerce/types' -type Variables = { +Variables = { first?: number field?: string } -type ReturnType = { - products: Product[] +ReturnType = { + products : Product[] } -const getAllProducts = async (options: { + getAllProducts = (options: { variables?: Variables config?: ShopifyConfig preview?: boolean -}): Promise => { +}): PromiseReturnType => { let { config, variables = { first: 250 } } = options ?? {} config = getConfig(config) - const { data }: GraphQLFetcherResult = await config.fetch( + { data }: GraphQLFetcherResult = config.fetch( getAllProductsQuery, { variables } ) - const products = data.products?.edges?.map(({ node: p }: ProductEdge) => + products = data.products?.edges?.map(({ node: p }: ProductEdge) => normalizeProduct(p) ) - return { + { products, } }