Class DefaultBatchLoaderRegistry

java.lang.Object
org.springframework.graphql.execution.DefaultBatchLoaderRegistry
All Implemented Interfaces:
BatchLoaderRegistry, DataLoaderRegistrar

public class DefaultBatchLoaderRegistry extends Object implements BatchLoaderRegistry
Default implementation of BatchLoaderRegistry that stores batch loader registrations. Also, an implementation of DataLoaderRegistrar that registers the batch loaders as DataLoaders in DataLoaderRegistry.
Since:
1.0.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • DefaultBatchLoaderRegistry

      public DefaultBatchLoaderRegistry()
      Default constructor.
    • DefaultBatchLoaderRegistry

      public DefaultBatchLoaderRegistry(Supplier<org.dataloader.DataLoaderOptions> defaultOptionsSupplier)
      Constructor with a default DataLoaderOptions supplier to use as a starting point for batch loader registrations.
      Parameters:
      defaultOptionsSupplier - a supplier for default dataloader options
      Since:
      1.1.0
  • Method Details

    • forTypePair

      public <K, V> BatchLoaderRegistry.RegistrationSpec<K,V> forTypePair(Class<K> keyType, Class<V> valueType)
      Description copied from interface: BatchLoaderRegistry
      Begin the registration of a new batch load function by specifying the types of the keys and values that will be used as input and output.

      When this method is used, the name for the DataLoader is automatically set as defined in BatchLoaderRegistry.RegistrationSpec.withName(String), and likewise, @SchemaMapping handler methods can transparenly locate and inject a DataLoader<T> argument based on the generic type <T>.

      Specified by:
      forTypePair in interface BatchLoaderRegistry
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyType - the type of keys that will be used as input
      valueType - the type of value that will be returned as output
      Returns:
      a spec to complete the registration
    • forName

      public <K, V> BatchLoaderRegistry.RegistrationSpec<K,V> forName(String name)
      Description copied from interface: BatchLoaderRegistry
      Begin the registration of a new batch load function by specifying the name for the DataLoader.

      Note: when this method is used, the parameter name of a DataLoader<T> argument in a @SchemaMapping handler method needs to match the name given here.

      Specified by:
      forName in interface BatchLoaderRegistry
      Type Parameters:
      K - the type of keys that will be used as input
      V - the type of values that will be used as output
      Parameters:
      name - the name to use to register a DataLoader
      Returns:
      a spec to complete the registration
    • registerDataLoaders

      public void registerDataLoaders(org.dataloader.DataLoaderRegistry registry, GraphQLContext context)
      Description copied from interface: DataLoaderRegistrar
      Callback that provides access to the DataLoaderRegistry from the the ExecutionInput.
      Specified by:
      registerDataLoaders in interface DataLoaderRegistrar
      Parameters:
      registry - the registry to make registrations against
      context - the GraphQLContext from the ExecutionInput that registrars should set in the DataLoaderOptions so that batch loaders can access it via BatchLoaderEnvironment.