Skip to content

Commit 440b123

Browse files
committed
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
1 parent 0f37af1 commit 440b123

File tree

10 files changed

+30
-26
lines changed

10 files changed

+30
-26
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.springframework.context.annotation.Configuration;
3737
import org.springframework.core.io.Resource;
3838
import org.springframework.core.io.support.ResourcePatternResolver;
39-
import org.springframework.graphql.data.method.annotation.support.AnnotatedDataFetcherConfigurer;
39+
import org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer;
4040
import org.springframework.graphql.execution.DataFetcherExceptionResolver;
4141
import org.springframework.graphql.execution.GraphQlSource;
4242
import org.springframework.graphql.execution.MissingSchemaException;
@@ -58,8 +58,8 @@ public class GraphQlAutoConfiguration {
5858
private static final Log logger = LogFactory.getLog(GraphQlAutoConfiguration.class);
5959

6060
@Bean
61-
public AnnotatedDataFetcherConfigurer annotatedDataFetcherConfigurer() {
62-
return new AnnotatedDataFetcherConfigurer();
61+
public AnnotatedControllerConfigurer annotatedControllerConfigurer() {
62+
return new AnnotatedControllerConfigurer();
6363
}
6464

6565
@Bean

spring-graphql-docs/src/docs/asciidoc/boot-starter.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ starter detects such beans adds them to <<index#execution-graphqlsource,GraphQlS
123123

124124
Typically, however, applications will not implement ``DataFetcher`` directly and will
125125
instead create <<index#controllers,annotated controllers>>. The Boot
126-
starter declares a `RuntimeWiringConfigurer` called `AnnotatedDataFetcherConfigurer` that
126+
starter declares a `RuntimeWiringConfigurer` called `AnnotatedControllerConfigurer` that
127127
detects `@Controller` classes with annotated handler methods and registers those as
128128
``DataFetcher``s.
129129

spring-graphql-docs/src/docs/asciidoc/index.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ support for detecting `@Controller` and `@Component` classes on the classpath an
439439
auto-registering bean definitions for them. It also acts as a stereotype for the annotated
440440
class, indicating its role as a data fetching component in a GraphQL application.
441441

442-
`AnnotatedDataFetcherConfigurer` detects `@Controller` beans and registers their
442+
`AnnotatedControllerConfigurer` detects `@Controller` beans and registers their
443443
annotated handler methods as ``DataFetcher``s via `RuntimeWiring.Builder`. It is an
444444
implementation of `RuntimeWiringConfigurer` which can be added to `GraphQlSource.Builder`.
445-
The Spring Boot starter automatically declares `AnnotatedDataFetcherConfigurer` as a bean
445+
The Spring Boot starter automatically declares `AnnotatedControllerConfigurer` as a bean
446446
and adds all `RuntimeWiringConfigurer` beans to `GraphQlSource.Builder` and that enables
447447
support for annotated ``DataFetcher``s, see <<boot-graphql-runtimewiring>>.
448448

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
import org.springframework.core.MethodIntrospector;
4646
import org.springframework.core.MethodParameter;
4747
import org.springframework.core.annotation.AnnotatedElementUtils;
48-
import org.springframework.graphql.data.method.BatchLoadHandlerMethod;
49-
import org.springframework.graphql.data.method.DataFetcherHandlerMethod;
5048
import org.springframework.graphql.data.method.HandlerMethod;
5149
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
5250
import org.springframework.graphql.data.method.HandlerMethodArgumentResolverComposite;
@@ -68,10 +66,10 @@
6866
* @author Rossen Stoyanchev
6967
* @since 1.0.0
7068
*/
71-
public class AnnotatedDataFetcherConfigurer
69+
public class AnnotatedControllerConfigurer
7270
implements ApplicationContextAware, InitializingBean, RuntimeWiringConfigurer {
7371

74-
private final static Log logger = LogFactory.getLog(AnnotatedDataFetcherConfigurer.class);
72+
private final static Log logger = LogFactory.getLog(AnnotatedControllerConfigurer.class);
7573

7674
/**
7775
* Bean name prefix for target beans behind scoped proxies. Used to exclude those
@@ -289,7 +287,7 @@ private <P, F> String registerBatchLoader(MappingInfo info) {
289287
}
290288

291289
String dataLoaderKey = info.getCoordinates().toString();
292-
BatchLoadHandlerMethod invocable = new BatchLoadHandlerMethod(info.getHandlerMethod());
290+
BatchLoaderHandlerMethod invocable = new BatchLoaderHandlerMethod(info.getHandlerMethod());
293291
BatchLoaderRegistry registry = obtainApplicationContext().getBean(BatchLoaderRegistry.class);
294292

295293
Class<?> clazz = info.getHandlerMethod().getReturnType().getParameterType();

spring-graphql/src/main/java/org/springframework/graphql/data/method/BatchLoadHandlerMethod.java renamed to spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/BatchLoaderHandlerMethod.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.graphql.data.method;
16+
package org.springframework.graphql.data.method.annotation.support;
1717

1818
import java.util.Collection;
1919
import java.util.Map;
@@ -24,6 +24,8 @@
2424

2525
import org.springframework.core.CollectionFactory;
2626
import org.springframework.core.MethodParameter;
27+
import org.springframework.graphql.data.method.HandlerMethod;
28+
import org.springframework.graphql.data.method.InvocableHandlerMethodSupport;
2729
import org.springframework.lang.Nullable;
2830
import org.springframework.util.Assert;
2931

@@ -35,10 +37,10 @@
3537
* @author Rossen Stoyanchev
3638
* @since 1.0.0
3739
*/
38-
public class BatchLoadHandlerMethod extends InvocableHandlerMethodSupport {
40+
public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport {
3941

4042

41-
public BatchLoadHandlerMethod(HandlerMethod handlerMethod) {
43+
public BatchLoaderHandlerMethod(HandlerMethod handlerMethod) {
4244
super(handlerMethod);
4345
}
4446

spring-graphql/src/main/java/org/springframework/graphql/data/method/DataFetcherHandlerMethod.java renamed to spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethod.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.graphql.data.method;
16+
package org.springframework.graphql.data.method.annotation.support;
1717

1818
import java.util.Arrays;
1919

@@ -22,6 +22,10 @@
2222
import org.springframework.core.DefaultParameterNameDiscoverer;
2323
import org.springframework.core.MethodParameter;
2424
import org.springframework.core.ParameterNameDiscoverer;
25+
import org.springframework.graphql.data.method.HandlerMethod;
26+
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
27+
import org.springframework.graphql.data.method.HandlerMethodArgumentResolverComposite;
28+
import org.springframework.graphql.data.method.InvocableHandlerMethodSupport;
2529
import org.springframework.lang.Nullable;
2630
import org.springframework.util.Assert;
2731
import org.springframework.util.ObjectUtils;

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4040

4141
/**
42-
* Unit tests for {@link AnnotatedDataFetcherConfigurer}, focusing on detection
42+
* Unit tests for {@link AnnotatedControllerConfigurer}, focusing on detection
4343
* and mapping of handler methods to schema fields.
4444
*
4545
* @author Rossen Stoyanchev
@@ -84,7 +84,7 @@ private RuntimeWiring.Builder initRuntimeWiringBuilder(Class<?> handlerType) {
8484
appContext.registerBean(BatchLoaderRegistry.class, () -> this.batchLoaderRegistry);
8585
appContext.refresh();
8686

87-
AnnotatedDataFetcherConfigurer configurer = new AnnotatedDataFetcherConfigurer();
87+
AnnotatedControllerConfigurer configurer = new AnnotatedControllerConfigurer();
8888
configurer.setApplicationContext(appContext);
8989
configurer.afterPropertiesSet();
9090

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public Map<Course, List<Person>> students(List<Course> courses) {
260260
private static class CourseConfig {
261261

262262
@Bean
263-
public GraphQlSource graphQlSource(AnnotatedDataFetcherConfigurer configurer) {
263+
public GraphQlSource graphQlSource(AnnotatedControllerConfigurer configurer) {
264264
return GraphQlSource.builder()
265265
.schemaResources(new ByteArrayResource(schema.getBytes(StandardCharsets.UTF_8)))
266266
.configureRuntimeWiring(configurer)
@@ -275,8 +275,8 @@ public GraphQlService graphQlService(GraphQlSource source, BatchLoaderRegistry r
275275
}
276276

277277
@Bean
278-
public AnnotatedDataFetcherConfigurer annotatedDataFetcherConfigurer() {
279-
return new AnnotatedDataFetcherConfigurer();
278+
public AnnotatedControllerConfigurer annotatedDataFetcherConfigurer() {
279+
return new AnnotatedControllerConfigurer();
280280
}
281281

282282
@Bean

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingDetectionTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.assertj.core.api.Assertions.assertThat;
3838

3939
/**
40-
* Unit tests for {@link AnnotatedDataFetcherConfigurer}, focusing on detection
40+
* Unit tests for {@link AnnotatedControllerConfigurer}, focusing on detection
4141
* and mapping of handler methods to schema fields.
4242
*
4343
* @author Rossen Stoyanchev
@@ -85,7 +85,7 @@ private RuntimeWiring.Builder initRuntimeWiringBuilder(Class<?> handlerType) {
8585
appContext.registerBean(handlerType);
8686
appContext.refresh();
8787

88-
AnnotatedDataFetcherConfigurer configurer = new AnnotatedDataFetcherConfigurer();
88+
AnnotatedControllerConfigurer configurer = new AnnotatedControllerConfigurer();
8989
configurer.setApplicationContext(appContext);
9090
configurer.afterPropertiesSet();
9191

@@ -101,8 +101,8 @@ private void assertMapping(Map<String, Map<String, DataFetcher>> map, String coo
101101
String typeName = strings[0];
102102
String field = strings[1];
103103

104-
AnnotatedDataFetcherConfigurer.SchemaMappingDataFetcher dataFetcher =
105-
(AnnotatedDataFetcherConfigurer.SchemaMappingDataFetcher) map.get(typeName).get(field);
104+
AnnotatedControllerConfigurer.SchemaMappingDataFetcher dataFetcher =
105+
(AnnotatedControllerConfigurer.SchemaMappingDataFetcher) map.get(typeName).get(field);
106106

107107
assertThat(dataFetcher.getHandlerMethod().getMethod().getName()).isEqualTo(methodName);
108108
}

spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ public GraphQlSource graphQlSource() {
240240
}
241241

242242
@Bean
243-
public AnnotatedDataFetcherConfigurer annotatedDataFetcherConfigurer() {
244-
return new AnnotatedDataFetcherConfigurer();
243+
public AnnotatedControllerConfigurer annotatedDataFetcherConfigurer() {
244+
return new AnnotatedControllerConfigurer();
245245
}
246246

247247
@Bean

0 commit comments

Comments
 (0)