titaniumit.graphql.filtering.extentions 0.1.35

There is a newer version of this package available.
See the version list below for details.
dotnet add package titaniumit.graphql.filtering.extentions --version 0.1.35                
NuGet\Install-Package titaniumit.graphql.filtering.extentions -Version 0.1.35                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="titaniumit.graphql.filtering.extentions" Version="0.1.35" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add titaniumit.graphql.filtering.extentions --version 0.1.35                
#r "nuget: titaniumit.graphql.filtering.extentions, 0.1.35"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install titaniumit.graphql.filtering.extentions as a Cake Addin
#addin nuget:?package=titaniumit.graphql.filtering.extentions&version=0.1.35

// Install titaniumit.graphql.filtering.extentions as a Cake Tool
#tool nuget:?package=titaniumit.graphql.filtering.extentions&version=0.1.35                

Introduction

publish Graphql Filters coverage testoutcome

An extention on GraphQL.net to add filtering on clr types

Example graphql filters

Filters are based on a clrType/interface

Using AddFilter as argument. The graphql type for the filters are automaticly added

  • FilterGraphType<typename>
  • And/Or/Not types
  • Condition type
  • Any

Simple filters

condition:{
    fieldName:Id
    operator: equal
    value: 1
}
condition:{
    fieldName: DateField
    operator: equal
    value: "10-10-2023" 
}

Operators on scalars

supported operators on scalartypes

  • equal
  • greater
  • greaterOrEqual
  • less
  • lessOrEqual
  • notEqual

Booleans

supported

  • and
  • or
  • not

Collections

to filter collection members the any field on the filtertype is present that contains per colletion field a member.

Resolvers

Using filters in a Resolver.

Field<DiverGraphType>("Diver")
    .AddFilter("filter").FilterType<Diver>()
    .Resolve(ctx =>
    {
        var filter = ctx.GetFilterExpression<Diver>("filter");
        var datasource = ctx.RequestServices!.GetRequiredService<IDivers>();
        if (filter != null)
            return datasource.Divers.SingleOrDefault(filter.Compile());
        else
            return null;
    });

When getting a filter on parent for a child

 Field<ListGraphType<DiveGraphType>>("Dives")
            .Resolve( ctx => {
              var datasource = ctx.RequestServices!.GetRequiredService<IDives>();
              var expression = ctx.GetSubFilterExpression<Dive>();
              if( expression != null){
                return datasource.Dives.Where( d => d.Diver?.Id == ctx.Source.Id).Where(expression.Compile());
              } else{
                return datasource.Dives.Where( d => d.Diver?.Id == ctx.Source.Id);
              }
            });

query examples

query GetDiverFixedFilter {
    diver(filter:{
        condition:{
            fieldName:id
            operator: equal
            value: 1
        }
    }){
        name
        email
        id
    }
}

query GetDiverByEmail {
    diver(filter:{
        condition:{
            fieldName: email
            operator: equal
            value: "john@divers.down"
        }
    }){
        name
        email
        id
    }
}

query GetDiversWithCoarseFilters {
    divers(filter:{
        any:{
            courses:{
                condition:{
                    fieldName: name
                    operator:equal
                    value: "OpenWater"
                }
            }
        }
    }){
        name
        email
        id
    }
}

query GetDiverFilterById($id: ValueScalar!) {
    diver(filter:{
        condition:{
            fieldName:id
            operator: equal
            value: $id
        }
    }){
        id
    }
}

query GetDiversWithDivesAt($location:ValueScalar!){
    divers(filter: {
        any:{
            dives:{
                condition:{
                    fieldName:location
                    operator:equal
                    value: $location
                }
            }
        }
    }){
        name
        dives{
            start
            end
        }
    }
}

example project

Setup

Todo

  • documentation
  • more test cases
  • custom filter functions
  • configuration options like, casing.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.39 92 6/20/2024
0.1.38 84 5/23/2024
0.1.37 77 5/23/2024
0.1.36 79 5/23/2024
0.1.35 77 5/23/2024
0.1.34 101 3/28/2024
0.1.33 90 1/25/2024
0.1.32 82 1/25/2024
0.1.31 81 1/19/2024
0.1.30 86 1/10/2024
0.1.29 99 1/3/2024
0.1.28 97 1/3/2024
0.1.27 88 1/3/2024