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,
}) => {
return handleFetchResponse(
await fetch(url, {
await fetch(url!, {
method,
body: JSON.stringify({ query, variables }),
headers: {

View File

@ -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),
}
}

View File

@ -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
}
}