Skip to content

Can i intercept the iqueryable ? #4039

Answered by PascalSenn
lucas-garrido asked this question in Q&A
Discussion options

You must be logged in to vote

You can use a middleware to intercept the queries

public class Query 
{
   [UseYourMiddleware]
   [UseFiltering]
   public IQueryable<Foo> GetFoos(...) => ...
}
    public class UseYourMiddlewareAttribute : ObjectFieldDescriptorAttribute
    {
        public override void OnConfigure(
            IDescriptorContext context,
            IObjectFieldDescriptor descriptor,
            MemberInfo member)
        {
            descriptor.Use(next => async context =>
            {
                await next(context);

                if (context.Result is IQueryable<Foo> q)
                {
                    // intercept the IQueryable in q
                }

            });
        }
    }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lucas-garrido
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants