-
-
Notifications
You must be signed in to change notification settings - Fork 96
Closed
Description
Short version:
When I'm writing filter _operator with nested structure, it's not apply to final mongoose query.
orders.find({ orderStatus: { '$ne': 'PAID' } }, { projection: { 'items._id': true, 'items.inbound.timeStamp': true, _id: true, 'inbound.timeStamp': true }})
filter: {
_operators: {
inbound: { timeStamp: { ne: null } }
orderStatus: { ne: "PAID" }
}
}
Long version with details:
Have a such resolver
OrderTC.mongooseResolvers
.findMany({
suffix: "Extended",
filter: {
operators: true,
},
})Schema
const orderSchema = new Schema(
{
_id: String,
orderStatus: String
inbound: {
timeStamp: {
type: Date,
index: true,
},
},
},
{
autoCreate: true,
timestamps: true,
_id: false,
}
)Filter arguments:
filter: {
_operators: {
inbound: { timeStamp: { ne: null } }
orderStatus: { ne: "PAID" }
}
}And what I see as a final query to mongo is
orders.find({ orderStatus: { '$ne': 'PAID' } }, { projection: { 'items._id': true, 'items.inbound.timeStamp': true, _id: true, 'inbound.timeStamp': true }})
Actually to be more precise I'm recreating preparePaginationResolver
import { preparePaginationResolver } from "graphql-compose-pagination"
const findMany = OrderTC.mongooseResolvers
.findMany({
suffix: "Extended",
filter: {
operators: true,
},
})
.addFilterArg({
name: "retailerName",
type: "String",
})
.wrapResolve((next) => async (rp) => {
const retailerName = rp.args.filter?.retailerName
if (retailerName) {
...some logic...
}
return next(rp)
})
const count = OrderTC.mongooseResolvers
.count({ suffix: "Extended" })
const pageResolver = preparePaginationResolver(OrderTC, {
findManyResolver: findMany,
countResolver: count,
name: "pagination",
perPage: 50,
})
export const orderPagination = pageResolver