graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

$or operator does not work with resolver.addFilterArg()

Open nodkz opened this issue 7 years ago • 2 comments

@bakuzan wrote in #93:

I gave this a try and it works great when using field filters, but custom filter arguments, ones added with resolver.addFilterArg(), aren't being picked up when used inside an OR/AND

Yep, it does not work yet. I need to think how to integrate it to filter logic.

Internally resolver.addFilterArg() wraps underlying resolver and prepare resolveParams.rawQuery argument. And it cannot be pick up inside an OR/AND. For now, I don't know how to properly alive this logic. It quite complex task and cannot be solved quickly. Need to think.


As a workaround

  1. If you have a simple argument which needs to be added to filter (without custom processing of provided argument via addFilterArg). You may just add a new arg directly to Resolver and arg value from request will be picked up.
Resolver.getArgTC('filter').setField('myArg', { type: 'String', defaultValue: 20, description: 'My simple argument' })
  1. Or write your custom resolver where you describe args and resolve manually.

nodkz avatar Feb 23 '18 04:02 nodkz

Unfortunately my filter isn't simple. For now I guess I'll write a custom resolver!

bakuzan avatar Feb 23 '18 11:02 bakuzan

Yep, with something complex is better to write own resolver.

At the same time you will know how tediously do it by hands and how resolver generation by graphql-compose-mongoose makes live easier.

nodkz avatar Feb 23 '18 11:02 nodkz