Skip to content

Commit 043e5ff

Browse files
dugenkui03snicoll
authored andcommitted
Reuse BatchLoaderRegistry in GraphQlService
See gh-29929
1 parent 8ee9681 commit 043e5ff

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public BatchLoaderRegistry batchLoaderRegistry() {
123123

124124
@Bean
125125
@ConditionalOnMissingBean
126-
public GraphQlService graphQlService(GraphQlSource graphQlSource) {
126+
public GraphQlService graphQlService(GraphQlSource graphQlSource, BatchLoaderRegistry batchLoaderRegistry) {
127127
ExecutionGraphQlService service = new ExecutionGraphQlService(graphQlSource);
128-
service.addDataLoaderRegistrar(this.batchLoaderRegistry);
128+
service.addDataLoaderRegistrar(batchLoaderRegistry);
129129
return service;
130130
}
131131

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ void shouldDisableFieldIntrospection() {
169169
});
170170
}
171171

172+
@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+
});
178+
}
179+
172180
@Configuration(proxyBeanMethods = false)
173181
static class CustomGraphQlBuilderConfiguration {
174182

@@ -253,4 +261,14 @@ public void customize(GraphQlSource.Builder builder) {
253261

254262
}
255263

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

0 commit comments

Comments
 (0)