Interface BatchLoaderRegistry

All Superinterfaces:
DataLoaderRegistrar
All Known Implementing Classes:
DefaultBatchLoaderRegistry

public interface BatchLoaderRegistry extends DataLoaderRegistrar
Registry for functions to batch load data values, given a set of keys.

At request time, each function is registered as a DataLoader in the DataLoaderRegistry and can be accessed in the data layer to load related entities while avoiding the N+1 select problem.

Since:
1.0.0
Author:
Rossen Stoyanchev
See Also:
  • Method Details

    • forTypePair

      <K, V> BatchLoaderRegistry.RegistrationSpec<K,V> forTypePair(Class<K> keyType, Class<V> valueType)
      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>.

      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

      <K, V> BatchLoaderRegistry.RegistrationSpec<K,V> forName(String name)
      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.

      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