You can do this by using a middleware.
public class Query
{
[UseYourCustom]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Person> GetPersons() => //...
}
public class UseYourCustomAttribute : ObjectFieldDescriptorAttribute
{
public override void OnConfigure(
IDescriptorContext context,
IObjectFieldDescriptor descriptor,
MemberInfo member)
{
descriptor.Use(next => async context =>
{
// before the resolver pipeline
await next(context);
// after the resolver pipeline
if (context.Result is IQueryable<Person> query)
{
// all middleware are applied to `query`
}
});
}
}
In Version 12 you will also be able to do the following:
public class Query
{
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Person> GetPersons(IResolverContext context)
{
IQueryable<Person> person = //...
var allMiddlewareApplied = persons
.Sort(context)
.Filter(context)
.Project(context);
return allMiddlewareApplied
}
}