A simple GraphQL API built with Node.js, TypeScript, Apollo Server, and PostgreSQL.
- Node.js - JavaScript runtime
- TypeScript - Type-safe JavaScript
- Express 5 - Web framework
- Apollo Server 5 - GraphQL server
- pg - PostgreSQL client for Node.js
- GraphQL - Query language and runtime
- GraphQL Tools - Schema merging and file loading utilities
- GraphQL Scalars - Custom scalar types (EmailAddress, PhoneNumber)
- Jest - Testing framework
- ts-node - TypeScript execution for Node.js
- nodemon - Development server with auto-reload
- @faker-js/faker - Test data generation
- Node.js (v18 or higher recommended)
- npm or yarn
- Docker and Docker Compose (for running PostgreSQL)
npm installStart PostgreSQL using Docker Compose:
docker-compose up -dThis will start a PostgreSQL container with the following default configuration:
- Host: localhost
- Port: 5432
- User: postgres
- Password: password
- Database: graphqldemo
Create a .env file in the root directory (optional, defaults are used if not provided):
POSTGRES_USER=postgres
POSTGRES_HOST=localhost
POSTGRES_DB=graphqldemo
POSTGRES_PASSWORD=password
POSTGRES_PORT=5432npm run buildRun the application in development mode with auto-reload:
npm run devThe server will start at http://localhost:4000/graphql
Build and run the compiled JavaScript:
npm run build
npm startOnce the server is running, you can access the GraphQL Playground at:
- URL:
http://localhost:4000/graphql
Tests require a separate test database. The test setup will automatically create test databases, but you need to ensure PostgreSQL is running.
npm testnpm run test:watchnpm run test:coveragenpm test tests/api/register.test.ts