GraphQL + PostgreSQL
This codebase is a GraphQL + PostgreSQL boilerplate. It is intended to be used as a
Booster for my Launchpad.
However, that being said, it can still be used completely on its own.
Starting the fully-fledged backend is as simple as running the commands below.
sh setup.sh
make database
make server
Command | Description |
---|---|
make database |
Launches the database container |
make server |
Launches the server container |
make down |
Removes the database + server containers |
make nuke |
Purges all database + server containers, images, networks, volumes |
make bash |
Shells into the server to run one-off commands. e.g. npm run test:e2e |
Command | Description | ||
---|---|---|---|
npm run build |
Bundles the app into a single build folder |
||
npm run prod |
Runs the built server on $PORT | 7002 (must run npm run build first) |
|
npm run dev |
Runs the server with hot reloading on $PORT | 7000 | |
npm run test |
Runs the entire suite of unit and end-to-end tests | ||
npm run test:e2e |
Runs the suite of end-to-end tests | ||
npm run test:unit |
Runs the suite of unit tests | ||
npm run db:seed |
Seeds the database with dummy data | ||
npm run db:wipe |
Drops the database and all its data | ||
npm run db |
Generates a migration file with all SQL queries needed to update the database | ||
npm run db |
Creates an empty migration file for you to fill in | ||
npm run db |
Executes all pending migrations | ||
npm run db |
Reverts the most recently executed migration | ||
npm run db |
Shows all migrations and whether they’ve been run or not |
Environment variables are injected into the app at runtime. To add a new environment variable, you will need to update
the following files:
Please note the environment variables in each of these places are only used when running the app locally. If you are
deploying this app, it is expected you specify env vars on the hosted server and reference them in
google-cloud-build/build.yaml and
google-cloud-build/promote.yaml. See deployment.
Migrations are located in the migrations folder. To create a migration, run either of the following
commands:
npm run db
create -- -n <name>
—> This will create an empty migration file ready for you to populatenpm run db
generate -- -n <name>
—> This will create a migration file and write all SQL queries needed toWhen creating and running migrations, it’s a very good idea to stop your dev server if it’s running. Since the server
runs with syncronize
on in dev mode, it will automatically try to update your schema as you change your code. Which
can be very frustrating as you’re trying to test out your migrations.
Code released under the MIT License