A robust task management API built using NestJS, GraphQL (Apollo Server), and TypeORM with PostgreSQL.
- GraphQL API: Code-first approach using
@nestjs/graphqland@nestjs/apollo. - Users & Todos: Full CRUD operations for users and their associated todos.
- Database Integration: Data persistence using TypeORM and PostgreSQL.
- Relationships: One-to-Many relationship between Users and Todos.
- Framework: NestJS
- API Type: GraphQL (Apollo Server)
- ORM: TypeORM
- Database: PostgreSQL
- Language: TypeScript
- Node.js (v16+)
- PostgreSQL database running locally or remotely.
- Clone the repository (or navigate to the directory).
- Install dependencies:
npm install
- Database Configuration:
Update the
TypeOrmModule.forRootconfiguration insrc/app.module.tswith your PostgreSQL credentials:TypeOrmModule.forRoot({ type: 'postgres', host: 'localhost', port: 5432, username: 'your_username', password: 'your_password', database: 'nestjs-graphql', autoLoadEntities: true, synchronize: true, // Set to false in production })
# Development mode (watch)
npm run start:dev
# Production mode
npm run start:prodThe server will be available at: http://localhost:3005
Once the server is running, you can access the Apollo Sandbox (GraphQL Playground) at:
👉 http://localhost:3005/graphql
Get all users with their todos:
query {
users {
id
name
email
todos {
title
completed
}
}
}Create a new user:
mutation {
createUser(name: "John Doe", email: "john@example.com") {
id
name
}
}Create a todo for a user:
mutation {
createTodo(input: { title: "Learn NestJS", userId: 1 }) {
id
title
user {
name
}
}
}src/
├── users/ # User module (Entity, Service, Resolver)
├── todos/ # Todo module (Entity, Service, Resolver, DTOs)
├── app.module.ts # Main application module
└── main.ts # Entry point
This project is MIT licensed.