This repo shows how to build a GraphQL server with TypeScript and the following technologies:
- Fastify: Fast and low overhead web framework, for Node.js
- Mercurius: GraphQL adapter for Fastify
- Nexus: Declarative, Code-First GraphQL Schemas for JavaScript/TypeScript
- Prisma: Next-generation ORM for type-safe interaction with the database
- PostgreSQL: powerful, open source object-relational database system with over 30 years of active development.
- Altair GraphQL: GraphQL Web Client (similar to GraphQL Playground)
The project is written in TypeScript and attempts to maintain a high degree of type-safety by leveraging Prisma and GraphQL.
- cp
./dotenv/test.env
./dotenv/.env
- Include
DATABASE_URL
DATABASE_URL="postgresql://<user>:<password>@<url>:5432/postgres?schema=<scheme>"
Note that you should change appropriate values in
user
,password
,url
,scheme
fields. Or you can even use other database. More about connection urls - Running
yarn start
oryarn dev
will loadenv
fromdotenv/.env
.
yarn generate
- Change models in
schema.prisma
.Note that
prisma/migrations
dir is included in.gitignore
in this repo but it should not be ignored in production. - Run migration script.
Note that this should be targeting the production database. Locally, you can just run
yarn db-push
.yarn migrate
- Deploy migration to production.
Note you may want to run
yarn migrate:dev
beforhand to test your migration.yarn migrate:deploy
➜ ~ createuser --interactive --pwprompt
Enter name of role to add: test
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y