- Install
Node.js
.
brew install node
- Install PostgreSQL and initial.
# Load package (this line is used according to your computer's situation)
brew tap homebrew/core
# Recommended installation method
brew install postgresql@15
# Check version
psql -V 或者 psql --version
# Add environment variables
echo 'export PATH="/usr/local/opt/postgresql@15/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
# Start PostgreSQL service
brew services start postgresql@15
# Create user and initialize password
createuser postgres -P
# Create Database
createdb toguDb -O postgres -E UTF8 -e
# Connection
psql -h 127.0.0.1 -p 5432 -U postgres -d postgres
OR if you want to use docker To run a PostgreSQL database locally:.
- Run
yarn
initialize the package required for the project.
npm install -g yarn
yarn install
- Create
api/.env
file.
echo "DATABASE_URL=postgresql://postgres:TOUGU_ADMIN@localhost:5432/toguDb" >> .env
echo "JWT_SECRET=hello_tougu" >> .env
# Migrate local database
cd prisma/touguDb
npx prisma generate
npx prisma migrate reset
- Start server.
yarn start
Now you can see it on: http://localhost:4000/graphql
Operation:
mutation CreateUser($input: CreateUserInput!) {
createUser(input: $input) {
token
}
}
Variables:
{
"input": {
"email": "admin@tougu.com",
"password":"tougu_admin",
"displayName": "admin",
"mobile": "0412 345 678",
"realName": "tougu_master",
"ref": "admin"
}
}
Running the following query to get a token
query AuthenticUser($email: String!, $password: String!) {
authenticUser(email: $email, password: $password) {
token
}
}
{
"email": "admin@tougu.com",
"password": "tougu_admin"
}
Running an example query like:
query GetUsers {
getUsers {
id
email
}
}
And put your token in Headers as:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTY5NzMyMzgwOCwiZXhwIjoxNjk3MzY3MDA4fQ.Xo4xASTWtz_I3-jAv5l-DGk9LDCy6RxkwMCmKtCGEd4
- Install docker locally: https://www.docker.com/get-started
- Pull the PostgreSQL Image:
docker pull postgres
- Run a PostgreSQL Container:
docker run --name togudb -e POSTGRES_PASSWORD=TOUGU_ADMIN -e POSTGRES_DB=toguDb -p 5432:5432 -d postgres
- Wait for the Container to Start and check the container's status:
docker ps
- Download a DBeaver: https://dbeaver.io/download/, connect your db using DBeaver by using the following config:
Host: localhost
Port: 5432
Database: toguDb
Username: postgres
Password: TOUGU_ADMIN
- (optional). Stop and remove the container: (you need to run step 3 again once you remove it):
docker stop togudb
docker rm togudb