Starter kit for quick start with Typescript, Lerna, GraphQL and MongoDB locally and deploy to AWS Lambda + MongoDB Shared Cloud using Actions.
Checkout GraphQL with Playground deployed to AWS Lambda with MongoDB Cloud Shared:
https://rb7zk6fsce.execute-api.us-east-1.amazonaws.com/dev/graphql
Query example:
# Write your query or mutation here
query {
users {
id
email
name
__typename
}
}
π€πͺπ€£πβ€
- Demo
- Table of Contents
- Technologies used
- Bootstrap lerna environment
- Run project locally with MongoDB in Docker Compose
- Build Prisma Client library
- Run sample code
- Prisma Studio
- MongoDB Cloud Shared (M0 clusters) configuration
- Deploy to AWS Lambda
- Connect project to Serverless Dasard
Prisma - Next-generation Node.js and TypeScript ORM with GraphQL interface
MongoDB - JSON document database
Typescript - JavaScript with syntax for types
Lerna - A tool for managing JavaScript projects with multiple packages
GraphQL - query language for APIs and a runtime for fulfilling those queries with your existing data
Parcel.js - Parcel is a zero configuration build tool for the web. It combines a great out-of-the-box development experience with a scalable architecture that can take your project from just getting started to massive production application
Docker Compose - tool for defining and running multi-container Docker applications. Its used in this project to run MongoDB database in dev environment locally. Prisma Client requires Mongo to run in replica mode, so standalone MondoDB Community Server is not enough
Actions - makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from
npx lerna bootstrap
It will generate Prisma Client automatically with npm postinstall script. When you modify your schema and want to test locally, then follow steps in Build Prisma Client library
You will have a complete local development experience with debug and live reload using MongoDB in Docker and Prisma Client in serverless offline mode.
docker-compose up -d
npx lerna run --parallel start-dev
or inside packages/api
npm run start-dev
GraphQL Playground: http://localhost:3000/dev/graphql
With Lerna (Manually):
npx lerna run build-lib
Or from inside packages/prisma-client package you can use it directly:
npm run build-lib
or run in live-reload mode (Automatic):
npx lerna run start-dev
start-dev
- you can run this script within some specific package, if you want live reload only for this one.
npx ts-node index.ts
start-dev
script starting it Automatically, if you want to run it manually, then Inside packages/prisma-client directory run this:
npx prisma studio
You will have to add the infamous 0.0.0.0/0 CIDR block to your MongoDB Atlas cluster IP Whitelist because you wonβt know which IP address AWS Lambda is using to make calls to your Atlas database.
I'm using Actions as CI/CD tool to deploy using Serverless Framework to AWS Lambda. But you can easily adjust it for any other CI/CD tool you prefer. Checkout ./workflows/node.js.yml for details.
It requires secrets to be added to project Actions configuration (Repository / Settings / Secrets / Actions):
PROD_AWS_ACCESS_KEY_ID
PROD_AWS_SECRET_ACCESS_KEY
AWS security keys. Read here
PROD_DATABASE_URL
MongoDB connection string. Get it from MongoDB Cloud admin (you can use any plan)
Warning Execute deploy commands below only if you know what you are doing and want to deploy it manually (temporary staging environment, for example, or demo purposes), then crete .env.local and override DATABASE_URL with your own and run this:
npx lerna deploy
or inside packages/prisma-client
npx serverless deploy
npx serverless
π€πͺπ€£πβ€