spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

ConditionalOnGraphQlSchema prevents code first approaches

Open bclozel opened this issue 2 years ago • 0 comments

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
  • GraphQlSourceBuilderCustomizer customizer 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.

bclozel avatar Nov 10 '22 09:11 bclozel