From 0bb8f580081b2ae35b96ba8bf7dba74ad282f535 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 27 Sep 2021 09:18:07 +0100 Subject: [PATCH] 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. --- .../graphql/boot/GraphQlServiceAutoConfiguration.java | 2 +- .../graphql/execution/BatchLoaderRegistry.java | 4 ++-- .../graphql/execution/DataLoaderRegistrar.java | 3 ++- .../graphql/execution/DefaultBatchLoaderRegistry.java | 2 +- .../annotation/support/BatchMappingDetectionTests.java | 2 +- .../annotation/support/BatchMappingInvocationTests.java | 8 ++++---- .../support/DataLoaderArgumentResolverTests.java | 2 +- .../annotation/support/SchemaMappingInvocationTests.java | 2 +- .../graphql/execution/BatchLoadingTests.java | 2 +- .../execution/DefaultBatchLoaderRegistryTests.java | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java index ec436480..8365cdc5 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java @@ -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() { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java index 7187ab46..1f273153 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java @@ -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. * *

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 diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java index 7f0cb604..c9f896eb 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java @@ -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 diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java index aa155446..24c97cab 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java @@ -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> loaders = new ArrayList<>(); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java index c47b76ff..c20ce2a5 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java @@ -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 diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java index 2f9fd23c..8ad27b98 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java @@ -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(); } } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java index 4f91fd83..782e9f56 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java @@ -113,7 +113,7 @@ public class DataLoaderArgumentResolverTests { } private DataFetchingEnvironment initEnvironment(Consumer registryConsumer) { - DefaultBatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry(); + BatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry(); registryConsumer.accept(batchLoaderRegistry); DataLoaderRegistry registry = DataLoaderRegistry.newRegistry().build(); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java index d9a9d7bf..aedc8b38 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java @@ -245,7 +245,7 @@ public class SchemaMappingInvocationTests { } @Bean - public DefaultBatchLoaderRegistry batchLoaderRegistry() { + public BatchLoaderRegistry batchLoaderRegistry() { return new DefaultBatchLoaderRegistry(); } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java index 63439080..3e35be45 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java @@ -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)); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java index 8fa44667..91a1f429 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java @@ -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();