A GraphQL server with Spring Boot and MySQL
- Used Java 11 and Import maven project into Eclipse.
- Set Server port in Application.properties file.
- Set Data Source Url in Application.properties file.
- Set Data Source Username and Data Source Password in Application.properties file.
Reference link
https://www.baeldung.com/lombok-ide
- /graphql is the REST resource which can fetch information and Modify data
Request body for Create User with Custom Input
QUERY
mutation createUser($req: UserInput) {
createUser(input: $req) {
userId
firstName
lastName
dob
address
postId
}
}
GRAPHQL VARIABLES
{
"req" : {
"firstName": "test2",
"lastName": "test2",
"dob": "1997-07-11",
"address": "testaddress"
}
}
Query
query {
getAllUsers{
userId
firstName
address
}
}
QUERY
mutation {
updateUserAddress(userId: 1,address: "testaddress1") {
userId
firstName
lastName
address
}
}
QUERY
mutation createPost($req: PostInput) {
createPost(input: $req) {
postId
postName
dateCreated
}
}
GRAPHQL VARIABLES
{
"req" : {
"postName": "posttest",
"dateCreated": "2021-06-07"
}
}
QUERY
query {
getAllPosts{
postId
postName
dateCreated
}
}