0

I use Quarkus 1.6.1.Final version with GraphQL implementation using SmallRye GraphQL. My aim is to define logic to check user permissions on every request (Query + Mutation) made to /graphql endpoint. So, I am trying to find something like jax-rs ContainerRequestFilter but for GraphQL. Do you have any ideas on how to do it? I've tried to define ContainerRequestFilter but it catches only RestEasy requests but not GraphQL ones.

fabasoad
  • 1,613
  • 18
  • 20

1 Answers1

0

I was looking into this myself. It seems like GraphQL directly registers a Vert.X routing call [1] rather than using Undertow(servlets) or RestEASY(jaxrs). This is so it can do stuff like partial results more easily from what I can tell.

You're going to want to look at intercepting Vert.X requests using the RouteFilter annotation. I've included the link below, but it works a lot like the ContainerRequestFilter from jax-rs. I've copied the sample code from the Quarkus help guide [2] to provide a quick example:

package org.acme.reactive.routes;

import io.vertx.ext.web.RoutingContext;

public class MyFilters {

    @RouteFilter(100) 
    void myFilter(RoutingContext rc) {
       // Put your logic here

       // continue the filtering of the request
       rc.next(); 
    }
}

1: https://github.com/quarkusio/quarkus/blob/master/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLRecorder.java

2: https://quarkus.io/guides/reactive-routes#intercepting-http-requests

  • I get this Error when I add some logic above the method. `io.quarkus.runtime.BlockingOperationNotAllowedException: You have attempted to perform a blocking operation on a IO thread. This is not allowed, as blocking the IO thread will cause major performance issues with your application. If you want to perform blocking EntityManager operations make sure you are doing it from a worker thread.` – Kyaw Thura Jan 17 '23 at 09:52
  • 1
    This is taking advantage of vert.x to hook into the request chain, so this part should be pretty safe. It sounds like you may have returned a non `Uni` or `Multi` in a later method though, either at the resource or in your Persistence entity repository, when you are using a reactive framework. – Martin Lowe Jan 18 '23 at 14:17