spring-graphql icon indicating copy to clipboard operation
spring-graphql copied to clipboard

Is it possible to retrieve a HandlerMethod somewhere between interceptors.

Open nejcr opened this issue 3 years ago • 0 comments

What I would like to achieve is getting a HandlerMethod, annotated with @Controller before it executes. I can achieve this in SpringBoot by extending HandlerInterceptor and casting the handler to HandlerMethod. For example:

public class CustomHandlerInterceptor  implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (handler instanceof HandlerMethod handlerMethod){
           Method method = handlerMethod.getMethod();
           CustomAnnonation controller = AnnotationUtils.findAnnotation(handlerMethod.getMethod().getDeclaringClass(), CustomAnnonation.class);
           CustomAnnonation method = handlerMethod.getMethodAnnotation(CustomAnnonation.class);
            ...
        }
        return true;
    }
}

Is there an easy way do the same with graphql as well

nejcr avatar Aug 05 '22 12:08 nejcr