re: make search work with Saleor API (WIP)

This commit is contained in:
Zaiste 2021-04-20 16:32:49 +02:00
parent 65df8036ae
commit a4cc1624c0
No known key found for this signature in database
GPG Key ID: 15DF7EBC7F2FFE35
3 changed files with 4 additions and 13 deletions

View File

@ -9,7 +9,7 @@ const fetcher: Fetcher = async ({
query, query,
}) => { }) => {
return handleFetchResponse( return handleFetchResponse(
await fetch(url, { await fetch(url!, {
method, method,
body: JSON.stringify({ query, variables }), body: JSON.stringify({ query, variables }),
headers: { headers: {

View File

@ -7,19 +7,9 @@ export const getSearchVariables = ({
categoryId, categoryId,
sort, sort,
}: SearchProductsInput) => { }: SearchProductsInput) => {
let query = ''
if (search) {
query += `product_type:${search} OR title:${search} OR tag:${search}`
}
if (brandId) {
query += `${search ? ' AND ' : ''}vendor:${brandId}`
}
return { return {
categoryId, categoryId,
query, filter: { search },
...getSortVariables(sort, !!categoryId), ...getSortVariables(sort, !!categoryId),
} }
} }

View File

@ -31,9 +31,10 @@ export const productConnection = /* GraphQL */ `
const getAllProductsQuery = /* GraphQL */ ` const getAllProductsQuery = /* GraphQL */ `
query getAllProducts( query getAllProducts(
$first: Int = 100 $first: Int = 100
$filter: ProductFilterInput
$channel: String = "default-channel" $channel: String = "default-channel"
) { ) {
products(first: $first, channel: $channel) { products(first: $first, channel: $channel, filter: $filter) {
...productConnnection ...productConnnection
} }
} }