Member-only story
GraphQL with Spring Boot

GraphQL is a query language for API which we can use to get data from backend servers. Through GraphQL we can control what properties are needed for our use case and can exactly query for those properties.
Spring Boot is a very popular Java framework and from Spring Boot 2.7 we are getting framework support for GraphQL.
If you are not a member, you can read from here
Overview
In this article I will demonstrate:
- Basic mutation type
- Mutation with input type
- Basic Query type (single and batch)
- Multiple schema files for specific domains
- Exception handling
- Integration tests
The template is also available in GitHub. Let’s begin 🙂
Initial Setup
For this demonstration, I will write GraphQL mutations and queries to get user data. User has basic properties and one nested object for address.
To keep it simple, I did not use any databases. I will create users using mutation and store them in the memory.
I created a Spring Boot project using IntelliJ IDEA. I am using Spring Boot 3.3.4 and Java 21. But Java 17 should be enough too.