Class AnnotatedControllerDetectionSupport<M>

java.lang.Object
org.springframework.graphql.data.method.annotation.support.AnnotatedControllerDetectionSupport<M>
Type Parameters:
M - the type of mapping info prepared from a controller method
All Implemented Interfaces:
Aware, InitializingBean, ApplicationContextAware
Direct Known Subclasses:
AnnotatedControllerConfigurer, FederationSchemaFactory

public abstract class AnnotatedControllerDetectionSupport<M> extends Object implements ApplicationContextAware, InitializingBean
Convenient base for classes that find annotated controller method with argument values resolved from a DataFetchingEnvironment.
Since:
1.3.0
Author:
Rossen Stoyanchev
  • Field Details

    • springSecurityPresent

      protected static final boolean springSecurityPresent
    • logger

      protected final Log logger
  • Constructor Details

    • AnnotatedControllerDetectionSupport

      public AnnotatedControllerDetectionSupport()
  • Method Details

    • addFormatterRegistrar

      public void addFormatterRegistrar(FormatterRegistrar registrar)
      Add a FormatterRegistrar to customize the ConversionService that assists in binding GraphQL arguments onto @Argument annotated method parameters.
      Parameters:
      registrar - the formatter registrar
    • getConversionService

      protected FormattingConversionService getConversionService()
    • setFallBackOnDirectFieldAccess

      public void setFallBackOnDirectFieldAccess(boolean fallBackOnDirectFieldAccess)
      Whether binding GraphQL arguments onto @Argument should falls back to direct field access in case the target object does not use accessor methods.
      Parameters:
      fallBackOnDirectFieldAccess - whether binding should fall back on direct field access
      Since:
      1.2.0
    • isFallBackOnDirectFieldAccess

      protected boolean isFallBackOnDirectFieldAccess()
    • getExceptionResolver

      public HandlerDataFetcherExceptionResolver getExceptionResolver()
      Return a DataFetcherExceptionResolver that resolves exceptions with @GraphQlExceptionHandler methods in @ControllerAdvice classes declared in Spring configuration. This is useful primarily for exceptions from non-controller DataFetchers since exceptions from @SchemaMapping controller methods are handled automatically at the point of invocation.
      Returns:
      a resolver instance that can be plugged into GraphQlSource.Builder
      Since:
      1.2.0
    • setExecutor

      public void setExecutor(Executor executor)
      Configure an Executor to use for asynchronous handling of Callable return values from controller methods, as well as for blocking controller methods on Java 21+.

      By default, this is not set in which case controller methods with a Callable return value are not supported, and blocking methods will be invoked synchronously.

      Parameters:
      executor - the executor to use
    • getExecutor

      @Nullable public Executor getExecutor()
    • setBlockingMethodPredicate

      public void setBlockingMethodPredicate(@Nullable Predicate<HandlerMethod> predicate)
      Configure a predicate to decide which controller methods are blocking. On Java 21+, such methods are invoked asynchronously through the configured Executor, unless the executor is a thread pool executor as determined via prefersShortLivedTasks.

      By default, on Java 21+ the predicate returns false for controller method return types known to ReactiveAdapterRegistry as well as Kotlin suspending functions. On Java 20 and lower, the predicate returns false. You can configure the predicate for more control, or alternatively, return Callable.

      Parameters:
      predicate - the predicate to use
      Since:
      1.3
    • getArgumentResolvers

      protected HandlerMethodArgumentResolverComposite getArgumentResolvers()
      Return the configured argument resolvers.
    • setApplicationContext

      public void setApplicationContext(ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface ApplicationContextAware
    • getApplicationContext

      @Nullable protected ApplicationContext getApplicationContext()
    • obtainApplicationContext

      protected final ApplicationContext obtainApplicationContext()
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • initArgumentResolvers

      protected abstract HandlerMethodArgumentResolverComposite initArgumentResolvers()
    • detectHandlerMethods

      protected Set<M> detectHandlerMethods()
      Scan beans in the ApplicationContext, detect and prepare a map of handler methods.
    • getMappingInfo

      @Nullable protected abstract M getMappingInfo(Method method, Object handler, Class<?> handlerType)
    • createHandlerMethod

      protected HandlerMethod createHandlerMethod(Method originalMethod, Object handler, Class<?> handlerType)
    • getHandlerMethod

      protected abstract HandlerMethod getHandlerMethod(M mappingInfo)
    • shouldInvokeAsync

      protected boolean shouldInvokeAsync(HandlerMethod handlerMethod)