This repo contains a simple Spring Boot (2.x) service that implements GraphQL API. The implementation is based on graphql-java-tools a GraphQL java library.
mvn clean install
Graphql Endpoint: http://localhost:8080/api
Graphiql Endpoint: http://localhost:8080/graphiql
H2 database console: http://localhost:8080/h2-console
Query to retrieve all people. Also, info about the pagination is returned.
query getPersons {
persons {
info {
count
pages
size
total
}
results {
id
firstName
lastName
age
}
}
}
Response:
{
"data": {
"persons": {
"info": {
"count": 4,
"pages": 1,
"size": 1000,
"total": 4
},
"results": [
{
"id": "1",
"firstName": "Joe",
"lastName": "Briggs",
"age": 23
},
{
"id": "2",
"firstName": "John",
"lastName": "Smith",
"age": 44
},
{
"id": "3",
"firstName": "Steve",
"lastName": "Jones",
"age": 16
},
{
"id": "4",
"firstName": "Tom",
"lastName": "Richards",
"age": 67
}
]
}
}
}
Get people ordered by firt name on descendent:
query getPersons {
persons(orderBy:[LAST_NAME_DESC]) {
info {
count
pages
size
total
}
results {
id
firstName
lastName
age
}
}
}
Response:
{
"data": {
"persons": {
"info": {
"count": 4,
"pages": 1,
"size": 1000,
"total": 4
},
"results": [
{
"id": "4",
"firstName": "Tom",
"lastName": "Richards",
"age": 67
},
{
"id": "3",
"firstName": "Steve",
"lastName": "Jones",
"age": 16
},
{
"id": "2",
"firstName": "John",
"lastName": "Smith",
"age": 44
},
{
"id": "1",
"firstName": "Joe",
"lastName": "Briggs",
"age": 23
}
]
}
}
}
Get people filtered by age.
{
persons(filter: {age: 16}) {
results {
id
firstName
lastName
age
}
}
}
Response:
{
"data": {
"persons": {
"results": [
{
"id": "3",
"firstName": "Steve",
"lastName": "Jones",
"age": 16
}
]
}
}
}
Get people paging in size 2, return page 2.
{
persons(page:2, size: 2) {
results {
firstName
age
}
}
}
Response:
{
"data": {
"persons": {
"results": [
{
"firstName": "Steve",
"age": 16
},
{
"firstName": "Tom",
"age": 67
}
]
}
}
}
Create a new person
mutation {
newPerson(firstName: "Jose", lastName: "Palma", age:39) {
id
}
}
Response:
{
"data": {
"newPerson": {
"id": "5"
}
}
}