Class AnnotatedControllerConfigurer

java.lang.Object
org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer
All Implemented Interfaces:
Aware, InitializingBean, ApplicationContextAware, RuntimeWiringConfigurer

public class AnnotatedControllerConfigurer extends Object implements ApplicationContextAware, InitializingBean, RuntimeWiringConfigurer
RuntimeWiringConfigurer that finds @SchemaMapping annotated handler methods in @Controller classes declared in Spring configuration, and registers them as DataFetchers.

In addition to initializing a RuntimeWiring.Builder, this class, also provides an option to configure data fetchers on a GraphQLCodeRegistry.Builder.

This class detects the following strategies in Spring configuration, expecting to find a single, unique bean of that type:

Since:
1.0.0
Author:
Rossen Stoyanchev, Brian Clozel
  • Constructor Details

    • AnnotatedControllerConfigurer

      public AnnotatedControllerConfigurer()
  • 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
    • 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 we should fall back on direct field access
      Since:
      1.2.0
    • addCustomArgumentResolver

      public void addCustomArgumentResolver(HandlerMethodArgumentResolver resolver)
      Add a HandlerMethodArgumentResolver for custom controller method arguments. Such custom resolvers are ordered after built-in resolvers except for SourceMethodArgumentResolver, which is always last.
      Parameters:
      resolver - the resolver to add.
      Since:
      1.2.0
    • getExceptionResolver

      public DataFetcherExceptionResolver 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
    • setDataBinderInitializer

      @Deprecated(since="1.1.0", forRemoval=true) public void setDataBinderInitializer(@Nullable Consumer<DataBinder> consumer)
      Deprecated, for removal: This API element is subject to removal in a future version.
      this property is deprecated, ignored, and should not be necessary as a DataBinder is no longer used to bind arguments
      Configure an initializer that configures the DataBinder before the binding process.
      Parameters:
      consumer - the data binder initializer
      Since:
      1.0.1
    • setExecutor

      public void setExecutor(Executor executor)
      Configure an Executor to use for asynchronous handling of Callable return values from controller methods.

      By default, this is not set in which case controller methods with a Callable return value cannot be registered.

      Parameters:
      executor - the executor to use
    • setApplicationContext

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

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

      protected final ApplicationContext obtainApplicationContext()
    • configure

      public void configure(RuntimeWiring.Builder runtimeWiringBuilder)
      Description copied from interface: RuntimeWiringConfigurer
      Apply changes to the RuntimeWiring.Builder such as registering DataFetchers, custom scalar types, and more.
      Specified by:
      configure in interface RuntimeWiringConfigurer
      Parameters:
      runtimeWiringBuilder - the builder to configure
    • configure

      public void configure(GraphQLCodeRegistry.Builder codeRegistryBuilder)
      Alternative to configure(RuntimeWiring.Builder) that registers data fetchers in a GraphQLCodeRegistry.Builder. This could be used with programmatic creation of GraphQLSchema.
      Parameters:
      codeRegistryBuilder - the code registry to be processed