question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello 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: image image

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:closed
  • Created 5 years ago
  • Comments:50 (48 by maintainers)

github_iconTop GitHub Comments

2reactions
michaelstaibcommented, Jun 25, 2019

@PascalSenn This one is now really coming together… we are hitting 90% code coverage now on filters.

2reactions
PascalSenncommented, Apr 30, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL Search and Filter – How to ...
Searching and filtering is a standard part of any GraphQL API. In this article, we'll learn how to add filtering capabilities to your...
Read more >
Search and Filtering - GraphQL
You can filter query results to find objects with one or more specified values using the in keyword. This keyword can find matches...
Read more >
Filtering, Pagination & Sorting
The goal is to allow clients to constrain the list of Link elements returned by the feed query by providing filtering and pagination...
Read more >
How to filter list objects by field value in GraphQL?
As it turns out, there is no built-in filter function defined on lists/arrays! GraphQL (query language) is basically about selecting fields ...
Read more >
Understanding GraphQL Filters
In this article, we will go over the fundamentals of searching and filtering queries for GraphQL.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found