This project is basic an implementation of java-graphql-springboot microservice.
###TODO: Needs to expose rest controllers.
- Clone the project
git clone https://github.com/singh523/java-graphql-springboot.git- Service having an implementation with Liquibase and you just need to create a schema testgraphql in your local mysql database and apply the changes for database username & password in application.yaml file.
spring:
datasource:
url: jdbc:mysql://localhost:3306/testgraphql
username: xxxx
password: xxxx@xxxx- Build & Run
mvn clean install
mvn spring-boot:runOnce the service is running, you should be able to run the graphql queries via browser.
Access URL in a browser http://localhost:8080/graphiql Below is an example to fetch employees & departments, you should be able to add required fields in input query and the respective fields will be returned in a response:
{
employees {
id
firstName
department {
id
name
}
}
}Response:
{
"data": {
"employees": [
{
"id": "1",
"firstName": "John",
"department": {
"id": "1",
"name": "Test1"
}
},
{
"id": "2",
"firstName": "Adam",
"department": {
"id": "1",
"name": "Test1"
}
},
{
"id": "3",
"firstName": "Tracy",
"department": {
"id": "1",
"name": "Test1"
}
},
{
"id": "4",
"firstName": "Lucy",
"department": {
"id": "2",
"name": "Test2"
}
},
{
"id": "5",
"firstName": "Peter",
"department": {
"id": "4",
"name": "Test4"
}
},
{
"id": "6",
"firstName": "Alan",
"department": {
"id": "4",
"name": "Test4"
}
},
{
"id": "7",
"firstName": "Pamela",
"department": {
"id": "4",
"name": "Test4"
}
}
]
}
}