Reference

ConfigureFiltering

Package Trax.Api.GraphQLNamespaces Trax.Api.GraphQL.Configuration.TraxGraphQLBuilder, Trax.Api.GraphQL.Configuration.TraxFilterBuilder, Trax.Api.GraphQL.FilteringSource TraxFilterBuilder/, ITraxFilterModule.cs, CaseInsensitiveStringFilterModule.cs, ListElementFilterBinding.cs

A TraxGraphQLBuilder method that layers opt-in operators onto HotChocolate's filter convention. Stock filtering is the default; ConfigureFiltering adds operators without changing the existing ones.

Signature

public TraxGraphQLBuilder ConfigureFiltering(
    Func<TraxFilterBuilder, TraxFilterBuilder> configure)

Parameters

ParameterTypeRequiredDescription
configureFunc<TraxFilterBuilder, TraxFilterBuilder>YesBuilds the set of filter operations to register. Each TraxFilterBuilder method adds one operation module.

TraxFilterBuilder methods

MethodDescription
AddCaseInsensitiveStringOperations()Adds icontains and ieq to every string filter input in the schema.

Returns

The TraxGraphQLBuilder, for chaining.

Behavior

ConfigureFiltering has an effect only when at least one [TraxQueryModel] entity has filtering on (the default). With operations registered and filtering off everywhere, Build() throws InvalidOperationException, since the operations would never be added. Calling it more than once, or calling the same method twice, registers each module once.

Each operator set is an ITraxFilterModule, whose Apply(IFilterConventionDescriptor) registers its operation ids, GraphQL names, input fields and expression handlers onto the convention.

Case-insensitive string operations

AddCaseInsensitiveStringOperations() adds two operators beside the stock contains and eq, which stay case-sensitive:

OperatorMeaningTranslates to
icontainsCase-insensitive substring matchlower(col) LIKE lower(@p)
ieqCase-insensitive equalitylower(col) = lower(@p)

Both fold with SQL lower(), not Postgres ILIKE, on every provider (Npgsql, SQL Server, SQLite, in-memory). A lower(col) expression index serves lower(col) = lower(@p) and lower(col) LIKE 'prefix%'. The operators are registered on the convention, so they appear on every string filter input, including ExposeAs-projected inputs and AddFilterType overrides.

Indexing

A lower() predicate reads the whole table without a matching expression index. Trax creates no index for it; the index that serves each operator:

OperatorIndex
icontainsgin (lower(col) gin_trgm_ops) (needs the pg_trgm extension)
ieqbtree (lower(col))

Scalar collection elements

Filter inputs for the elements of a scalar collection (Badge[], string[], List<int>) are restricted automatically, with no configuration. They expose eq, in, nin and the comparable operators, but not neq.

Inside a collection, neq lowers to Any(x => x != value) over a primitive collection, which no EF Core provider can translate, so the element position has an input type of its own:

input ListBadgeElementFilterInput {
  all: BadgeElementFilterInput
  none: BadgeElementFilterInput
  some: BadgeElementFilterInput
  any: Boolean
}
 
input BadgeElementFilterInput {
  eq: Badge
  in: [Badge!]
  nin: [Badge!]
}

all: { neq: X } is the only filter this removes. none: { eq: X } means the same thing and is still available. Scalar properties keep the full operation set including neq.

A collection of a nullable scalar (int?[], Badge?[]) shares the input of its underlying type, as it does in stock HotChocolate, so it has no neq either. eq: null matches an element that is null.

The restricted types are named {Scalar}ElementFilterInput rather than reusing HotChocolate's {Scalar}OperationFilterInput, so a restricted type never collides with a stock input of the same scalar that another part of the schema still uses.

The restriction applies to the auto-generated filter input, to ExposeAs-projected inputs, and to custom AddFilterType overrides, because it is bound by property type rather than per field. Navigation collections are untouched: their elements are entities, filtered by the entity's own filter input.

See Scalar collections for the operator table and the GIN index behaviour.

Example

builder.Services.AddTraxGraphQL(graphql => graphql
    .AddDbContext<GameDbContext>()
    .ConfigureFiltering(filter => filter.AddCaseInsensitiveStringOperations()));
query {
  discover {
    players(where: { displayName: { icontains: "wall" } }) {
      nodes { displayName }
    }
  }
}

See also