- Docker: Install Docker Desktop on your computer
- Apollo Graphql server
- Authentication with JWT. Uses HTTP read only cookies.
- Example (User) GraphQL schema and resolvers
- PostgreSQL for Data Store (Used in a docker container)
- sequelize-typescript project as ORM
- Dockerfile and docker-compose file to set up in dev environment
- Migrations with umzug from sequelize
Not the first time? Skip to How to run subsequently
- Pull this repository
- copy
.env.example
to.env
. You can changeJWT_SECRET
to any valid string (if you wish, it's not important on dev) - In
.env
modifyORIGINS
to add your Frontend Client URL like this
ORIGINS=https://studio.apollographql.com,[YOUR_URL]
- Still in
.env
changeSECURE=1
toSECURE=
in order to make requests from ahttp
non-secure URL, which your Frontend client may be. (To test with the Graphql Apollo client directly this needs to be equal to 1) - cd into the root directory run
docker-compose up --build -d
- After the docker-compose command, wait 1 min and navigate to
http://localhost:4001/graphql
and you can run your graphql queries there to test them directly. - If you see the graphql server interface then it means the api should be working, you can now make requests from your client but before that,
- Enable cookies in Apollo Studio, so visit
http://localhost:4001/graphql
, go to settings (Gear Icon) and click the cookie switch on:
- cd into the root directory run
docker-compose up --build -d
- cd into the root directory run
docker-compose down
docker system prune -a
is useful to run regularly to clean up unused containers and orphan images so they don't hog your memory.
There are scripts that handle migration.
To generate a migration file, run
yarn generate-migration [model-name] [action]
For example a real command could look like this:
yarn generate-migration order create
This file will be created in src/migrations
On development, migrations will automatically be run when you run the docker-compose up command in earlier steps.
After running the app, visit the the Graphql Server GUI, Click on Query your Server
and on the left, See Documentation
- For example to get a User, for a particular Id, and also handle errors, you have to pass this to the graphql URL
Query {
getUser(id: 1) {
... on Error {
message
}
... on User {
email, name
}
}
}
- Is something else running on port 4001? We need this port. You can change it of course, just make sure you use the right URLs then when trying to access this app :)
- Getting Cors Errors? Open Issue or PR