Skip to content

Commit 052b1f0

Browse files
committed
Refactor schema mapping inspection support
Because performing the schema mapping inspection on the `TypeDefinitionRegistry` could be too early in the process, this commit uses instead the `GraphQLSchema` instance directly for the inspection. Other extension points could indeed contribute more to the schema before it's fully built. As for querying for DataFetcher instances, the inspector keeps using the `RuntimeWiring` instance right after Spring for GraphQL contributed to it. After that, data fetchers could wrapped by other extensions, preventing it from getting the type information we need. This also moves the `TypedDataFetcher` interface to a different package to prevent a package tangle, and renamed as `SelfDescribingDataFetcher` to enable further extension and to be more descriptive. This changes the report format to keep it on a single line. Closes gh-386
1 parent 998d188 commit 052b1f0

File tree

8 files changed

+307
-368
lines changed

8 files changed

+307
-368
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
import org.springframework.format.support.DefaultFormattingConversionService;
6363
import org.springframework.format.support.FormattingConversionService;
6464
import org.springframework.graphql.data.GraphQlArgumentBinder;
65-
import org.springframework.graphql.data.TypedDataFetcher;
65+
import org.springframework.graphql.execution.SelfDescribingDataFetcher;
6666
import org.springframework.graphql.data.method.HandlerMethod;
6767
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
6868
import org.springframework.graphql.data.method.HandlerMethodArgumentResolverComposite;
@@ -540,7 +540,7 @@ public String toString() {
540540
/**
541541
* {@link DataFetcher} that wrap and invokes a {@link HandlerMethod}.
542542
*/
543-
static class SchemaMappingDataFetcher implements TypedDataFetcher<Object> {
543+
static class SchemaMappingDataFetcher implements SelfDescribingDataFetcher<Object> {
544544

545545
private final MappingInfo info;
546546

@@ -632,7 +632,7 @@ private <T> Publisher<T> handleSubscriptionError(
632632
}
633633

634634
@Override
635-
public ResolvableType getDeclaredType() {
635+
public ResolvableType getReturnType() {
636636
return ResolvableType.forMethodReturnType(this.info.getHandlerMethod().getMethod());
637637
}
638638

spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.springframework.data.util.TypeInformation;
4242
import org.springframework.graphql.data.GraphQlArgumentBinder;
4343
import org.springframework.graphql.data.GraphQlRepository;
44-
import org.springframework.graphql.data.TypedDataFetcher;
44+
import org.springframework.graphql.execution.SelfDescribingDataFetcher;
4545
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
4646
import org.springframework.util.Assert;
4747
import org.springframework.validation.BindException;
@@ -442,7 +442,7 @@ public interface ReactiveQueryByExampleBuilderCustomizer<T> {
442442
}
443443

444444

445-
private static class SingleEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements TypedDataFetcher<R> {
445+
private static class SingleEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements SelfDescribingDataFetcher<R> {
446446

447447
private final QueryByExampleExecutor<T> executor;
448448

@@ -482,13 +482,13 @@ public R get(DataFetchingEnvironment env) throws BindException {
482482
}
483483

484484
@Override
485-
public ResolvableType getDeclaredType() {
485+
public ResolvableType getReturnType() {
486486
return ResolvableType.forClass(this.resultType);
487487
}
488488
}
489489

490490

491-
private static class ManyEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements TypedDataFetcher<Iterable<R>> {
491+
private static class ManyEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements SelfDescribingDataFetcher<Iterable<R>> {
492492

493493
private final QueryByExampleExecutor<T> executor;
494494

@@ -528,14 +528,14 @@ public Iterable<R> get(DataFetchingEnvironment env) throws BindException {
528528
}
529529

530530
@Override
531-
public ResolvableType getDeclaredType() {
531+
public ResolvableType getReturnType() {
532532
return ResolvableType.forClassWithGenerics(Iterable.class, this.resultType);
533533
}
534534

535535
}
536536

537537

538-
private static class ReactiveSingleEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements TypedDataFetcher<Mono<R>> {
538+
private static class ReactiveSingleEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements SelfDescribingDataFetcher<Mono<R>> {
539539

540540
private final ReactiveQueryByExampleExecutor<T> executor;
541541

@@ -575,14 +575,14 @@ public Mono<R> get(DataFetchingEnvironment env) throws BindException {
575575
}
576576

577577
@Override
578-
public ResolvableType getDeclaredType() {
578+
public ResolvableType getReturnType() {
579579
return ResolvableType.forClassWithGenerics(Mono.class, this.resultType);
580580
}
581581

582582
}
583583

584584

585-
private static class ReactiveManyEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements TypedDataFetcher<Flux<R>> {
585+
private static class ReactiveManyEntityFetcher<T, R> extends QueryByExampleDataFetcher<T> implements SelfDescribingDataFetcher<Flux<R>> {
586586

587587
private final ReactiveQueryByExampleExecutor<T> executor;
588588

@@ -622,7 +622,7 @@ public Flux<R> get(DataFetchingEnvironment env) throws BindException {
622622
}
623623

624624
@Override
625-
public ResolvableType getDeclaredType() {
625+
public ResolvableType getReturnType() {
626626
return ResolvableType.forClassWithGenerics(Flux.class, this.resultType);
627627
}
628628

spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery;
4848
import org.springframework.data.util.TypeInformation;
4949
import org.springframework.graphql.data.GraphQlRepository;
50-
import org.springframework.graphql.data.TypedDataFetcher;
50+
import org.springframework.graphql.execution.SelfDescribingDataFetcher;
5151
import org.springframework.graphql.execution.RuntimeWiringConfigurer;
5252
import org.springframework.util.Assert;
5353
import org.springframework.util.LinkedMultiValueMap;
@@ -540,7 +540,7 @@ public interface ReactiveQuerydslBuilderCustomizer<T> {
540540
}
541541

542542

543-
private static class SingleEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements TypedDataFetcher<R> {
543+
private static class SingleEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements SelfDescribingDataFetcher<R> {
544544

545545
private final QuerydslPredicateExecutor<T> executor;
546546

@@ -584,13 +584,13 @@ public R get(DataFetchingEnvironment env) {
584584
}
585585

586586
@Override
587-
public ResolvableType getDeclaredType() {
587+
public ResolvableType getReturnType() {
588588
return ResolvableType.forClass(this.resultType);
589589
}
590590
}
591591

592592

593-
private static class ManyEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements TypedDataFetcher<Iterable<R>> {
593+
private static class ManyEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements SelfDescribingDataFetcher<Iterable<R>> {
594594

595595
private final QuerydslPredicateExecutor<T> executor;
596596

@@ -632,14 +632,14 @@ public Iterable<R> get(DataFetchingEnvironment env) {
632632
}
633633

634634
@Override
635-
public ResolvableType getDeclaredType() {
635+
public ResolvableType getReturnType() {
636636
return ResolvableType.forClassWithGenerics(Iterable.class, this.resultType);
637637
}
638638

639639
}
640640

641641

642-
private static class ReactiveSingleEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements TypedDataFetcher<Mono<R>> {
642+
private static class ReactiveSingleEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements SelfDescribingDataFetcher<Mono<R>> {
643643

644644
private final ReactiveQuerydslPredicateExecutor<T> executor;
645645

@@ -682,14 +682,14 @@ public Mono<R> get(DataFetchingEnvironment env) {
682682
}
683683

684684
@Override
685-
public ResolvableType getDeclaredType() {
685+
public ResolvableType getReturnType() {
686686
return ResolvableType.forClassWithGenerics(Mono.class, this.resultType);
687687
}
688688

689689
}
690690

691691

692-
private static class ReactiveManyEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements TypedDataFetcher<Flux<R>> {
692+
private static class ReactiveManyEntityFetcher<T, R> extends QuerydslDataFetcher<T> implements SelfDescribingDataFetcher<Flux<R>> {
693693

694694
private final ReactiveQuerydslPredicateExecutor<T> executor;
695695

@@ -732,7 +732,7 @@ public Flux<R> get(DataFetchingEnvironment env) {
732732
}
733733

734734
@Override
735-
public ResolvableType getDeclaredType() {
735+
public ResolvableType getReturnType() {
736736
return ResolvableType.forClassWithGenerics(Flux.class, this.resultType);
737737
}
738738

spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ protected GraphQLSchema initGraphQlSchema() {
139139
}
140140
});
141141

142-
SchemaInspector.Report schemaInspectionReport = new SchemaInspector().inspectSchema(registry, runtimeWiring);
143-
if(!schemaInspectionReport.isEmpty()) {
144-
logger.info(schemaInspectionReport.getSummary());
145-
logger.info(schemaInspectionReport.getDetailedReport());
146-
}
142+
configureGraphQl(builder -> {
143+
GraphQLSchema schema = builder.build().getGraphQLSchema();
144+
SchemaMappingInspector.Report schemaInspectionReport = new SchemaMappingInspector().inspectSchemaMappings(schema, runtimeWiring);
145+
if(!schemaInspectionReport.isEmpty()) {
146+
logger.info(schemaInspectionReport.getSummary());
147+
}
148+
});
147149

148150
return (this.schemaFactory != null ?
149151
this.schemaFactory.apply(registry, runtimeWiring) :

0 commit comments

Comments
 (0)