profile
viewpoint

Ask questionsFiltering on an existing field with wrapResolve

I've been trying to wrap the "findMany" resolver with a simple filter on an existing field from the Schema, but the traditional approach from the graphql-compose page on wrapResolve() does not seem to be working as rp.args only includes limit - it does not include filter or skip, which is odd because I can still use those in regular queries from GraphiQL or the frontend.

Since rp.args should include filter, limit, and skip, and orderStatus is a field on my Schema, this seems like it should be able to filter the orders to only return those in which the orderStatus field is equal to "Placed".

activeOrders: OrderTC.getResolver("findMany").wrapResolve(next => rp => {
        console.log(rp.args);
        rp.args.filter.orderStatus = "Placed";
        return next(rp);
})

However, this throws an error because it says that rp.args.filter is undefined. Trying rp.args.fulfillment also does not work.

I should also note that I can successfully filter when making a query or mutation call from the frontend.

query OrderSelect {
  findMany(filter:{ orderStatus:"Placed"}) {
    _id
    user {
        name
    }
  }
}
graphql-compose/graphql-compose-mongoose

Answer questions nodkz

It's very strange, we have a lot of places with such logic and it works.

Maybe you have an error in your code? In your example, I see that you provide resolver activeOrders field but query findMany field.

wrapResolve creates a new resolver and keeps the initial resolver unchanged.

useful!

Related questions

[Critical Bug] addRelation not working because wrong use of projection in mongoose hot 1
Github User Rank List