Spring streaming response made easy
In this short article, we'll get into stream large size of data through stream as an alternative to the traditional endpoints.
Wed, 10th September 2025
Read MoreBlossoming Intelligence: How to Run Spring AI Locally with Ollama
In this short article, we'll look at how easy it is to create a chat bot backend powered by Spring and Olama using the llama 3 model.
Sat, 11th May 2024
Read MoreThis article is the first step towards using GraphQL inside a Spring application.
But first, let's know more about GraphQL. According to Red Hat, GraphQL is a query language and server-side runtime for application programming interfaces (APIs) that focuses on providing clients with only the information they need.
GraphQL was created with the goal of making APIs that are quick, versatile, and developer-friendly. It may even be used within the GraphiQL integrated development environment (IDE). GraphQL, a REST alternative, allows developers to create queries that pull data from various sources in a single API call.
Additionally, GraphQL allows API administrators to add or remove fields without affecting existing queries. Developers may use any techniques they choose to create APIs, and the GraphQL definition will ensure that they work consistently for clients.
The project we'll be building is a simple school/student find all endpoint — only this time using GraphQL which allows us to change and mutate our response data structure.
The student will have an id, name, email, and school, each school has an id and a name.
Now we created our controllers for the student and for the school with a simple findAll
endpoint, starting with the student's:
The school controller will be similar to the student's:
And of course, we need our GraphQL schema to be set, inside the resources folder we created another name graphql which contains a file under the name schema.graphqls (resources>graphql>schema.graphqls).
The schema should look like this:
Finally to the results! You can use the GraphiQL interface on http://localhost:8080/graphiql.
Let's try and retrieve the list of students only showing their names:
Now, let's have them by id, name, and email:
Let's add their schools to the results:
Also, we can retrieve the schools:
And of course, we can retrieve students
and schools
with the same query:
GraphQL is a significant benefit for any project due to its result manipulation; this is simply the first step toward GraphQL usage under the Spring umbrella!
Kindly, find the source code in my GitHub Repository here.