An example of GraphQL endpoint that leverages Springboot and JPA
Run ./gradlew build
Run ./gradlew bootRun
After starting the application, use postman to POST a request to the following url http://localhost:8080/graphql in a browser.
{
customer (id: "1") {
id
firstName
lastName
accounts {
id
name
balance
}
}
}
{
"customer": {
"id": "1",
"firstName": "Bob",
"lastName": "Johnson",
"accounts": [
{
"id": "1",
"name": "Bob's Checking Account",
"balance": 2100.5
},
{
"id": "2",
"name": "Bob's Savings Account",
"balance": 325.5
}
]
}
}
After starting application, use postman to request to the following URL http://localhost:8080/mutate in a browser
mutation M{
first : saveCoach(firstName : "Bob", lastName : "Customer"){
id
firstName
lastName
},
second : saveCoach(id : "22", firstName : "Sally", lastName : "Brown", accounts : [{accountId: "33", customerId: "22", accountName:"Sally Checking"},{accountId: "34", customerId: "22", accountName:"Sally Saving"}]){
id
firstName
lastName
accounts {
id
name
}
}
}
{
"customer": {
"id": "1",
"firstName": "Bob",
"lastName": "Johnson",
"accounts": [
{
"id": "1",
"name": "Bob's Checking Account"
},
{
"id": "2",
"name": "Bob's Savings Account"
}
]
}
}
{
allCustomers {
id
firstName
lastName
accounts {
id
name
balance
}
}
}
{
"allCustomers": [
{
"id": "1",
"firstName": "Bob",
"lastName": "Johnson",
"accounts": [
{
"id": "1",
"name": "Bob's Checking Account",
"balance": 2100.5
},
{
"id": "2",
"name": "Bob's Savings Account",
"balance": 325.5
}
]
},
{
"id": "2",
"firstName": "Sally",
"lastName": "Brown",
"accounts": [
{
"id": "3",
"name": "Sally's Checking Account",
"balance": 500.5
},
{
"id": "4",
"name": "Sally's Savings Account",
"balance": 5555.5
}
]
}
]
}