mirror of
https://github.com/vercel/commerce.git
synced 2025-07-01 02:41:22 +00:00
re: make search work with Saleor API (WIP)
This commit is contained in:
parent
65df8036ae
commit
a4cc1624c0
@ -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: {
|
||||||
|
@ -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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user