This repo contains the starter code for the a serverless graphql backend.
Note: The steps mentioned below is for ubuntu. For MAC as well it should remain same as ubuntu. But for windows some things might change. I haven't tested for the windows yet.
- Docker
- Docker Compose
- NodeJS
- First clone the repo
- After cloning run below command
yarn install
- Now run below command
docker volume create --name=local-development-pg-volume
OR
sudo docker volume create --name=local-development-pg-volume
- And now run below command
docker-compose up
OR
sudo docker-compose up
- Finally run below command to start the dev server
yarn dev
Open http://localhost:3000/dev/playground and you will be able to access the graphql playground.
The backend is built as a serverless architecture.
We are using a framework https://www.serverless.com/
It helps us deploy and upload our code easily to AWS Lambada.
It utilizes AWS cloudformation to create required resources on AWS.
The file serverless.yml
in the root folder contains the
- GraphQL
- Apollo
- AWS Lambada
- serverless.com
- NodeJS
- AWS RDS PostGrace
To run the the local development environment we are using a plugin called serverless-offline
.
This allows us to simulate a lambada function execution.
AWS cloudformation deploy the required stacks. OAll of the code is stored in s3. The AWS Lambada then references that code.
- Make sure to add all the environment variables in the circle ci dashboard.
- Also add all of the environment variables in the
serverless.yml
file under the provider environment section.
- For all db operations make a file with the same name as the table and do all of the operations in it. All those files currently are in
core
folder - All of the table names should be singular. Just because "user" keyword is reserved in PostGres I have named our one table "users" to avoid any confusion with the served keyword. Make sure to name all other tables singular
- All of the data validation, authentication and autherization login should be in the graphql resolver.
- All of the data stored in the DB will be in snake case
- All requests and responses data to client will be in the snake case.
- Any unused variables should start with
_
Like below.
async (_parent, _args, ctx, info) => {
const user = ctx.assertAuthenticated();
const results = await User.findById(ctx, user.id);
return results[0];
},