From a4cc1624c05ad1b39846f037f530182f3f0756b9 Mon Sep 17 00:00:00 2001 From: Zaiste Date: Tue, 20 Apr 2021 16:32:49 +0200 Subject: [PATCH] re: make search work with Saleor API (WIP) --- framework/saleor/fetcher.ts | 2 +- framework/saleor/utils/get-search-variables.ts | 12 +----------- .../saleor/utils/queries/get-all-products-query.ts | 3 ++- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/framework/saleor/fetcher.ts b/framework/saleor/fetcher.ts index 14cf85e9c..4cfb23a55 100644 --- a/framework/saleor/fetcher.ts +++ b/framework/saleor/fetcher.ts @@ -9,7 +9,7 @@ const fetcher: Fetcher = async ({ query, }) => { return handleFetchResponse( - await fetch(url, { + await fetch(url!, { method, body: JSON.stringify({ query, variables }), headers: { diff --git a/framework/saleor/utils/get-search-variables.ts b/framework/saleor/utils/get-search-variables.ts index c1b40ae5d..04f215e5a 100644 --- a/framework/saleor/utils/get-search-variables.ts +++ b/framework/saleor/utils/get-search-variables.ts @@ -7,19 +7,9 @@ export const getSearchVariables = ({ categoryId, sort, }: SearchProductsInput) => { - let query = '' - - if (search) { - query += `product_type:${search} OR title:${search} OR tag:${search}` - } - - if (brandId) { - query += `${search ? ' AND ' : ''}vendor:${brandId}` - } - return { categoryId, - query, + filter: { search }, ...getSortVariables(sort, !!categoryId), } } diff --git a/framework/saleor/utils/queries/get-all-products-query.ts b/framework/saleor/utils/queries/get-all-products-query.ts index 87be83868..f17082c59 100644 --- a/framework/saleor/utils/queries/get-all-products-query.ts +++ b/framework/saleor/utils/queries/get-all-products-query.ts @@ -31,9 +31,10 @@ export const productConnection = /* GraphQL */ ` const getAllProductsQuery = /* GraphQL */ ` query getAllProducts( $first: Int = 100 + $filter: ProductFilterInput $channel: String = "default-channel" ) { - products(first: $first, channel: $channel) { + products(first: $first, channel: $channel, filter: $filter) { ...productConnnection } }