This is a full-stack e-commerce application with a modern GraphQL architecture for learning purposes. Its showcases a production-ready app including type-safe resolvers, efficient data fetching, real-time subscriptions, and comprehensive error handling.
- GraphQL API: Apollo Server 4.x with TypeScript
- Database: PostgreSQL with Prisma 5.x ORM
- Authentication: JWT-based auth with httpOnly cookies
- Payments: Stripe integration
- Real-time: GraphQL Subscriptions
- Framework: Next.js 15 with React 18
- GraphQL Client: Apollo Client 3.x with React Hooks
- Styling: Styled Components 6.x
- Type Safety: TypeScript with GraphQL Code Generator
- Containerization: Docker & Docker Compose
- Deployment: Vercel (frontend), Railway/Render (backend)
- Development: Hot reload, type checking, linting
- Schema-First Design: Well-defined GraphQL schema with proper type definitions
- Efficient Resolvers: Optimized database queries with Prisma, preventing N+1 problems
- Type Safety: End-to-end type safety from database to frontend using TypeScript and code generation
- Error Handling: Comprehensive error handling with GraphQL error extensions
- Authentication: Secure JWT-based authentication with permission-based authorization
- Real-time Capabilities: GraphQL subscriptions for live updates (cart, orders, etc.)
- Query Optimization: Field-level resolvers with data loader pattern
- Input Validation: Zod-based validation for mutations
- ποΈ Product Catalog: Browse, search, and filter items with pagination
- π Shopping Cart: Add/remove items with real-time updates
- π³ Checkout: Secure payment processing with Stripe
- π€ User Management: Registration, authentication, password reset
- π Role-Based Access: Permission system (ADMIN, USER, ITEMCREATE, etc.)
- π¦ Order Management: View order history and details
- π¨ Modern UI: Responsive design with smooth animations
The application follows a clean, modular GraphQL schema structure:
type Query {
items(where: ItemWhereInput, orderBy: ItemOrderByInput, skip: Int, first: Int): [Item]!
item(where: ItemWhereUniqueInput!): Item
itemsConnection(where: ItemWhereInput): ItemConnection!
me: User
users: [User]!
}
type Mutation {
createItem(title: String, description: String, price: Int, image: String): Item!
updateItem(id: ID!, title: String, description: String, price: Int): Item!
deleteItem(id: ID!): Item
signup(email: String!, password: String!, name: String!): User!
signin(email: String!, password: String!): User!
addToCart(id: ID!): CartItem
removeFromCart(id: ID!): CartItem
createOrder(token: String!): Order!
# ... more mutations
}- Forwarding Resolvers: Simple queries forwarded directly to Prisma
- Custom Resolvers: Complex business logic with proper error handling
- Context-Based Auth: User authentication via request context
- Permission Checks: Field and operation-level permission validation
Prisma schema with proper relationships:
model User {
id String @id @default(uuid())
name String
email String @unique
password String
permissions Permission[]
cart CartItem[]
orders Order[]
# ... more fields
}
model Item {
id String @id @default(uuid())
title String
description String
price Int
image String?
user User @relation(fields: [userId], references: [id])
# ... more fields
}- Node.js 20+ and npm/yarn
- Docker and Docker Compose (for local development)
- PostgreSQL (or use Docker)
- Stripe account (for payments)
-
Clone the repository
git clone <repository-url> cd reactjs-graphql-practice
-
Set up environment variables
cp backend/.env.example backend/.env cp frontend/.env.example frontend/.env.local
Edit the
.envfiles with your configuration:- Database connection string
- JWT secret
- Stripe keys
- Email service credentials
-
Start services with Docker Compose
docker-compose up -d
This will start:
- PostgreSQL database
- GraphQL API server (port 4000)
- Frontend development server (port 3000)
-
Run database migrations
cd backend npm run prisma:migrate npm run prisma:generate -
Access the application
- Frontend: http://localhost:3000
- GraphQL Playground: http://localhost:4000/graphql
- Prisma Studio:
npm run prisma:studio(in backend directory)
-
Backend Setup
cd backend npm install npm run prisma:generate npm run dev -
Frontend Setup
cd frontend npm install npm run dev
query GetItems($skip: Int, $first: Int) {
items(skip: $skip, first: $first, orderBy: createdAt_DESC) {
id
title
description
price
image
user {
name
}
}
itemsConnection {
aggregate {
count
}
}
}mutation CreateItem($title: String!, $description: String!, $price: Int!) {
createItem(
title: $title
description: $description
price: $price
) {
id
title
price
}
}mutation SignIn($email: String!, $password: String!) {
signin(email: $email, password: $password) {
id
name
email
permissions
}
}# Backend tests
cd backend
npm test
# Frontend tests
cd frontend
npm test
# Run all tests
npm run test:all- Connect your GitHub repository to Vercel
- Configure environment variables in Vercel dashboard
- Deploy automatically on push to main branch
- Connect your repository
- Set up PostgreSQL database
- Configure environment variables
- Deploy
- Schema Design: Clear, intuitive schema with proper naming conventions
- Resolver Efficiency: Optimized queries with Prisma, avoiding N+1 problems
- Error Handling: Meaningful error messages with proper error codes
- Type Safety: End-to-end TypeScript types from schema to components
- Security: Authentication and authorization at resolver level
- Performance: Field-level resolvers, query complexity analysis
- Documentation: Self-documenting schema with descriptions
- Testing: Comprehensive test coverage for resolvers and components
- JWT authentication with httpOnly cookies
- Password hashing with bcrypt
- Input validation and sanitization
- Permission-based access control
- CORS configuration
- SQL injection prevention (Prisma)
.
βββ backend/ # GraphQL API server
β βββ src/
β β βββ schema/ # GraphQL schema and resolvers
β β βββ lib/ # Utilities (Prisma, auth, etc.)
β β βββ middleware/ # Express/Apollo middleware
β βββ prisma/ # Prisma schema and migrations
β βββ Dockerfile
βββ frontend/ # Next.js application
β βββ src/
β β βββ app/ # Next.js pages
β β βββ components/ # React components
β β βββ graphql/ # GraphQL queries/mutations
β β βββ lib/ # Utilities (Apollo Client, etc.)
β βββ Dockerfile
βββ docker-compose.yml # Local development setup
βββ README.md
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This project is designed as a comprehensive GraphQL learning resource, demonstrating:
- GraphQL schema design and best practices
- Apollo Server setup and configuration
- Prisma ORM integration with GraphQL
- Apollo Client usage in React applications
- Type-safe GraphQL development
- Real-world authentication and authorization
- Payment integration patterns
- Testing GraphQL APIs and React components
For questions or feedback, please open an issue on GitHub.
Built with β€οΈ using GraphQL, React, and modern web technologies
