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:
Rossen Stoyanchev
2021-09-27 09:18:07 +01:00
parent 56ca50e6f3
commit 0bb8f58008
10 changed files with 15 additions and 14 deletions

View File

@@ -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() {

View File

@@ -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

View File

@@ -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

View File

@@ -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<>();

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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();

View File

@@ -245,7 +245,7 @@ public class SchemaMappingInvocationTests {
}
@Bean
public DefaultBatchLoaderRegistry batchLoaderRegistry() {
public BatchLoaderRegistry batchLoaderRegistry() {
return new DefaultBatchLoaderRegistry();
}

View File

@@ -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));

View File

@@ -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();