Polish "Reuse BatchLoaderRegistry in GraphQlService"
See gh-29929
This commit is contained in:
parent
043e5ff0f5
commit
935d37b2ca
|
@ -64,8 +64,6 @@ public class GraphQlAutoConfiguration {
|
|||
|
||||
private static final Log logger = LogFactory.getLog(GraphQlAutoConfiguration.class);
|
||||
|
||||
private final BatchLoaderRegistry batchLoaderRegistry = new DefaultBatchLoaderRegistry();
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GraphQlSource graphQlSource(ResourcePatternResolver resourcePatternResolver, GraphQlProperties properties,
|
||||
|
@ -118,7 +116,7 @@ public class GraphQlAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public BatchLoaderRegistry batchLoaderRegistry() {
|
||||
return this.batchLoaderRegistry;
|
||||
return new DefaultBatchLoaderRegistry();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.springframework.graphql.GraphQlService;
|
|||
import org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer;
|
||||
import org.springframework.graphql.execution.BatchLoaderRegistry;
|
||||
import org.springframework.graphql.execution.DataFetcherExceptionResolver;
|
||||
import org.springframework.graphql.execution.DataLoaderRegistrar;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.MissingSchemaException;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
|
@ -170,11 +171,18 @@ class GraphQlAutoConfigurationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void shouldConfigCustomBatchLoaderRegistry() {
|
||||
this.contextRunner.withUserConfiguration(CustomBatchLoaderRegistryConfiguration.class).run((context) -> {
|
||||
assertThat(context).getBeanNames(BatchLoaderRegistry.class).containsOnly("customBatchLoaderRegistry");
|
||||
assertThat(context).hasSingleBean(BatchLoaderRegistry.class);
|
||||
});
|
||||
void shouldConfigureCustomBatchLoaderRegistry() {
|
||||
this.contextRunner
|
||||
.withBean("customBatchLoaderRegistry", BatchLoaderRegistry.class, () -> mock(BatchLoaderRegistry.class))
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(BatchLoaderRegistry.class);
|
||||
assertThat(context.getBean("customBatchLoaderRegistry"))
|
||||
.isSameAs(context.getBean(BatchLoaderRegistry.class));
|
||||
assertThat(context.getBean(GraphQlService.class))
|
||||
.extracting("dataLoaderRegistrars",
|
||||
InstanceOfAssertFactories.list(DataLoaderRegistrar.class))
|
||||
.containsOnly(context.getBean(BatchLoaderRegistry.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
@ -261,14 +269,4 @@ class GraphQlAutoConfigurationTests {
|
|||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomBatchLoaderRegistryConfiguration {
|
||||
|
||||
@Bean
|
||||
BatchLoaderRegistry customBatchLoaderRegistry() {
|
||||
return mock(BatchLoaderRegistry.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue