graphql-platform
graphql-platform copied to clipboard
Filter extension method on IQueryable<T> not working
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
when i use Filter extension method, this method not working unless i expilictly use below code on before resolve middleware:
context.LocalContextData = context.LocalContextData.SetItem(QueryableFilterProvider.SkipFilteringKey
, false);
Steps to reproduce
public class QueryType : ObjectType<Query>
{
protected override void Configure(IObjectTypeDescriptor<Query> descriptor)
{
descriptor.Field(f => f.Companies)
.Authorize()
.UseOffsetPaging()
.UseProjection()
.UseFiltering()
.UseSorting()
.Resolve(async ctx =>
{
//load IQueryable<Company>
});
}
}`
2.
` public class CompanyType : ObjectType<Company>
{
protected override void Configure(IObjectTypeDescriptor<Company> descriptor)
{
descriptor.Field(f => f.Jobs)
.Use(next => async context =>
{
context.LocalContextData = context.LocalContextData.SetItem(QueryableFilterProvider.SkipFilteringKey
, false);
await next(context);
})
.UseOffsetPaging()
.UseProjection()
.UseFiltering()
.UseSorting()
.IsProjected(false)
.Resolve(async ctx =>
{
var skip = ctx.ArgumentValue<int>("skip");
var take = ctx.ArgumentValue<int>("take");
//load jobs from db
jobs = jobs.Filter(ctx).Sort(ctx);
if (skip > 0)
jobs = jobs.Skip(skip);
if (take > 0)
jobs = jobs.Take(take);
return jobs;
});
}
}
Relevant log output
No response
Additional Context?
No response
Product
Hot Chocolate
Version
12.9.0
Is you resolver hit?
hoe does the rexpression look like on return jobs?
yes my resolver hit
for your second question consider I have got 10 records from DB and after using Filter, I still got 10
I checked this Extension method, after the first time of filtering apply u set
context.LocalContextData.SetItem(QueryableFilterProvider.SkipFilteringKey , true);
see below link:
https://github.com/ChilliCream/hotchocolate/blob/ad668d74ef12062eb2210c0714743628c1672e26/src/HotChocolate/Data/src/Data/Filters/Expressions/QueryableFilterProvider.cs
and it makes sense you prevent filtering twice but why this field is already set to true when I never use filtering as u see in my code samples?
Is you resolver hit? hoe does the rexpression look like on
return jobs?
Possibly because it is "half projected" https://github.com/ChilliCream/hotchocolate/blob/8f0d403b1807b56215e188f2c90aec2bd5511bf2/src/HotChocolate/Data/src/Data/Projections/Expressions/Optimizers/QueryableFilterProjectionOptimizer.cs#L22-L30
i suppose it registers the middleware but does not respect IsProjected(false)
thanks for reporting
Can this one be closed?
I am not sure , i think its a bug but i solve it by defining a middleware and manually set property then filtering start working
On Mon, 8 Aug 2022, 21:18 Michael Staib, @.***> wrote:
Can this one be closed?
— Reply to this email directly, view it on GitHub https://github.com/ChilliCream/hotchocolate/issues/5126#issuecomment-1208364346, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJFFMF3LDNFL7BLAILLOUYDVYE26TANCNFSM5X7E6RGQ . You are receiving this because you authored the thread.Message ID: @.***>