21
21
import org .reflections .Reflections ;
22
22
import org .reflections .ReflectionsException ;
23
23
import org .springframework .boot .autoconfigure .AutoConfigureBefore ;
24
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
24
25
import org .springframework .boot .context .properties .EnableConfigurationProperties ;
25
26
import org .springframework .context .annotation .Bean ;
26
27
import org .springframework .context .annotation .Configuration ;
32
33
import java .util .Set ;
33
34
34
35
import static graphql .annotations .AnnotationsSchemaCreator .newAnnotationsSchema ;
35
- import static java .util .Objects .isNull ;
36
36
37
37
@ Configuration
38
38
@ AutoConfigureBefore ({GraphQLJavaToolsAutoConfiguration .class })
@@ -43,12 +43,17 @@ public class GraphQLAnnotationsAutoConfiguration {
43
43
44
44
private final GraphQLAnnotationsProperties graphQLAnnotationsProperties ;
45
45
private final Optional <Relay > relay ;
46
- private final Optional <GraphQLAnnotations > customAnnotationProcessor ;
47
46
private final List <TypeFunction > typeFunctions ;
48
47
private final List <GraphQLScalarType > customScalarTypes ;
49
48
50
49
@ Bean
51
- public GraphQLSchema graphQLSchema () {
50
+ @ ConditionalOnMissingBean
51
+ public GraphQLAnnotations graphQLAnnotations () {
52
+ return new GraphQLAnnotations ();
53
+ }
54
+
55
+ @ Bean
56
+ public GraphQLSchema graphQLSchema (final GraphQLAnnotations graphQLAnnotations ) {
52
57
log .info ("Using GraphQL Annotations library to build the schema. Schema definition files will be ignored." );
53
58
log .info ("GraphQL classes are searched in the following package (including subpackages): {}" ,
54
59
graphQLAnnotationsProperties .getBasePackage ());
@@ -73,14 +78,12 @@ public GraphQLSchema graphQLSchema() {
73
78
if (!customScalarTypes .isEmpty ()) {
74
79
builder .typeFunction (new GraphQLScalarTypeFunction (customScalarTypes ));
75
80
}
76
- customAnnotationProcessor .ifPresent (graphQLAnnotations -> {
77
- log .info ("Registering custom GraphQL annotations processor {}" , graphQLAnnotations .getClass ());
78
- builder .setAnnotationsProcessor (graphQLAnnotations );
79
- });
80
- if (isNull (builder .getGraphQLAnnotations ())) {
81
- // before setting a relay, we have to set the annotation processor, otherwise a NPE will occur
82
- builder .setAnnotationsProcessor (new GraphQLAnnotations ());
81
+ if (graphQLAnnotations .getClass ().equals (GraphQLAnnotations .class )) {
82
+ log .info ("Using default GraphQL Annotation processor." );
83
+ } else {
84
+ log .info ("Using custom annotation process of type {}" , graphQLAnnotations .getClass ());
83
85
}
86
+ builder .setAnnotationsProcessor (graphQLAnnotations );
84
87
relay .ifPresent (r -> {
85
88
log .info ("Registering relay {}" , r .getClass ());
86
89
builder .setRelay (r );
0 commit comments