2121import org .reflections .Reflections ;
2222import org .reflections .ReflectionsException ;
2323import org .springframework .boot .autoconfigure .AutoConfigureBefore ;
24+ import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
2425import org .springframework .boot .context .properties .EnableConfigurationProperties ;
2526import org .springframework .context .annotation .Bean ;
2627import org .springframework .context .annotation .Configuration ;
3233import java .util .Set ;
3334
3435import static graphql .annotations .AnnotationsSchemaCreator .newAnnotationsSchema ;
35- import static java .util .Objects .isNull ;
3636
3737@ Configuration
3838@ AutoConfigureBefore ({GraphQLJavaToolsAutoConfiguration .class })
@@ -43,12 +43,17 @@ public class GraphQLAnnotationsAutoConfiguration {
4343
4444 private final GraphQLAnnotationsProperties graphQLAnnotationsProperties ;
4545 private final Optional <Relay > relay ;
46- private final Optional <GraphQLAnnotations > customAnnotationProcessor ;
4746 private final List <TypeFunction > typeFunctions ;
4847 private final List <GraphQLScalarType > customScalarTypes ;
4948
5049 @ 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 ) {
5257 log .info ("Using GraphQL Annotations library to build the schema. Schema definition files will be ignored." );
5358 log .info ("GraphQL classes are searched in the following package (including subpackages): {}" ,
5459 graphQLAnnotationsProperties .getBasePackage ());
@@ -73,14 +78,12 @@ public GraphQLSchema graphQLSchema() {
7378 if (!customScalarTypes .isEmpty ()) {
7479 builder .typeFunction (new GraphQLScalarTypeFunction (customScalarTypes ));
7580 }
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 ());
8385 }
86+ builder .setAnnotationsProcessor (graphQLAnnotations );
8487 relay .ifPresent (r -> {
8588 log .info ("Registering relay {}" , r .getClass ());
8689 builder .setRelay (r );
0 commit comments