Skip to content

About

⚡ Production-ready GraphQL API built with Apollo Server 4, Prisma ORM, and PostgreSQL. Features JWT authentication, cursor-based pagination, comments system, and Docker support.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Node GraphQL API — Apollo Server + Prisma + PostgreSQL ⚡

Production-ready GraphQL API built with Apollo Server 4, Prisma ORM, and PostgreSQL. Features JWT authentication, cursor-based pagination, comments system, and Docker deployment.

Node.js TypeScript GraphQL Prisma PostgreSQL Docker


📋 Overview

This is a production-ready GraphQL API that demonstrates modern backend development with Node.js, TypeScript, and Prisma ORM. It includes user authentication, posts with comments, cursor-based pagination, and is fully Dockerized.

Perfect for learning GraphQL, building a blog backend, or as a starter template for your next API project.


✨ Features

Feature Description
🔐 JWT Authentication Register, login, and protected routes
📝 Posts CRUD Create, update, delete posts with ownership
💬 Comments System Comment on posts with author tracking
📄 Cursor Pagination Efficient pagination for large datasets
🗄️ Prisma ORM Type-safe database access with migrations
🐳 Docker Ready PostgreSQL + API in Docker Compose
📚 GraphQL Playground Interactive API explorer at /graphql
🏗️ Modular Architecture Clean separation of concerns

🛠️ Tech Stack

Technology Purpose
Apollo Server 4 GraphQL server
Prisma ORM Database access & migrations
PostgreSQL Primary database
JWT Authentication
bcrypt Password hashing
Docker Containerization
TypeScript Type safety

🚀 Quick Start

# Clone & install
git clone https://github.com/mmdverse/node-graphql-api.git
cd node-graphql-api
npm install

# Set up environment
cp .env.example .env

# Run database migrations
npx prisma migrate dev

# Start the server
npm run dev

Server runs at http://localhost:4000 🚀


🐳 Docker Setup

docker-compose up --build

This starts the API + PostgreSQL database together.


📖 GraphQL API

Queries

# Get paginated posts
query GetPosts {
  posts(first: 10) {
    edges {
      node {
        id
        title
        content
        author { username }
        comments { text author { username } }
      }
      cursor
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

# Get single post
query GetPost($id: ID!) {
  post(id: $id) {
    title
    content
    author { username }
    comments { text }
  }
}

# Get current user
query Me {
  me {
    id
    username
    email
    posts { title }
  }
}

Mutations

# Register new user
mutation Register {
  register(input: { email: "user@example.com", username: "user", password: "pass123" }) {
    token
    user { id email username }
  }
}

# Create a post
mutation CreatePost {
  createPost(input: { title: "Hello World", content: "My first post!" }) {
    id
    title
    createdAt
  }
}

# Add comment
mutation CreateComment {
  createComment(input: { text: "Great post!", postId: "post-id-here" }) {
    id
    text
    author { username }
  }
}

📁 Project Structure

src/
├── resolvers/       # GraphQL resolvers (Query, Mutation)
├── schema/          # GraphQL type definitions
├── services/        # Business logic layer
├── utils/           # JWT helpers, context, validation
└── index.ts         # Server entry point

🧪 Example Usage

# Register
curl -X POST http://localhost:4000/graphql \
  -H "Content-Type: application/json" \
  -d '{"query": "mutation { register(input: { email: \"test@test.com\", username: \"test\", password: \"pass123\" }) { token } }"}'

# Get posts (authenticated)
curl -X POST http://localhost:4000/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"query": "{ posts(first: 10) { edges { node { title } } } }"}'

🔗 Related Projects


📄 License

MIT — Ready for learning and production use.


Built with ❤️ by Mohammad

ساخته شده با ❤️ توسط Mohammad | 📱 تلگرام

About

⚡ Production-ready GraphQL API built with Apollo Server 4, Prisma ORM, and PostgreSQL. Features JWT authentication, cursor-based pagination, comments system, and Docker support.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages