spring-boot
spring-boot copied to clipboard
ConditionalOnGraphQlSchema prevents code first approaches
As discussed in spring-projects/spring-graphql#526, Spring for GraphQL did not adopt a "code first" approach (generating the GraphQL schema from Java method signatures), but rather a "schema first" approach (manually crafting a schema as the core contract of the service and controllers registering data fetchers for this schema).
While Spring for GraphQL is not designed with "code first" approaches in mind, we don't want to prevent developers from building such infrastructures in their projects. Currently, the main GraphQL auto-configuration is annotated with @ConditionalOnGraphQlSchema which checks for the presence of one of:
- schema files on the classpath, in the location pointed by
spring.graphql.schema GraphQlSourceBuilderCustomizercustomizer beans
If developers want full controller over the GraphQL schema, the Spring GraphQL team currently advises to create your own GraphQlSource bean. The current implementation of the condition prevents that and developers currently put an empty "schema.graphql" file to work around this problem. We should revisit this condition implementation to also consider GraphQlSource beans.