Skip to content

ibadeeCodes/nestjs-graphql-server

Repository files navigation

NestJS GraphQL Apollo Server

A robust task management API built using NestJS, GraphQL (Apollo Server), and TypeORM with PostgreSQL.

🚀 Features

  • GraphQL API: Code-first approach using @nestjs/graphql and @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.

🛠️ Tech Stack

  • Framework: NestJS
  • API Type: GraphQL (Apollo Server)
  • ORM: TypeORM
  • Database: PostgreSQL
  • Language: TypeScript

📋 Prerequisites

⚙️ Project Setup

  1. Clone the repository (or navigate to the directory).
  2. Install dependencies:
    npm install
  3. Database Configuration: Update the TypeOrmModule.forRoot configuration in src/app.module.ts with 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
    })

🏃 Running the Application

# Development mode (watch)
npm run start:dev

# Production mode
npm run start:prod

The server will be available at: http://localhost:3005

🔍 Exploring the API

Once the server is running, you can access the Apollo Sandbox (GraphQL Playground) at: 👉 http://localhost:3005/graphql

Sample Queries

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
    }
  }
}

🏗️ Project Structure

src/
 ├── users/             # User module (Entity, Service, Resolver)
 ├── todos/             # Todo module (Entity, Service, Resolver, DTOs)
 ├── app.module.ts      # Main application module
 └── main.ts            # Entry point

📜 License

This project is MIT licensed.

nestjs-graphql-server

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors