Created
May 15, 2023 14:32
-
-
Save glen-84/3fe64dc0e785517f859b525af61218c2 to your computer and use it in GitHub Desktop.
HC custom filter WIP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EntityIdOperationFilterInputType : FilterInputType | |
{ | |
protected override void Configure(IFilterInputTypeDescriptor descriptor) | |
{ | |
descriptor | |
.Operation(DefaultFilterOperations.Equals) | |
.Type<LongType>(); | |
} | |
} | |
public abstract class QueryableEntityIdOperationHandler : QueryableOperationHandlerBase | |
{ | |
protected QueryableEntityIdOperationHandler(InputParser inputParser) : base(inputParser) { } | |
protected abstract int Operation { get; } | |
public override bool CanHandle( | |
ITypeCompletionContext context, | |
IFilterInputTypeDefinition typeDefinition, | |
IFilterFieldDefinition fieldDefinition) | |
{ | |
return context.Type is EntityIdOperationFilterInputType && | |
fieldDefinition is FilterOperationFieldDefinition operationField && | |
operationField.Id == this.Operation; | |
} | |
} | |
public class QueryableEntityIdEqualsHandler : QueryableEntityIdOperationHandler | |
{ | |
public QueryableEntityIdEqualsHandler(InputParser inputParser) : base(inputParser) { } | |
protected override int Operation => DefaultFilterOperations.Equals; | |
public override Expression HandleOperation( | |
QueryableFilterContext context, | |
IFilterOperationField field, | |
IValueNode value, | |
object? parsedValue) | |
{ | |
Console.WriteLine("Not getting here yet, so not implemented."); | |
var property = context.GetInstance(); | |
return FilterExpressionBuilder.Equals(property, parsedValue); | |
} | |
} | |
// Usage. | |
public class ArticleFilterType : FilterInputType<Article> | |
{ | |
protected override void Configure(IFilterInputTypeDescriptor<Article> descriptor) | |
{ | |
descriptor.BindFieldsExplicitly(); | |
descriptor.Field("entityId").Type<EntityIdOperationFilterInputType>(); | |
} | |
} | |
// Registration. | |
.AddConvention<IFilterConvention>( | |
new FilterConventionExtension( | |
x => x.AddProviderExtension( | |
new QueryableFilterProviderExtension( | |
y => y.AddFieldHandler<QueryableEntityIdEqualsHandler>())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment