Class DefaultBatchLoaderRegistry
java.lang.Object
org.springframework.graphql.execution.DefaultBatchLoaderRegistry
- All Implemented Interfaces:
BatchLoaderRegistry
,DataLoaderRegistrar
Default implementation of
BatchLoaderRegistry
that stores batch loader
registrations. Also, an implementation of DataLoaderRegistrar
that
registers the batch loaders as DataLoader
s in DataLoaderRegistry
.- Since:
- 1.0.0
- Author:
- Rossen Stoyanchev
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.graphql.execution.BatchLoaderRegistry
BatchLoaderRegistry.RegistrationSpec<K,
V> -
Constructor Summary
ConstructorDescriptionDefault constructor.DefaultBatchLoaderRegistry
(Supplier<org.dataloader.DataLoaderOptions> defaultOptionsSupplier) Constructor with a defaultDataLoaderOptions
supplier to use as a starting point for batch loader registrations. -
Method Summary
Modifier and TypeMethodDescription<K,
V> BatchLoaderRegistry.RegistrationSpec<K, V> Begin the registration of a new batch load function by specifying the name for theDataLoader
.<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.boolean
Whether the registrar has anyDataLoader
registrations to make.void
registerDataLoaders
(org.dataloader.DataLoaderRegistry registry, GraphQLContext context) Callback that provides access to theDataLoaderRegistry
from the theExecutionInput
.
-
Constructor Details
-
DefaultBatchLoaderRegistry
public DefaultBatchLoaderRegistry()Default constructor. -
DefaultBatchLoaderRegistry
public DefaultBatchLoaderRegistry(Supplier<org.dataloader.DataLoaderOptions> defaultOptionsSupplier) Constructor with a defaultDataLoaderOptions
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 inBatchLoaderRegistry.RegistrationSpec.withName(String)
, and likewise,@SchemaMapping
handler methods can transparenly locate and inject aDataLoader<T>
argument based on the generic type<T>
.- Specified by:
forTypePair
in interfaceBatchLoaderRegistry
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
keyType
- the type of keys that will be used as inputvalueType
- the type of value that will be returned as output- Returns:
- a spec to complete the registration
-
forName
Description copied from interface:BatchLoaderRegistry
Begin the registration of a new batch load function by specifying the name for theDataLoader
.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 interfaceBatchLoaderRegistry
- Type Parameters:
K
- the type of keys that will be used as inputV
- the type of values that will be used as output- Parameters:
name
- the name to use to register aDataLoader
- Returns:
- a spec to complete the registration
-
hasRegistrations
public boolean hasRegistrations()Description copied from interface:DataLoaderRegistrar
Whether the registrar has anyDataLoader
registrations to make.- Specified by:
hasRegistrations
in interfaceDataLoaderRegistrar
-
registerDataLoaders
Description copied from interface:DataLoaderRegistrar
Callback that provides access to theDataLoaderRegistry
from the theExecutionInput
.- Specified by:
registerDataLoaders
in interfaceDataLoaderRegistrar
- Parameters:
registry
- the registry to make registrations againstcontext
- the GraphQLContext from the ExecutionInput that registrars should set in theDataLoaderOptions
so that batch loaders can access it viaBatchLoaderEnvironment
.
-