GraphQL Filters
See original GitHub issueHello there 👋
We are currently working with graphql.net. We miss some features that are proposed in this library and it seems like it would be a way better fit for our needs. Great work so far!
Anyway, for our graphql.net environment we developed a filter mechanism. We were highly inspired by the work of prisma. So that’s how it looks like in our api:
You can also filte for nested objects:
{
servers(where:{disks{freeSpace_lt:$num}}) {
principalName
}
}
In graphql.net we define custom graph types that, with some DI magic, resolve the right input types. So we define apart from ObjectType, MutationType and InputType also a filter type:
public class SystemFilterType<T> : FilterGraphType<System>
{
public SystemFilterType(IDependencyResolver resolver) : base(resolver)
{
FilterAndOrderBy(x => x.PrincipalName);
FilterAndOrderBy(x => x.NetbiosName);
In our resolver the resolvers we get the arguments from the query and then just apply the filters on a IEnumerable<T>.
return arguments.Filter(context, result);
So a Filter Graph Type is on one hand a input type ( so defines arguments like name, name_contains, name_in ) and on the other hand applies that filter on a IEnumerable. A filter polymorphically calls all nested filter.
That’s a pretty powerfull tool. We enable user with no programming skills to query our api through graphiql or playground and give them the opportunity to quickly get insights for their demand.
We lift the filter process from the front end to the back end and will even in a later version use IQueryable to directly filter on the database (which hopefully delivers even better performance)
What would be the proper approach to implement something like this on hotchocolate? Could we use directives? Would that mean we could reduce the boilerplate for filter (SystemFilterType)?
Issue Analytics
- State:
- Created 5 years ago
- Comments:50 (48 by maintainers)
Top GitHub Comments
@PascalSenn This one is now really coming together… we are hitting 90% code coverage now on filters.
I started a repository as a Playground for the Filters. Later this will be integrated into the main repository of hot chocolate. It easier to develop in a test project. It’s also great to verify the public api of the new schema builder.
This repo will ONLY be used as a PoC. https://github.com/PascalSenn/HotChocolate.Filters