Configure GraphQlProperties even if GraphQlSource is defined
Prior to this commit, the main GraphQL auto-configuration would be guarded with a condition on a `GraphQlSource` bean being missing. While we want to prevent the auto-configuration from registering such a bean if the user configuration already did so, we should still contribute the `GraphQlProperties` bean to the context, as it is required for other purposes. This commit moves the condition directly on the bean method to avoid this. Fixes gh-186
This commit is contained in:
@@ -50,13 +50,13 @@ import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass({GraphQL.class, GraphQlSource.class})
|
||||
@ConditionalOnMissingBean(GraphQlSource.class)
|
||||
@EnableConfigurationProperties(GraphQlProperties.class)
|
||||
public class GraphQlAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GraphQlAutoConfiguration.class);
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GraphQlSource graphQlSource(ResourcePatternResolver resourcePatternResolver, GraphQlProperties properties,
|
||||
ObjectProvider<DataFetcherExceptionResolver> exceptionResolversProvider,
|
||||
ObjectProvider<Instrumentation> instrumentationsProvider,
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.MissingSchemaException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link GraphQlAutoConfiguration}
|
||||
@@ -74,6 +75,15 @@ class GraphQlAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBackOffWithCustomGraphQlSource() {
|
||||
this.contextRunner.withUserConfiguration(CustomGraphQlSourceConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).getBeanNames(GraphQlSource.class).containsOnly("customGraphQlSource");
|
||||
assertThat(context).hasSingleBean(GraphQlProperties.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomGraphQlBuilderConfiguration {
|
||||
|
||||
@@ -84,4 +94,14 @@ class GraphQlAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomGraphQlSourceConfiguration {
|
||||
|
||||
@Bean
|
||||
GraphQlSource customGraphQlSource() {
|
||||
return mock(GraphQlSource.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user