Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jawherkl/graphql-nodejs-ecom
A GraphQL-based e-commerce API built with Node.js for efficient product, order, and user management.
https://github.com/jawherkl/graphql-nodejs-ecom
express graphql nodejs
Last synced: 2 days ago
JSON representation
A GraphQL-based e-commerce API built with Node.js for efficient product, order, and user management.
- Host: GitHub
- URL: https://github.com/jawherkl/graphql-nodejs-ecom
- Owner: JawherKl
- Created: 2024-09-30T15:03:55.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-01-17T15:55:26.000Z (25 days ago)
- Last Synced: 2025-01-17T16:49:54.986Z (25 days ago)
- Topics: express, graphql, nodejs
- Language: JavaScript
- Homepage:
- Size: 92.8 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Project: **E-Commerce GraphQL API**
#### Core Features:
1. **Product Management**:
- Query: Fetch a list of products with filtering, sorting, and pagination options.
- Mutation: Add, update, or delete a product.
- Fields: `id`, `name`, `description`, `price`, `category`, `stock`, `images`.2. **User Authentication**:
- Mutation: Register a user, log in, and log out.
- Query: Fetch the current authenticated user's details.
- Fields: `id`, `username`, `email`, `token`.3. **Shopping Cart**:
- Query: Fetch items in the cart for the authenticated user.
- Mutation: Add an item to the cart, remove an item, update quantities.
- Fields: `id`, `productId`, `quantity`, `price`.4. **Orders**:
- Query: Fetch a user’s order history.
- Mutation: Create an order (checkout).
- Fields: `id`, `products`, `total`, `status`, `createdAt`.5. **Reviews**:
- Query: Fetch reviews for a product.
- Mutation: Add, edit, or delete a review.
- Fields: `id`, `userId`, `productId`, `rating`, `comment`, `createdAt`.#### Advanced Features:
1. **Real-Time Updates**:
- Subscription: Notify users about product stock updates or order status changes.2. **Dynamic Pricing**:
- Query: Calculate discounts or special offers dynamically during checkout.3. **Recommendations**:
- Query: Fetch product recommendations based on user purchase history.#### Tech Stack:
- **Node.js**: Backend runtime.
- **Apollo Server**: GraphQL implementation for building the API.
- **MongoDB**: Database for storing products, users, orders, and reviews.
- **JWT**: Authentication and authorization.#### Folder Structure:
```
graphql-nodejs-ecommerce/
├── src/
│ ├── schema/
│ │ ├── typeDefs.js # Define GraphQL schema
│ │ └── resolvers.js # Implement resolvers
│ ├── models/
│ │ ├── Product.js
│ │ ├── User.js
│ │ ├── Order.js
│ │ └── Review.js
│ ├── services/
│ │ ├── authService.js
│ │ └── productService.js
│ └── index.js # Entry point
├── package.json
└── .env
```### Testing the Application:
Run the following mutations/queries in Apollo Studio or Postman to test:#### **Register a User**
```graphql
mutation {
register(name: "Jhon Doe", email: "[email protected]", password: "securepassword", role: "admin") {
user {
id
name
role
}
token
}
}
```#### **Login a User**
```graphql
mutation {
login(email: "[email protected]", password: "securepassword") {
user {
id
name
}
token
}
}
```#### **Create a Product**
Include the token in the header (`Authorization: Bearer `):
```graphql
mutation {
createProduct(name: "Product A", description: "Description A", price: 19.99) {
id
name
price
}
}
```
### Command Execution:
`npm install``npm run start` or
`npm run dev` or
`npm run test`