Minor refactoring

Rename AnnotatedDataFetcherConfigurer -> AnnotatedControllerConfigurer,
since handler methods are now not only data fetchers but also
batch loaders.

Move DataFetcherHandlerMethod and BatchLoaderHandlerMethod into the
support package next to AnnotatedControllerConfigurer where they're used.

See gh-130
This commit is contained in:
Rossen Stoyanchev
2021-09-29 17:56:08 +01:00
parent 0f37af1b25
commit 440b123cc4
10 changed files with 30 additions and 26 deletions

View File

@@ -36,7 +36,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.graphql.data.method.annotation.support.AnnotatedDataFetcherConfigurer;
import org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer;
import org.springframework.graphql.execution.DataFetcherExceptionResolver;
import org.springframework.graphql.execution.GraphQlSource;
import org.springframework.graphql.execution.MissingSchemaException;
@@ -58,8 +58,8 @@ public class GraphQlAutoConfiguration {
private static final Log logger = LogFactory.getLog(GraphQlAutoConfiguration.class);
@Bean
public AnnotatedDataFetcherConfigurer annotatedDataFetcherConfigurer() {
return new AnnotatedDataFetcherConfigurer();
public AnnotatedControllerConfigurer annotatedControllerConfigurer() {
return new AnnotatedControllerConfigurer();
}
@Bean

View File

@@ -123,7 +123,7 @@ starter detects such beans adds them to <<index#execution-graphqlsource,GraphQlS
Typically, however, applications will not implement ``DataFetcher`` directly and will
instead create <<index#controllers,annotated controllers>>. The Boot
starter declares a `RuntimeWiringConfigurer` called `AnnotatedDataFetcherConfigurer` that
starter declares a `RuntimeWiringConfigurer` called `AnnotatedControllerConfigurer` that
detects `@Controller` classes with annotated handler methods and registers those as
``DataFetcher``s.

View File

@@ -439,10 +439,10 @@ support for detecting `@Controller` and `@Component` classes on the classpath an
auto-registering bean definitions for them. It also acts as a stereotype for the annotated
class, indicating its role as a data fetching component in a GraphQL application.
`AnnotatedDataFetcherConfigurer` detects `@Controller` beans and registers their
`AnnotatedControllerConfigurer` detects `@Controller` beans and registers their
annotated handler methods as ``DataFetcher``s via `RuntimeWiring.Builder`. It is an
implementation of `RuntimeWiringConfigurer` which can be added to `GraphQlSource.Builder`.
The Spring Boot starter automatically declares `AnnotatedDataFetcherConfigurer` as a bean
The Spring Boot starter automatically declares `AnnotatedControllerConfigurer` as a bean
and adds all `RuntimeWiringConfigurer` beans to `GraphQlSource.Builder` and that enables
support for annotated ``DataFetcher``s, see <<boot-graphql-runtimewiring>>.

View File

@@ -45,8 +45,6 @@ import org.springframework.core.KotlinDetector;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.graphql.data.method.BatchLoadHandlerMethod;
import org.springframework.graphql.data.method.DataFetcherHandlerMethod;
import org.springframework.graphql.data.method.HandlerMethod;
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
import org.springframework.graphql.data.method.HandlerMethodArgumentResolverComposite;
@@ -68,10 +66,10 @@ import org.springframework.util.StringUtils;
* @author Rossen Stoyanchev
* @since 1.0.0
*/
public class AnnotatedDataFetcherConfigurer
public class AnnotatedControllerConfigurer
implements ApplicationContextAware, InitializingBean, RuntimeWiringConfigurer {
private final static Log logger = LogFactory.getLog(AnnotatedDataFetcherConfigurer.class);
private final static Log logger = LogFactory.getLog(AnnotatedControllerConfigurer.class);
/**
* Bean name prefix for target beans behind scoped proxies. Used to exclude those
@@ -289,7 +287,7 @@ public class AnnotatedDataFetcherConfigurer
}
String dataLoaderKey = info.getCoordinates().toString();
BatchLoadHandlerMethod invocable = new BatchLoadHandlerMethod(info.getHandlerMethod());
BatchLoaderHandlerMethod invocable = new BatchLoaderHandlerMethod(info.getHandlerMethod());
BatchLoaderRegistry registry = obtainApplicationContext().getBean(BatchLoaderRegistry.class);
Class<?> clazz = info.getHandlerMethod().getReturnType().getParameterType();

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.graphql.data.method;
package org.springframework.graphql.data.method.annotation.support;
import java.util.Collection;
import java.util.Map;
@@ -24,6 +24,8 @@ import reactor.core.publisher.Mono;
import org.springframework.core.CollectionFactory;
import org.springframework.core.MethodParameter;
import org.springframework.graphql.data.method.HandlerMethod;
import org.springframework.graphql.data.method.InvocableHandlerMethodSupport;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -35,10 +37,10 @@ import org.springframework.util.Assert;
* @author Rossen Stoyanchev
* @since 1.0.0
*/
public class BatchLoadHandlerMethod extends InvocableHandlerMethodSupport {
public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport {
public BatchLoadHandlerMethod(HandlerMethod handlerMethod) {
public BatchLoaderHandlerMethod(HandlerMethod handlerMethod) {
super(handlerMethod);
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.graphql.data.method;
package org.springframework.graphql.data.method.annotation.support;
import java.util.Arrays;
@@ -22,6 +22,10 @@ import graphql.schema.DataFetchingEnvironment;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.graphql.data.method.HandlerMethod;
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
import org.springframework.graphql.data.method.HandlerMethodArgumentResolverComposite;
import org.springframework.graphql.data.method.InvocableHandlerMethodSupport;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

View File

@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Unit tests for {@link AnnotatedDataFetcherConfigurer}, focusing on detection
* Unit tests for {@link AnnotatedControllerConfigurer}, focusing on detection
* and mapping of handler methods to schema fields.
*
* @author Rossen Stoyanchev
@@ -84,7 +84,7 @@ public class BatchMappingDetectionTests {
appContext.registerBean(BatchLoaderRegistry.class, () -> this.batchLoaderRegistry);
appContext.refresh();
AnnotatedDataFetcherConfigurer configurer = new AnnotatedDataFetcherConfigurer();
AnnotatedControllerConfigurer configurer = new AnnotatedControllerConfigurer();
configurer.setApplicationContext(appContext);
configurer.afterPropertiesSet();

View File

@@ -260,7 +260,7 @@ public class BatchMappingInvocationTests {
private static class CourseConfig {
@Bean
public GraphQlSource graphQlSource(AnnotatedDataFetcherConfigurer configurer) {
public GraphQlSource graphQlSource(AnnotatedControllerConfigurer configurer) {
return GraphQlSource.builder()
.schemaResources(new ByteArrayResource(schema.getBytes(StandardCharsets.UTF_8)))
.configureRuntimeWiring(configurer)
@@ -275,8 +275,8 @@ public class BatchMappingInvocationTests {
}
@Bean
public AnnotatedDataFetcherConfigurer annotatedDataFetcherConfigurer() {
return new AnnotatedDataFetcherConfigurer();
public AnnotatedControllerConfigurer annotatedDataFetcherConfigurer() {
return new AnnotatedControllerConfigurer();
}
@Bean

View File

@@ -37,7 +37,7 @@ import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link AnnotatedDataFetcherConfigurer}, focusing on detection
* Unit tests for {@link AnnotatedControllerConfigurer}, focusing on detection
* and mapping of handler methods to schema fields.
*
* @author Rossen Stoyanchev
@@ -85,7 +85,7 @@ public class SchemaMappingDetectionTests {
appContext.registerBean(handlerType);
appContext.refresh();
AnnotatedDataFetcherConfigurer configurer = new AnnotatedDataFetcherConfigurer();
AnnotatedControllerConfigurer configurer = new AnnotatedControllerConfigurer();
configurer.setApplicationContext(appContext);
configurer.afterPropertiesSet();
@@ -101,8 +101,8 @@ public class SchemaMappingDetectionTests {
String typeName = strings[0];
String field = strings[1];
AnnotatedDataFetcherConfigurer.SchemaMappingDataFetcher dataFetcher =
(AnnotatedDataFetcherConfigurer.SchemaMappingDataFetcher) map.get(typeName).get(field);
AnnotatedControllerConfigurer.SchemaMappingDataFetcher dataFetcher =
(AnnotatedControllerConfigurer.SchemaMappingDataFetcher) map.get(typeName).get(field);
assertThat(dataFetcher.getHandlerMethod().getMethod().getName()).isEqualTo(methodName);
}

View File

@@ -240,8 +240,8 @@ public class SchemaMappingInvocationTests {
}
@Bean
public AnnotatedDataFetcherConfigurer annotatedDataFetcherConfigurer() {
return new AnnotatedDataFetcherConfigurer();
public AnnotatedControllerConfigurer annotatedDataFetcherConfigurer() {
return new AnnotatedControllerConfigurer();
}
@Bean