Polish GraphQL QueryBE and QueryDSL auto-configurations
Closes gh-34974
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.graphql.data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import graphql.GraphQL;
|
||||
@@ -29,9 +30,9 @@ import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlSourceBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor;
|
||||
import org.springframework.graphql.data.query.QueryByExampleDataFetcher;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} that creates a
|
||||
@@ -49,10 +50,10 @@ import org.springframework.graphql.execution.GraphQlSource;
|
||||
public class GraphQlQueryByExampleAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public GraphQlSourceBuilderCustomizer queryByExampleRegistrar(ObjectProvider<QueryByExampleExecutor<?>> executors,
|
||||
ObjectProvider<ReactiveQueryByExampleExecutor<?>> reactiveExecutors) {
|
||||
return new GraphQlQuerydslSourceBuilderCustomizer<>(QueryByExampleDataFetcher::autoRegistrationConfigurer,
|
||||
executors, reactiveExecutors);
|
||||
public GraphQlSourceBuilderCustomizer queryByExampleRegistrar(ObjectProvider<QueryByExampleExecutor<?>> executors) {
|
||||
RuntimeWiringConfigurer configurer = QueryByExampleDataFetcher
|
||||
.autoRegistrationConfigurer(executors.orderedStream().toList(), Collections.emptyList());
|
||||
return (builder) -> builder.configureRuntimeWiring(configurer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.graphql.data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import graphql.GraphQL;
|
||||
@@ -29,9 +30,9 @@ import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlSourceBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor;
|
||||
import org.springframework.graphql.data.query.QuerydslDataFetcher;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} that creates a
|
||||
@@ -50,10 +51,10 @@ import org.springframework.graphql.execution.GraphQlSource;
|
||||
public class GraphQlQuerydslAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public GraphQlSourceBuilderCustomizer querydslRegistrar(ObjectProvider<QuerydslPredicateExecutor<?>> executors,
|
||||
ObjectProvider<ReactiveQuerydslPredicateExecutor<?>> reactiveExecutors) {
|
||||
return new GraphQlQuerydslSourceBuilderCustomizer<>(QuerydslDataFetcher::autoRegistrationConfigurer, executors,
|
||||
reactiveExecutors);
|
||||
public GraphQlSourceBuilderCustomizer querydslRegistrar(ObjectProvider<QuerydslPredicateExecutor<?>> executors) {
|
||||
RuntimeWiringConfigurer configurer = QuerydslDataFetcher
|
||||
.autoRegistrationConfigurer(executors.orderedStream().toList(), Collections.emptyList());
|
||||
return (builder) -> builder.configureRuntimeWiring(configurer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.graphql.data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlSourceBuilderCustomizer;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
|
||||
/**
|
||||
* {@link GraphQlSourceBuilderCustomizer} to apply auto-configured QueryDSL
|
||||
* {@link RuntimeWiringConfigurer RuntimeWiringConfigurers}.
|
||||
*
|
||||
* @param <E> the executor type
|
||||
* @param <R> the reactive executor type
|
||||
* @author Phillip Webb
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class GraphQlQuerydslSourceBuilderCustomizer<E, R> implements GraphQlSourceBuilderCustomizer {
|
||||
|
||||
private final BiFunction<List<E>, List<R>, RuntimeWiringConfigurer> wiringConfigurerFactory;
|
||||
|
||||
private final List<E> executors;
|
||||
|
||||
private final List<R> reactiveExecutors;
|
||||
|
||||
GraphQlQuerydslSourceBuilderCustomizer(
|
||||
BiFunction<List<E>, List<R>, RuntimeWiringConfigurer> wiringConfigurerFactory, ObjectProvider<E> executors,
|
||||
ObjectProvider<R> reactiveExecutors) {
|
||||
this.wiringConfigurerFactory = wiringConfigurerFactory;
|
||||
this.executors = asList(executors);
|
||||
this.reactiveExecutors = asList(reactiveExecutors);
|
||||
}
|
||||
|
||||
private static <T> List<T> asList(ObjectProvider<T> provider) {
|
||||
return (provider != null) ? provider.orderedStream().toList() : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(GraphQlSource.SchemaResourceBuilder builder) {
|
||||
if (!this.executors.isEmpty() || !this.reactiveExecutors.isEmpty()) {
|
||||
builder.configureRuntimeWiring(this.wiringConfigurerFactory.apply(this.executors, this.reactiveExecutors));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.graphql.data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import graphql.GraphQL;
|
||||
@@ -28,10 +29,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlSourceBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor;
|
||||
import org.springframework.graphql.data.query.QueryByExampleDataFetcher;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} that creates a
|
||||
@@ -51,8 +52,9 @@ public class GraphQlReactiveQueryByExampleAutoConfiguration {
|
||||
@Bean
|
||||
public GraphQlSourceBuilderCustomizer reactiveQueryByExampleRegistrar(
|
||||
ObjectProvider<ReactiveQueryByExampleExecutor<?>> reactiveExecutors) {
|
||||
return new GraphQlQuerydslSourceBuilderCustomizer<>(QueryByExampleDataFetcher::autoRegistrationConfigurer,
|
||||
(ObjectProvider<QueryByExampleExecutor<?>>) null, reactiveExecutors);
|
||||
RuntimeWiringConfigurer configurer = QueryByExampleDataFetcher
|
||||
.autoRegistrationConfigurer(Collections.emptyList(), reactiveExecutors.orderedStream().toList());
|
||||
return (builder) -> builder.configureRuntimeWiring(configurer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.graphql.data;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import graphql.GraphQL;
|
||||
@@ -28,10 +29,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.graphql.GraphQlSourceBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor;
|
||||
import org.springframework.graphql.data.query.QuerydslDataFetcher;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} that creates a
|
||||
@@ -52,8 +53,9 @@ public class GraphQlReactiveQuerydslAutoConfiguration {
|
||||
@Bean
|
||||
public GraphQlSourceBuilderCustomizer reactiveQuerydslRegistrar(
|
||||
ObjectProvider<ReactiveQuerydslPredicateExecutor<?>> reactiveExecutors) {
|
||||
return new GraphQlQuerydslSourceBuilderCustomizer<>(QuerydslDataFetcher::autoRegistrationConfigurer,
|
||||
(ObjectProvider<QuerydslPredicateExecutor<?>>) null, reactiveExecutors);
|
||||
RuntimeWiringConfigurer configurer = QuerydslDataFetcher.autoRegistrationConfigurer(Collections.emptyList(),
|
||||
reactiveExecutors.orderedStream().toList());
|
||||
return (builder) -> builder.configureRuntimeWiring(configurer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class GraphQlQueryByExampleAutoConfigurationTests {
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(GraphQlAutoConfiguration.class, GraphQlQueryByExampleAutoConfiguration.class))
|
||||
.withUserConfiguration(MockRepositoryConfig.class)
|
||||
.withPropertyValues("spring.main.web-application-type=reactive");
|
||||
.withPropertyValues("spring.main.web-application-type=servlet");
|
||||
|
||||
@Test
|
||||
void shouldRegisterDataFetcherForQueryByExampleRepositories() {
|
||||
|
||||
@@ -50,7 +50,7 @@ class GraphQlQuerydslAutoConfigurationTests {
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(GraphQlAutoConfiguration.class, GraphQlQuerydslAutoConfiguration.class))
|
||||
.withUserConfiguration(MockRepositoryConfig.class)
|
||||
.withPropertyValues("spring.main.web-application-type=reactive");
|
||||
.withPropertyValues("spring.main.web-application-type=servlet");
|
||||
|
||||
@Test
|
||||
void shouldRegisterDataFetcherForQueryDslRepositories() {
|
||||
|
||||
Reference in New Issue
Block a user