Production endpoint: https://petbook-back.herokuapp.com/graphql
Development endpoint: https://petbook-back-dev.herokuapp.com/graphql
Interactive API (dev environment only)
- A. Prerequisites
- B. Setup
- C. Debug
- D. Test
- E. Log DB queries
- F. Obtaining Cloudinary API key
- G. Common issues
- NodeJS > v10 https://nodejs.org/en/download/
- IDE is up to your preference, but VS Code is recommended https://code.visualstudio.com/download
only if running with docker:
- Docker https://docs.docker.com/get-docker/
- Docker Compose https://docs.docker.com/compose/install/
- Install npm libraries with
npm install
command (if not installed previously). - Copy and rename
database.env.sample
todatabase.env
.POSTGRES_USER
,POSTGRES_PASSWORD
,POSTGRES_DB
can be adjusted to your liking, but the default configuration will work as well. - Copy and rename
common.env.sample
tocommon.env
. Create a cloudinary account and replace theCLOUDINARY_URL
variable or SetCLOUDINARY_DISABLED=true
- Make sure Docker is running.
- Run
docker-compose up -d
- Download the latest supported version of PostgreSQL https://www.postgresql.org/download/
e.g. Windows 7 and 8 support PostgreSQL version 10
- Install PostgreSQL, take note of the password and port you've chosen during the installation.
You might have to restart your PC after the installation is complete
- Start pgAdmin and connect to your server using the password you've chosen (should be visible under Servers dropdown on the left)
- Create a new user:
- Right click "Login/Group Roles" and select Create > Login/Group Role.
- Under the "General" tab, set the Name field (e.g. "backend"). Take note of the value you have chosen.
- Under the "Definition" tab, set the Password field (e.g. "example"). Take note of the value you have chosen.
- Under the "Privileges" tab, enable "Can login?".
- Click "Save".
- Create a new database:
- Right click "Databases" and select Create > Database.
- Under the "General" tab, set the Name field (e.g. "gis"). Take note of the value you have chosen.
- Click "Save".
- Upload data to tables:
- Right click on the database entry you've just created and select "Query Tool"
- Grant privileges to your new user:
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO username_from_step_4
; - Import SQL from
/database
folder in the number order (e.g. 1-schema.sql first, then 2-..., 3-..., etc.):- Click on the little folder icon inside the query tool
- Choose the file (e.g. "1-schema.sql") and click Select
- Click the execute button to run the query.
- Copy and rename
database.env.sample
todatabase.env
. Replace thePOSTGRES_USER
,POSTGRES_PASSWORD
,POSTGRES_DB
with the values you've set in the steps 4 and 5. ChangePOSTGRES_HOST
tolocalhost
- Copy and rename
common.env.sample
tocommon.env
. Create a cloudinary account and replace theCLOUDINARY_URL
variable or SetCLOUDINARY_DISABLED=true
- Run
npm install
andnpm run dev-dockerless-win
if on windows ornpm run dev-dockerless
- Check http://localhost:8081/graphql.
Run docker-compose -f docker-compose.yml -f docker-compose-debug.yml up -d
Tests run integration tests of the GraphQL service
To be able to test GraphQL queries, have your node server and database running locally as described in [B. Setup]. Then simply hit npm test
When changing or writing new interfaces for validation, generate the validator, e.g. npx typescript-json-validator test/interfaces/animal.interface.ts Animal
https://github.com/ForbesLindesay/typescript-json-validator
By default tests will hit the default local backend http://localhost:8081
. If you wish to change the URL of the backend, add a .env
file in test
directory with such contents
TEST_URL=<URL>
Add command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"]
to docker-compose.yml under db
configuration
- Register on https://cloudinary.com/users/register/free
- Sign In
- Go to your dashboard
- Copy the api environment variable:
Usually happens when new node modules are added. npm install
is done on dockerfile build. To solve:
- Remove the previously compiled docker image
docker image rm pets-back_gis-backend
. - Run
docker-compose up -d
. This will force the dockerfile to be recompiled without cache
I have made changes to the SQL files inside /database folder. What do I do to make those changes appear in my database?
- Stop docker containers
docker-compose down
- Search for the correct volume
docker volume list
DRIVER VOLUME NAME
local pets-back_database-data
- Delete the volume
docker volume rm pets-back_database-data
- Run
docker-compose up
to start the stack - Check if the are no SQL errors
- Login to pgAdmin
- Open "Query Tool" for your database
- Execute file .github/workflows/nuke_database.sql
- Repeat step 6. from the setup without docker section
Front-End repository https://github.com/pets-oss/pets-front
Started by Kayak WeCanCode Academy 2021 @ Kaunas