Boilerplate for a Node, Prisma, and GraphQL backend using Todo as an example entity.
MIT License. This is something I've used in production before with success that I found useful for quickly bootstrapping GraphQL APIs. You can fork and clone this without giving me any credit for anything.
If you like it, you can star the repo ⭐️ or follow me on GitHub.
Feel free to make an issue or PR if you want to suggest ideas / fixes.
This configuration is a backend GraphQL API boilerplate with the following pieces:
- Docker as the container service to run your postgres server without installing postgres
- Node.js (Long-Term-Support Version) as the run-time environment to run JavaScript
- Express.js as the server framework / controller layer
- GraphQL as the query language for your API, and a server-side runtime for running queries
- Yoga as a lightweight GraphQL server
- Prisma as an ORM that works well with Node.js and Typescript
- Pothos a plugin based GraphQL schema builder for Typescript
- ESLint a linter for your code editor
- Prettier an opinionated code formatter
- Download and install Docker Desktop or Linux equivalent
- Clone/fork the repo, navigate to it in your terminal and run
pnpm install
- Define POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD and DATABASE_URL in an .env file within the root directory. Read more about these variables here
//example .env file contents
POSTGRES_DB="todolistapp"
POSTGRES_USER="username"
POSTGRES_PASSWORD="password"
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?schema=public"
- Run
docker-compose up
to start the container for your postgres server - Server is accessible at http://localhost:8000. You can change the PORT in
server.ts
- In a new tab, run
pnpm prisma generate
which uses the contents ofschema.prisma
to generate your Prisma Client - Prisma comes with Prisma Studio, a GUI to read and manipulate data in your database from the browser. Run
pnpm prisma studio
to open