Skip to content

Filter _operator for nested fields not apply  #304

@dmfilipenko

Description

@dmfilipenko

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions