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 TypeMethodDescriptionvoid
addFormatterRegistrar
(FormatterRegistrar registrar) Add aFormatterRegistrar
to customize theConversionService
that assists in binding GraphQL arguments onto@Argument
annotated method parameters.void
protected HandlerMethod
createHandlerMethod
(Method originalMethod, Object handler, Class<?> handlerType) Scan beans in the ApplicationContext, detect and prepare a map of handler methods.protected ApplicationContext
protected HandlerMethodArgumentResolverComposite
Return the configured argument resolvers.protected FormattingConversionService
Return aDataFetcherExceptionResolver
that resolves exceptions with@GraphQlExceptionHandler
methods in@ControllerAdvice
classes declared in Spring configuration.Return theconfigured Executor
.protected abstract HandlerMethod
getHandlerMethod
(M mappingInfo) protected abstract M
getMappingInfo
(Method method, Object handler, Class<?> handlerType) protected abstract HandlerMethodArgumentResolverComposite
protected boolean
protected final ApplicationContext
void
setApplicationContext
(ApplicationContext applicationContext) void
setBlockingMethodPredicate
(Predicate<HandlerMethod> predicate) Configure a predicate to decide which controller methods are blocking.void
setExecutor
(Executor executor) Configure anExecutor
to use for asynchronous handling ofCallable
return values from controller methods, as well as forblocking controller methods
on Java 21+.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.protected boolean
shouldInvokeAsync
(HandlerMethod handlerMethod)
-
Field Details
-
springSecurityPresent
protected static final boolean springSecurityPresent -
logger
-
-
Constructor Details
-
AnnotatedControllerDetectionSupport
public AnnotatedControllerDetectionSupport()
-
-
Method Details
-
addFormatterRegistrar
Add aFormatterRegistrar
to customize theConversionService
that assists in binding GraphQL arguments onto@Argument
annotated method parameters.- Parameters:
registrar
- the formatter registrar
-
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
Return aDataFetcherExceptionResolver
that resolves exceptions with@GraphQlExceptionHandler
methods in@ControllerAdvice
classes declared in Spring configuration. This is useful primarily for exceptions from non-controllerDataFetcher
s 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
Configure anExecutor
to use for asynchronous handling ofCallable
return values from controller methods, as well as forblocking 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
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
ReactiveAdapterRegistry
as 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:
setApplicationContext
in interfaceApplicationContextAware
-
getApplicationContext
-
obtainApplicationContext
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in 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
-