This repo contains the starter code for the a serverless graphql backend.
- 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.
- VERY IMPORTANT: Make sure to keep the node version less then 15
- Docker
- Docker Compose
- NodeJS V < 15
- 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.
- 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 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];
},
- For Node version more then 15 serverless-offline has issues and the started graphql server won't work properly. Make sure to keep the NodeJS version less then 15. Here's [dherault/serverless-offline#1150] the detail discussion about this issue. As due to post request not working properly with the Node version more then 15 the graphql server won't be able to connect to playgroud or apollo sandbox studio.