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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFormatterRegistrar(FormatterRegistrar registrar) Add aFormatterRegistrarto customize theConversionServicethat assists in binding GraphQL arguments onto@Argumentannotated method parameters.voidprotected HandlerMethodcreateHandlerMethod(Method originalMethod, Object handler, Class<?> handlerType) Scan beans in the ApplicationContext, detect and prepare a map of handler methods.protected ApplicationContextprotected HandlerMethodArgumentResolverCompositeReturn the configured argument resolvers.protected FormattingConversionServiceReturn aDataFetcherExceptionResolverthat resolves exceptions with@GraphQlExceptionHandlermethods in@ControllerAdviceclasses declared in Spring configuration.Return theconfigured Executor.protected abstract HandlerMethodgetHandlerMethod(M mappingInfo) protected abstract MgetMappingInfo(Method method, Object handler, Class<?> handlerType) protected abstract HandlerMethodArgumentResolverCompositeprotected booleanprotected final ApplicationContextvoidsetApplicationContext(ApplicationContext applicationContext) voidsetBlockingMethodPredicate(Predicate<HandlerMethod> predicate) Configure a predicate to decide which controller methods are blocking.voidsetExecutor(Executor executor) Configure anExecutorto use for asynchronous handling ofCallablereturn values from controller methods, as well as forblocking controller methodson Java 21+.voidsetFallBackOnDirectFieldAccess(boolean fallBackOnDirectFieldAccess) Whether binding GraphQL arguments onto@Argumentshould falls back to direct field access in case the target object does not use accessor methods.protected booleanshouldInvokeAsync(HandlerMethod handlerMethod)
-
Field Details
-
springSecurityPresent
protected static final boolean springSecurityPresent -
logger
-
-
Constructor Details
-
AnnotatedControllerDetectionSupport
public AnnotatedControllerDetectionSupport()
-
-
Method Details
-
addFormatterRegistrar
Add aFormatterRegistrarto customize theConversionServicethat assists in binding GraphQL arguments onto@Argumentannotated method parameters.- Parameters:
registrar- the formatter registrar
-
getConversionService
-
setFallBackOnDirectFieldAccess
public void setFallBackOnDirectFieldAccess(boolean fallBackOnDirectFieldAccess) Whether binding GraphQL arguments onto@Argumentshould 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
Return aDataFetcherExceptionResolverthat resolves exceptions with@GraphQlExceptionHandlermethods in@ControllerAdviceclasses declared in Spring configuration. This is useful primarily for exceptions from non-controllerDataFetchers since exceptions from@SchemaMappingcontroller 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
Configure anExecutorto use for asynchronous handling ofCallablereturn values from controller methods, as well as forblocking controller methodson Java 21+.By default, this is not set in which case controller methods with a
Callablereturn value are not supported, and blocking methods will be invoked synchronously.- Parameters:
executor- the executor to use
-
getExecutor
Return theconfigured Executor. -
setBlockingMethodPredicate
Configure a predicate to decide which controller methods are blocking. On Java 21+, such methods are invoked asynchronously through theconfigured Executor, unless the executor is a thread pool executor as determined viaprefersShortLivedTasks.By default, on Java 21+ the predicate returns false for controller method return types known to
ReactiveAdapterRegistryas well asKotlin suspending functions. On Java 20 and lower, the predicate returns false. You can configure the predicate for more control, or alternatively, returnCallable.- Parameters:
predicate- the predicate to use- Since:
- 1.3
-
getArgumentResolvers
Return the configured argument resolvers. -
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware
-
getApplicationContext
-
obtainApplicationContext
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
initArgumentResolvers
-
detectHandlerMethods
Scan beans in the ApplicationContext, detect and prepare a map of handler methods. -
getMappingInfo
-
createHandlerMethod
protected HandlerMethod createHandlerMethod(Method originalMethod, Object handler, Class<?> handlerType) -
getHandlerMethod
-
shouldInvokeAsync
-