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

Filtering on an existing field with wrapResolve

Open
#222 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
706
Forks
98
PR merge metrics
No merged PRs in 30d

Description

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()](https://graphql-compose.github.io/docs/basics/what-is-resolver.html#via-resolverwrapresolve) 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".
```javascript
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.
```gql
query OrderSelect {
findMany(filter:{ orderStatus:"Placed"}) {
_id
user {
name
}
}
}
```

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.