Closed lfaz closed 2 years ago
Also trying something like which still cant make it work:
.addFilterArg({
name: "priceRange",
type: `input priceRange {
priceFrom: Float!
priceTo: Float!
}`,
description: "Search by price greater or equal than x",
query: (rawQuery, value) => {
rawQuery.price = {
$and: [{ $gte: value.priceFrom }, { $lte: value.priceTo }],
};
},
}),
Try to activate mongoose.set('debug', true)
and check raw query.
in fact I managed to solve this out from this https://github.com/graphql-compose/graphql-compose/issues/22, there is a InputRange min,max example that seem to work pretty nice. I guess I will just close this issue!
My final solution that seem to work:
name: "PriceRange",
type: `input priceRange {
min: Float
max: Float
}`,
query: (rawQuery, value, resolveParams) => {
let minPrice = value.min || 0;
let maxPrice = value.max || 0;
if (!minPrice && !maxPrice) return;
if (minPrice > maxPrice && minPrice && maxPrice)
[minPrice, maxPrice] = [maxPrice, minPrice];
rawQuery.price = {};
if (minPrice) {
rawQuery.price.$gte = minPrice;
}
if (maxPrice) {
rawQuery.price.$lte = maxPrice;
}
},
I am trying to use the pagination plugin to list out the items and I have following code
And I try to use it like:
it doesnt seem to work, it only takes in consideration the first field
priceFrom
, any idea how to fix this? It should be pretty simple condition imo.Also tried to do like which didnt work at all