Production-ready GraphQL API built with Apollo Server 4, Prisma ORM, and PostgreSQL. Features JWT authentication, cursor-based pagination, comments system, and Docker deployment.
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.
| 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 |
| 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 |
# 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 devServer runs at http://localhost:4000 🚀
docker-compose up --buildThis starts the API + PostgreSQL database together.
# 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 }
}
}# 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 }
}
}src/
├── resolvers/ # GraphQL resolvers (Query, Mutation)
├── schema/ # GraphQL type definitions
├── services/ # Business logic layer
├── utils/ # JWT helpers, context, validation
└── index.ts # Server entry point
# 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 } } } }"}'- FastAPI Tasks — REST API with FastAPI
- TS Design Patterns — Design patterns
- React Kanban — Kanban board UI
MIT — Ready for learning and production use.
Built with ❤️ by Mohammad