You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, everone!!!
I've implemented the @PascalSenn solutution "Filtering.Demo" but in one specific case i'm facing an error like this: "message": "Object reference not set to an instance of an object.", "stackTrace": " at lambda_method1333(Closure , IAerodromoDTOModel ) at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at System.Linq.Enumerable.EnumerablePartition1.MoveNext() at HotChocolate.Types.Pagination.QueryableCursorPagination1.<>c__DisplayClass6_0.b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at HotChocolate.Types.Pagination.QueryableCursorPagination1.ExecuteAsync(IQueryable1 query, Int32 offset, CancellationToken cancellationToken)
at HotChocolate.Types.Pagination.CursorPaginationAlgorithm2.ApplyPaginationAsync(TQuery query, CursorPagingArguments arguments, Nullable1 totalCount, CancellationToken cancellationToken)
at HotChocolate.Types.Pagination.QueryableCursorPagingHandler1.ResolveAsync(IResolverContext context, IQueryable1 source, CursorPagingArguments arguments, CancellationToken cancellationToken)
at HotChocolate.Types.Pagination.CursorPagingHandler.HotChocolate.Types.Pagination.IPagingHandler.SliceAsync(IResolverContext context, Object source)
at HotChocolate.Types.Pagination.PagingMiddleware.InvokeAsync(IMiddlewareContext context)
at HotChocolate.Utilities.MiddlewareCompiler1.ExpressionHelper.AwaitTaskHelper(Task task) at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken) at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
My FilterConvention: public class CustomFilteringConvention : FilterConvention { protected override void Configure(IFilterConventionDescriptor descriptor) { descriptor.AddDefaults(); descriptor.Operation(DefaultFilterOperations.Contains).Name("contains"); descriptor.AddProviderExtension( new QueryableFilterProviderExtension( x => x.AddFieldHandler<QueryableStringInvariantContainsHandler>())); descriptor.Operation(DefaultFilterOperations.Equals).Name("equals"); descriptor.AddProviderExtension( new QueryableFilterProviderExtension( x => x.AddFieldHandler<QueryableStringInvariantEqualsHandler>())); } }
And my QueryableStringInvariantContainsHandler is: public class QueryableStringInvariantContainsHandler : QueryableStringOperationHandler { private static readonly MethodInfo _toLower = typeof(string) .GetMethods() .Single( x => x.Name == nameof(string.ToLower) && x.GetParameters().Length == 0); public QueryableStringInvariantContainsHandler(InputParser inputParser) : base(inputParser) { } protected override int Operation => DefaultFilterOperations.Contains; public override Expression HandleOperation( QueryableFilterContext context, IFilterOperationField field, IValueNode value, object parsedValue) { Expression property = context.GetInstance(); if (parsedValue is string str) { MethodInfo contains = typeof(string).GetMethods().Where(x => x.Name == "Contains").First(); var result = Expression.Call( Expression.Call(property, _toLower), contains, Expression.Constant(str.ToLower())); return result; } throw new InvalidOperationException(); } }
Does anyone know why this error is hapening? Is it because of null values in returned from the API?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, everone!!!
I've implemented the @PascalSenn solutution "Filtering.Demo" but in one specific case i'm facing an error like this:
"message": "Object reference not set to an instance of an object.", "stackTrace": " at lambda_method1333(Closure , IAerodromoDTOModel ) at System.Linq.Enumerable.WhereEnumerableIterator
1.MoveNext()at System.Linq.Enumerable.EnumerablePartition
1.MoveNext() at HotChocolate.Types.Pagination.QueryableCursorPagination
1.<>c__DisplayClass6_0.b__0()at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__277_0(Object obj)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at HotChocolate.Types.Pagination.QueryableCursorPagination
1.ExecuteAsync(IQueryable
1 query, Int32 offset, CancellationToken cancellationToken)at HotChocolate.Types.Pagination.CursorPaginationAlgorithm
2.ApplyPaginationAsync(TQuery query, CursorPagingArguments arguments, Nullable
1 totalCount, CancellationToken cancellationToken)at HotChocolate.Types.Pagination.QueryableCursorPagingHandler
1.ResolveAsync(IResolverContext context, IQueryable
1 source, CursorPagingArguments arguments, CancellationToken cancellationToken)at HotChocolate.Types.Pagination.CursorPagingHandler.HotChocolate.Types.Pagination.IPagingHandler.SliceAsync(IResolverContext context, Object source)
at HotChocolate.Types.Pagination.PagingMiddleware.InvokeAsync(IMiddlewareContext context)
at HotChocolate.Utilities.MiddlewareCompiler
1.ExpressionHelper.AwaitTaskHelper(Task task) at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken) at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
My FilterConvention:
public class CustomFilteringConvention : FilterConvention { protected override void Configure(IFilterConventionDescriptor descriptor) { descriptor.AddDefaults(); descriptor.Operation(DefaultFilterOperations.Contains).Name("contains"); descriptor.AddProviderExtension( new QueryableFilterProviderExtension( x => x.AddFieldHandler<QueryableStringInvariantContainsHandler>())); descriptor.Operation(DefaultFilterOperations.Equals).Name("equals"); descriptor.AddProviderExtension( new QueryableFilterProviderExtension( x => x.AddFieldHandler<QueryableStringInvariantEqualsHandler>())); } }
And my QueryableStringInvariantContainsHandler is:
public class QueryableStringInvariantContainsHandler : QueryableStringOperationHandler { private static readonly MethodInfo _toLower = typeof(string) .GetMethods() .Single( x => x.Name == nameof(string.ToLower) && x.GetParameters().Length == 0); public QueryableStringInvariantContainsHandler(InputParser inputParser) : base(inputParser) { } protected override int Operation => DefaultFilterOperations.Contains; public override Expression HandleOperation( QueryableFilterContext context, IFilterOperationField field, IValueNode value, object parsedValue) { Expression property = context.GetInstance(); if (parsedValue is string str) { MethodInfo contains = typeof(string).GetMethods().Where(x => x.Name == "Contains").First(); var result = Expression.Call( Expression.Call(property, _toLower), contains, Expression.Constant(str.ToLower())); return result; } throw new InvalidOperationException(); } }
Does anyone know why this error is hapening? Is it because of null values in returned from the API?
Tks very much!!!!
Beta Was this translation helpful? Give feedback.
All reactions