spring-bootgraphqlspring-graphql

Springboot 3 and GraphQL compatibility


I am upgrading my spring boot application from 2.1.6.RELEASE to 3.0.0 After resolving all the errors, the graphql apis are returning null and even the breakpoints are not getting triggered in any of the classes.

Does Spring boot 3 have support for GraphQL?

The following post kind of indicates that the support is not available but need some confirmation. https://spring.io/blog/2022/11/22/spring-for-graphql-1-0-3-released


Solution

  • Upgrade to Spring Boot 3 and Java 17
    
    Migrated to spring boot version 3.0.0 from 2.1.6.RELEASE
    Migrated to Java 17 from Java 8
    Removed GraphQLQueryResolver and GraphQLMutationResolver -  as they were not working
    Used the following instead:
        Added @QueryMapping and @MutationMapping
        Changed Query and Mutation classes from @Component to @Controller
        Added jakarta.persistence-api dependency
        @Argument keyword added to the parameters in functions
    
    Used the following dependency
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-graphql</artifactId>
            </dependency>