Skip to content

Practice GraphQL API with Node.js, Express, Apollo Server, Mongoose, Authentication, and Todo/User models — built as part of ITI's GraphQL course lab.

ZiadGamalDev/graphql-api-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL API Lab

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).


🧠 Features

  • 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-graphql for demo purposes
    • Type definitions & resolvers for User, Todo, and Auth

📁 File Structure Highlights

├── 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

🔐 Authentication

  • Uses JWT-based authentication with middleware
  • Only logged-in users can create/update/delete todos
  • Custom validation middleware for mutations

📄 Practice Tasks (from ITI Lab)

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 dataSource pattern in GraphQL

🧪 Sample GraphQL Queries

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

📦 Tech Stack

  • Backend: Node.js, Express
  • Database: MongoDB, Mongoose
  • GraphQL: Apollo Server, express-graphql
  • Auth: JWT

🚀 Getting Started

# Install dependencies
npm install

# Seed fake data (optional)
node src/db/seeders/db.seeder.js

# Run the GraphQL server
npm start

Then access:

  • Apollo Server Playground → http://localhost:3000/graphql
  • Express GraphQL (practice) → http://localhost:3000/graphql-express

📚 License

This project is for learning purposes, built as part of ITI coursework.

About

Practice GraphQL API with Node.js, Express, Apollo Server, Mongoose, Authentication, and Todo/User models — built as part of ITI's GraphQL course lab.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published