# 🚀 Modern GraphQL API with Hono, Drizzle & Cloudflare Workers
A high-performance, edge-ready GraphQL API built with Hono, GraphQL Yoga, and Drizzle ORM, deployed on Cloudflare Workers with D1 Database.
- Edge Computing: Deployed on Cloudflare Workers for global low-latency.
- Type-Safe ORM: Uses Drizzle ORM for robust SQLite (D1) interactions.
- GraphQL Yoga: Full-featured GraphQL server with GraphiQL IDE.
- Efficient Querying: Optimized resolvers with Drizzle's
.get()and.all(). - Relationship Management: Cascade deletes for Users, Games, and Reviews.
- Error Handling: Custom global error handling and typed GraphQL errors.
- Runtime: Cloudflare Workers
- Framework: Hono
- GraphQL: GraphQL Yoga
- Database: Cloudflare D1 (SQLite)
- ORM: Drizzle ORM
- Language: TypeScript
- Node.js (v16.13.0 or higher)
- npm
- Wrangler CLI (
npm install -g wrangler)
-
Clone the repository
git clone https://github.com/Amro145/GraphQL-API.git
-
Install dependencies
npm install
-
Setup D1 Database (Local) Generate migrations and apply them locally:
npx drizzle-kit generate npx wrangler d1 execute my_db_graphql --local --file=drizzle/0000_typical_chronomancer.sql # Apply subsequent migrations as needed -
Run Development Server
npm run dev
The API will be available at
http://localhost:8787/graphql.
The project uses three main tables:
- Users:
id,name,email - Games:
id,name,description,price,platform(JSON) - Reviews:
id,rating,comment,userId(FK),gameId(FK)
Access the GraphiQL Playground at /graphql to explore the schema.
users: Fetch all users.user(id: Int!): Fetch a single user by ID.games: Fetch all games.game(id: Int!): Fetch a single game by ID.reviews: Fetch all reviews.review(id: Int!): Fetch a review by ID.
- Create:
addUser(name: String!, email: String!): User!addGame(name: String!, description: String!, price: Int!, platform: [String!]!): Game!addReview(rating: Int!, comment: String!, gameId: Int!, userId: Int!): Review!
- Update:
updateGame(id: Int!, input: EditGameInput!): Game!
- Delete:
deleteUser(id: Int!): User!(Cascades to reviews)deleteGame(id: Int!): Game!(Cascades to reviews)deleteReview(id: Int!): Review!
-
Login to Cloudflare
npx wrangler login
-
Deploy to Cloudflare Workers
npm run deploy
-
Apply Migrations to Remote D1
npx wrangler d1 execute my_db_graphql --remote --file=drizzle/xxxx_migration.sql
Contributions are welcome! Please fork the repository and submit a pull request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.