graphql-compose / graphql-compose/graphql-compose-mongoose

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

Open
#95 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
706
Forks
98
PR merge metrics
No merged PRs in 30d

Description

@bakuzan wrote in [#93](https://github.com/graphql-compose/graphql-compose-mongoose/issues/93#issuecomment-367636883):
> 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](https://github.com/graphql-compose/graphql-compose/blob/e028c26a13d3ca13d21f621a5789f145aa937ffd/src/Resolver.js#L587-L600) 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.

```js
Resolver.getArgTC('filter').setField('myArg', { type: 'String', defaultValue: 20, description: 'My simple argument' })
```

2. Or write your custom resolver where you describe `args` and `resolve` manually.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.