Practice TypeScript, GraphQL, TypeORM with Nest.
Nest framework TypeScript starter repository.
- The auth module implements JWT authentication.
- We handle the authentication at the "transportation layer", which is decoupled from the GraphQL "APIs".
- The Auth Module supports
Sign Up
andSign In
over REST APIs. - Every time a user signs in, he/she gets the
accessToken
which valid for and hour. - The user uses the
accessToken
to access the tweet module for both REST endpoints and the GraphQL endpoint.
Download and install Docker Desktop
Start PostgreSQL with docker-compose
docker-compose up -d
Setup the database
psql -h 127.0.0.1 -U postgres -c 'DROP DATABASE IF EXISTS tweet'
psql -h 127.0.0.1 -U postgres -c 'CREATE DATABASE tweet'
Install node and dependencies
npm install
Start the app
npm run start
We have a few tooling
- Postman
- curl
- GraphQL Playground http://localhost:3000/graphql
I've created a postman collection for both Auth Module
, and Tweet Module
We can use it to test both REST and GraphQL APIs.
The other option is to get the JWT using curl, and test with GraphQL Playground
- Import Postman collection
- Config environment variable for the
url
http://localhost:3000
- Sign up and then sign in. This will get an accessToken from the server, and saved for other APIs.
Sign up an user.
curl -X POST 'http://localhost:3000/auth/signup' \
-H 'Content-Type: application/json' \
-d '{
"username": "[email protected]",
"password": "O1X0l0bEPtXShuT"
}'
Sign in as the user
curl -X POST 'http://localhost:3000/auth/signin' \
-H 'Content-Type: application/json' \
-d '{
"username": "[email protected]",
"password": "O1X0l0bEPtXShuT"
}'
Response:
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkpvZXNwaDFAZXhhbXBsZS5vcmciLCJpYXQiOjE2MTk1MDIyMTUsImV4cCI6MTYxOTU4ODYxNX0.nsHLRrZlmVtoifNMaBJHm8HKTsMTJJpeN3M46pNi5pM"
}
Open the GraphQL Playground, and set the token in the HTTP header
Nest is MIT licensed.