Learn how to create a Graphql server using spring.
- Java 17.
Execute following commands to build and run the Graphql server.
# Build project & install dependencies
./gradlew build
# Run project
./gradlew bootRun
This project uses a H2 database that serves as a source for the Person object that will be exposed using Graphql, to include additional information to query you need to modify resources/data.sql file and include new INSERT statements.
By using a GraphQL client like Postman we will be able to query our API. GraphQl server endpoint will be available at http://localhost:8080/graphql .
Query examples:
- Query to obtain full Person object information
query personDetails {
personById(id: 1) {
id
name
lastName
gender
}
}
- Query to obtain just some attributes of Person object.
query personDetails {
personById(id: 1) {
id
name
}
}
And just like that we got only the attributes that we need from our API.