Skip to content

Commit 935d37b

Browse files
committed
Polish "Reuse BatchLoaderRegistry in GraphQlService"
See gh-29929
1 parent 043e5ff commit 935d37b

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public class GraphQlAutoConfiguration {
6464

6565
private static final Log logger = LogFactory.getLog(GraphQlAutoConfiguration.class);
6666

67-
private final BatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
68-
6967
@Bean
7068
@ConditionalOnMissingBean
7169
public GraphQlSource graphQlSource(ResourcePatternResolver resourcePatternResolver, GraphQlProperties properties,
@@ -118,7 +116,7 @@ private List<Resource> resolveSchemaResources(ResourcePatternResolver resolver,
118116
@Bean
119117
@ConditionalOnMissingBean
120118
public BatchLoaderRegistry batchLoaderRegistry() {
121-
return this.batchLoaderRegistry;
119+
return new DefaultBatchLoaderRegistry();
122120
}
123121

124122
@Bean

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer;
3939
import org.springframework.graphql.execution.BatchLoaderRegistry;
4040
import org.springframework.graphql.execution.DataFetcherExceptionResolver;
41+
import org.springframework.graphql.execution.DataLoaderRegistrar;
4142
import org.springframework.graphql.execution.GraphQlSource;
4243
import org.springframework.graphql.execution.MissingSchemaException;
4344
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
@@ -170,11 +171,18 @@ void shouldDisableFieldIntrospection() {
170171
}
171172

172173
@Test
173-
void shouldConfigCustomBatchLoaderRegistry() {
174-
this.contextRunner.withUserConfiguration(CustomBatchLoaderRegistryConfiguration.class).run((context) -> {
175-
assertThat(context).getBeanNames(BatchLoaderRegistry.class).containsOnly("customBatchLoaderRegistry");
176-
assertThat(context).hasSingleBean(BatchLoaderRegistry.class);
177-
});
174+
void shouldConfigureCustomBatchLoaderRegistry() {
175+
this.contextRunner
176+
.withBean("customBatchLoaderRegistry", BatchLoaderRegistry.class, () -> mock(BatchLoaderRegistry.class))
177+
.run((context) -> {
178+
assertThat(context).hasSingleBean(BatchLoaderRegistry.class);
179+
assertThat(context.getBean("customBatchLoaderRegistry"))
180+
.isSameAs(context.getBean(BatchLoaderRegistry.class));
181+
assertThat(context.getBean(GraphQlService.class))
182+
.extracting("dataLoaderRegistrars",
183+
InstanceOfAssertFactories.list(DataLoaderRegistrar.class))
184+
.containsOnly(context.getBean(BatchLoaderRegistry.class));
185+
});
178186
}
179187

180188
@Configuration(proxyBeanMethods = false)
@@ -261,14 +269,4 @@ public void customize(GraphQlSource.Builder builder) {
261269

262270
}
263271

264-
@Configuration(proxyBeanMethods = false)
265-
static class CustomBatchLoaderRegistryConfiguration {
266-
267-
@Bean
268-
BatchLoaderRegistry customBatchLoaderRegistry() {
269-
return mock(BatchLoaderRegistry.class);
270-
}
271-
272-
}
273-
274272
}

0 commit comments

Comments
 (0)