This project is a GraphQL-based API built using Node.js, Express, Apollo Server, and MongoDB. It implements core GraphQL features for practicing concepts like type definitions, resolvers, mutations, authentication, and nested relationships.
💡 Built as part of the GraphQL Course Lab at the Information Technology Institute (ITI).
-
User Authentication
- Register, Login with JWT
- Protect private queries using middleware
-
Todos Management
- Users can create, update, delete their todos
- Get all todos or specific todo by ID
- Nested query: fetch all todos by a specific user
-
GraphQL Setup
- Uses both Apollo Server and
express-graphqlfor demo purposes - Type definitions & resolvers for
User,Todo, andAuth
- Uses both Apollo Server and
├── src/
│ ├── db/ # MongoDB connection, seeders, models
│ ├── modules/ # Modular structure (auth, user, todo)
│ ├── middleware/ # Authentication, validation
│ └── app.js # Main app entry
├── practice/ # Additional GraphQL server demo setups
├── public/
│ └── GraphQL-Lab.pdf # Lab instructions from ITI
├── index.js
└── .env- Uses JWT-based authentication with middleware
- Only logged-in users can create/update/delete todos
- Custom validation middleware for mutations
See GraphQL-Lab.pdf for full instructions. Key tasks included:
- Implement user/todo schema and models
- Create CRUD GraphQL queries and mutations
- Handle authentication and protect routes
- Implement nested resolver to get all todos by a user
- Bonus: Explore
dataSourcepattern in GraphQL
# Register User
mutation {
register(name: "Ziad", email: "ziad@example.com", password: "123456") {
token
user {
id
name
}
}
}
# Create Todo
mutation {
addTodo(title: "Finish GraphQL lab") {
id
title
user {
name
}
}
}- Backend: Node.js, Express
- Database: MongoDB, Mongoose
- GraphQL: Apollo Server, express-graphql
- Auth: JWT
# Install dependencies
npm install
# Seed fake data (optional)
node src/db/seeders/db.seeder.js
# Run the GraphQL server
npm startThen access:
- Apollo Server Playground →
http://localhost:3000/graphql - Express GraphQL (practice) →
http://localhost:3000/graphql-express
This project is for learning purposes, built as part of ITI coursework.