Programatically specifying the GraphQL schema in Spring boot

Viewed 190

I'm using a 'code first' approach for defining the schema using graphql-java-annotations instead of defining the schema in a separate .graphqls file.

I'm trying to specify the schema by using GraphQlSourceBuilderCustomizer as mentioned in the documentation but I get the following exception:

org.springframework.graphql.execution.MissingSchemaException: No GraphQL schema definition was configured. at java.base@17.0.2/java.util.Optional.orElseThrow(Optional.java:403) at app//org.springframework.graphql.execution.DefaultGraphQlSourceBuilder.build(DefaultGraphQlSourceBuilder.java:136) at app//org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration.graphQlSource(GraphQlAutoConfiguration.java:90)

Here's my configuration class. Does anyone know where I'm going wrong?

@Configuration
public class GraphQLConfiguration {
    @Bean
    public GraphQlSourceBuilderCustomizer sourceBuilderCustomizer() {
        GraphQLSchema graphQLSchema = AnnotationsSchemaCreator.newAnnotationsSchema()
                .query(GraphQLQuery.class)
                .build();

        return graphQlSourceBuilder -> graphQlSourceBuilder.configureGraphQl(graphQLBuilder -> graphQLBuilder.schema(graphQLSchema));
    }
}
0 Answers
Related