BatchLoaderRegistry extends DataLoaderRegistrar
Given that BatchLoaderRegistry is declared as a bean and injected into ExecutionGraphQlService as a DataLoaderRegistrar, it makes sense to have be a DataLoaderRegistrar vs declaring the bean as the implementation type. A BatchLoaderRegistry is supposed to result in DataLoader registrations so this makes sense in any case.
This commit is contained in:
@@ -43,7 +43,7 @@ import org.springframework.graphql.execution.GraphQlSource;
|
||||
@AutoConfigureAfter(GraphQlAutoConfiguration.class)
|
||||
public class GraphQlServiceAutoConfiguration {
|
||||
|
||||
private final DefaultBatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
private final BatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
|
||||
@Bean
|
||||
public BatchLoaderRegistry batchLoaderRegistry() {
|
||||
|
||||
@@ -27,7 +27,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Registry of functions that batch load data values given a set of keys.
|
||||
* Registry for functions to batch load data values, given a set of keys.
|
||||
*
|
||||
* <p>At request time, each function is registered as a
|
||||
* {@link org.dataloader.DataLoader} in the {@link org.dataloader.DataLoaderRegistry}
|
||||
@@ -41,7 +41,7 @@ import reactor.core.publisher.Mono;
|
||||
* @see org.dataloader.MappedBatchLoader
|
||||
* @see org.dataloader.DataLoader
|
||||
*/
|
||||
public interface BatchLoaderRegistry {
|
||||
public interface BatchLoaderRegistry extends DataLoaderRegistrar {
|
||||
|
||||
/**
|
||||
* Begin the registration of a new batch load function by specifying the
|
||||
|
||||
@@ -18,7 +18,8 @@ package org.springframework.graphql.execution;
|
||||
import org.dataloader.DataLoaderRegistry;
|
||||
|
||||
/**
|
||||
* Contract for access to the {@link DataLoaderRegistry} at request time.
|
||||
* Contract for callback access to the {@link DataLoaderRegistry} as it is
|
||||
* initialized for each request.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry, DataLoaderRegistrar {
|
||||
public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry {
|
||||
|
||||
private final List<ReactorBatchLoader<?,?>> loaders = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
@SuppressWarnings({"rawtypes", "unused"})
|
||||
public class BatchMappingDetectionTests {
|
||||
|
||||
private final DefaultBatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
private final BatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.RequestInput;
|
||||
import org.springframework.graphql.data.method.annotation.BatchMapping;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.execution.DataLoaderRegistrar;
|
||||
import org.springframework.graphql.execution.BatchLoaderRegistry;
|
||||
import org.springframework.graphql.execution.DefaultBatchLoaderRegistry;
|
||||
import org.springframework.graphql.execution.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
@@ -268,9 +268,9 @@ public class BatchMappingInvocationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GraphQlService graphQlService(GraphQlSource source, DataLoaderRegistrar registrar) {
|
||||
public GraphQlService graphQlService(GraphQlSource source, BatchLoaderRegistry registry) {
|
||||
ExecutionGraphQlService service = new ExecutionGraphQlService(source);
|
||||
service.addDataLoaderRegistrar(registrar);
|
||||
service.addDataLoaderRegistrar(registry);
|
||||
return service;
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ public class BatchMappingInvocationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultBatchLoaderRegistry batchLoaderRegistry() {
|
||||
public BatchLoaderRegistry batchLoaderRegistry() {
|
||||
return new DefaultBatchLoaderRegistry();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class DataLoaderArgumentResolverTests {
|
||||
}
|
||||
|
||||
private DataFetchingEnvironment initEnvironment(Consumer<BatchLoaderRegistry> registryConsumer) {
|
||||
DefaultBatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
BatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
registryConsumer.accept(batchLoaderRegistry);
|
||||
|
||||
DataLoaderRegistry registry = DataLoaderRegistry.newRegistry().build();
|
||||
|
||||
@@ -245,7 +245,7 @@ public class SchemaMappingInvocationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultBatchLoaderRegistry batchLoaderRegistry() {
|
||||
public BatchLoaderRegistry batchLoaderRegistry() {
|
||||
return new DefaultBatchLoaderRegistry();
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class BatchLoadingTests {
|
||||
}));
|
||||
});
|
||||
|
||||
DefaultBatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
|
||||
BatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
|
||||
registry.forTypePair(Long.class, Author.class)
|
||||
.registerBatchLoader((ids, env) -> Flux.fromIterable(ids).map(BookSource::getAuthor));
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
*/
|
||||
public class DefaultBatchLoaderRegistryTests {
|
||||
|
||||
private final DefaultBatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
private final BatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
|
||||
private final DataLoaderRegistry dataLoaderRegistry = DataLoaderRegistry.newRegistry().build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user