spring-kotlin-gql-gae
This is a sample skeleton of a backend app that was built using:
This app can be deployed on Google AppEngine Flex environment with a Google Cloud SQL(MySQL) database.
Getting Started
Running Locally
This section will cover the changes you will need to make to run the project locally.
Clone the project
After cloning the project open it using your favourite IDE. I recommend you InteliJ by Jetbrains
🚨
) Important Step
Install Mysql ( Mac OS) (Install mysql on your machine using homebrew and create a database. I found this post very useful and with all of the information you will need to do that. Note: Remember to record the USER_NAME, PASSWORD and DATABASE_NAME you will create. You will need it later.
Installation TLDR; ( Do the following on your terminal)
brew install mysql
brew services start mysql
mysql_secure_installation
mysql.server start
mysql -u root -p
mysql> CREATE DATABASE <DATABASE_NAME>;
mysql> CREATE USER '<USER>'@'localhost' IDENTIFIED BY '<PASSWORD>';
mysql> GRANT ALL PRIVILEGES ON <DATABASE_NAME>.* TO '<USER>'@'localhost';
mysql> exit
Configure the Database Connection on the project
- Open the project then the file **application.yml). The file is located at src/main/resources/application.yml
- Edit the spring configuration for the dev profile by adding the information about how to connect to your database
spring:
config:
activate:
on-profile: dev
r2dbc:
initialization-mode: always
url: r2dbc:mysql://localhost:3306/<DATABASE_NAME>
username: <USER>
password: <PASSWORD>
Run the application
You can run the application by executing the main function inside the SampleApplication.kt file or by executing the bootRun task that can be accessible through the tasks panel of your IDE if you are using InteliJ.
As it is mentioned on this page, after running the application you will get the following default routes:
Your newly created GraphQL server starts up with following preconfigured default routes:
/graphql - GraphQL server endpoint used for processing queries and mutations /subscriptions - GraphQL server endpoint used for processing subscriptions /sdl - Convenience endpoint that returns current schema in Schema Definition Language format /playground - Prisma Labs GraphQL Playground IDE endpoint
Go to playground and test
If all of your configurations are correct, you should now be able to have the GraphQL explorer by typing the following address on your browser: ***http://localhost:8080/playground.
This will open a Graphql IDE which will allow you to execute your GraphQL Operations and see your schema documentation.
Here are some of the things you can do with what we have setup now:
Create an Account
mutation CreateAccount($input: CreateAccountInput!) {
createAccount(input: $input){
account {
firstName
lastName
email
createdAt
id
}
}
}
*Load an account by Id
query GetAccount($id: ID!) {
account(id: $id) {
firstName
lastName
email
createdAt
}
}
Building your own schema
To build your own schema I recommend you follow the documentation that can be found here. I found that part of the process very clear and as a result I see no need of repeating the steps here.