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.
- Sentry: an error tracking and monitoring tool.
- 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.
Play with a deployed version of this API: https://fastify-prisma.up.railway.app/altair
The database schema is defined using the Prisma schema which defines 3 models:
- User
- Post
- Comment
The GraphQL schema is defined with Nexus using the code-first approach.
The relevant files are:
- ./src/schema.ts: Source of truth for the schema in TypeScript
- ./schema.graphql: Generated GraphQL scehma
- A PostgreSQL DB
- clone repo
- create
.env
file and defineDATABASE_URL
andSENTRY_DSN
npm install
npm run migrate:dev
to run shcema migrations with Prisma Migratenpm run dev
to start dev server and run the API