First of all, the GraphQL API created using the following technology stack:
As per my own convention, I would like to explore new technology by implementing address book application with the following database schema:
The application is currently running live in AWS lambda with MySQL database. You can test it out by sending HTTP POST request with the following GraphQL query in JSON to https://39nx6hi1ac.execute-api.ap-southeast-1.amazonaws.com/Prod/graphql:
{ "query":"{ findById(id: 27) { lastName firstName gender age } }" } |
Please make sure the JSON above is send in one line, I formatted it here for ease of read. If you are not sure what tool to use, I'm using Postman.
You will get the following JSON response:
{ "data": { "findById": { "lastName": "Lim", "firstName": "Chee Kin", "gender": "MALE", "age": 40, } } } |
Next, you can further extend the query to include fields of master-detail data:
{ "query":"{ findById(id: 27) { lastName firstName gender age contacts {id type value} } }" } |
You will get the following JSON response:
{ "data": { "findById": { "lastName": "Lim", "firstName": "Chee Kin", "gender": "MALE", "age": 40, "contacts": [ { "id": 28, "type": "MOBILE_NUMBER", "value": "+60123456789" }, { "id": 29, "type": "WORK_NUMBER", "value": "+604567890" }, { "id": 30, "type": "EMAIL_ADDRESS", "value": "test@test.com" } ] } } } |
The source code of the application is hosted in the Github repository at https://github.com/limcheekin/micronaut-person/tree/graal-data-jpa-2.0.x.
It is continuous build to native app using GraalVM in Docker container and deploy by Github Actions to AWS Lambda custom runtime.
The blog post only scratch the surface of the GraphQL API, kindly let me know if you are interested to find out more on how the API is created, how the continuous deployment with Github Actions works, how to create the AWS API Gateway and AWS Lambda custom runtime, etc. I will write a dedicated blog post for each topic.
I'd love to hear from you! :)
Updated on Dec 23: If GraalVM is new to you and you're curious on the reasons I go for GraalVM, please check out the well-written article at DZone.