1414import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
1515import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
1616import org .springframework .boot .autoconfigure .jackson .JacksonAutoConfiguration ;
17+ import org .springframework .boot .context .properties .ConfigurationProperties ;
1718import org .springframework .boot .context .properties .EnableConfigurationProperties ;
1819import org .springframework .context .annotation .Bean ;
1920import org .springframework .context .annotation .Configuration ;
@@ -36,15 +37,13 @@ public class GraphQLJavaToolsAutoConfiguration {
3637 @ Autowired (required = false )
3738 private GraphQLScalarType [] scalars ;
3839
39- @ Autowired (required = false )
40- private SchemaParserOptions options ;
41-
4240 @ Autowired (required = false )
4341 private List <SchemaDirective > directives ;
4442
4543 @ Autowired (required = false )
4644 private List <TypeDefinitionFactory > typeDefinitionFactories ;
4745
46+
4847 @ Autowired
4948 private GraphQLToolsProperties props ;
5049
@@ -54,13 +53,33 @@ public SchemaStringProvider schemaStringProvider() {
5453 return new ClasspathResourceSchemaStringProvider (props .getSchemaLocationPattern ());
5554 }
5655
56+ @ Bean
57+ @ ConditionalOnMissingBean
58+ @ ConfigurationProperties ("graphql.tools.schema-parser-options" )
59+ public SchemaParserOptions .Builder optionsBuilder (
60+ PerFieldObjectMapperProvider perFieldObjectMapperProvider
61+ ) {
62+ SchemaParserOptions .Builder optionsBuilder = SchemaParserOptions .newOptions ();
63+
64+ if (perFieldObjectMapperProvider != null ) {
65+ optionsBuilder .objectMapperProvider (perFieldObjectMapperProvider );
66+ }
67+ optionsBuilder .introspectionEnabled (props .isIntrospectionEnabled ());
68+
69+ if (typeDefinitionFactories != null ) {
70+ typeDefinitionFactories .forEach (optionsBuilder ::typeDefinitionFactory );
71+ }
72+
73+ return optionsBuilder ;
74+ }
75+
5776 @ Bean
5877 @ ConditionalOnBean ({GraphQLResolver .class })
5978 @ ConditionalOnMissingBean
6079 public SchemaParser schemaParser (
6180 List <GraphQLResolver <?>> resolvers ,
6281 SchemaStringProvider schemaStringProvider ,
63- PerFieldObjectMapperProvider perFieldObjectMapperProvider
82+ SchemaParserOptions . Builder optionsBuilder
6483 ) throws IOException {
6584 SchemaParserBuilder builder = dictionary != null ? new SchemaParserBuilder (dictionary ) : new SchemaParserBuilder ();
6685
@@ -71,23 +90,7 @@ public SchemaParser schemaParser(
7190 builder .scalars (scalars );
7291 }
7392
74- // fixme: should we even support options directly like this? the combination with the builder makes it complex
75- if (options != null ) {
76- builder .options (options );
77- } else {
78- SchemaParserOptions .Builder optionsBuilder = SchemaParserOptions .newOptions ();
79-
80- if (perFieldObjectMapperProvider != null ) {
81- optionsBuilder .objectMapperProvider (perFieldObjectMapperProvider );
82- }
83- optionsBuilder .introspectionEnabled (props .isIntrospectionEnabled ());
84-
85- if (typeDefinitionFactories != null ) {
86- typeDefinitionFactories .forEach (optionsBuilder ::typeDefinitionFactory );
87- }
88-
89- builder .options (optionsBuilder .build ());
90- }
93+ builder .options (optionsBuilder .build ());
9194
9295 if (directives != null ) {
9396 directives .forEach (it -> builder .directive (it .getName (), it .getDirective ()));
0 commit comments