High-performance GraphQL APIs powered by Rust and Cloudflare Workers.
juniper-graphql-worker combines the speed and safety of Rust with the global edge network of Cloudflare Workers to deliver a lightning-fast GraphQL API. This project uses the Juniper GraphQL library for Rust, Axum for HTTP routing, and the Cloudflare Workers platform for serverless deployment.
- Serverless
- Rust Performance
- GraphQL API
- Interactive Tools
- Type Safety
- Modular Design
- Websocket Subscriptions (Planned) - (A Cloudflare-specific Websocket implementation is required)
Bun manages the wrangler dependency and provides task execution. Source code for this project is written in Rust and targets
wasm32-unknown-unknown
.
-
Clone the repository
git clone https://github.com/geoffsee/juniper-graphql-worker.git cd juniper-graphql-worker
-
Install dependencies
bun i
-
Start the development server
bun dev
-
Navigate to
http://localhost:3000/playground
to interact with the GraphQL API
Optional: Deploy this api to the internet
bunx wrangler deploy
src/
lib.rs
- Main application entry point and server setupcontext.rs
- GraphQL context setupdatabase.rs
- Database connection and operationsmodels.rs
- GraphQL object and input type definitionsschema.rs
- GraphQL schema with queries and mutations
This GraphQL API implements a Star Wars-themed data model. Here's an example query:
query {
human(id: "1") {
id
name
homePlanet
appearsIn
}
}
And an example mutation:
mutation {
createHuman(
newHuman: {
name: "Han Solo",
homePlanet: "Corellia",
appearsIn: [NEWHOPE, EMPIRE, JEDI]
}
) {
id
name
homePlanet
}
}
Deploy to Cloudflare Workers:
bunx wrangler deploy
To extend the schema with new models:
- Add model definitions in
src/models.rs
- Add new queries and mutations in
src/schema.rs
Note: Your approach will vary based on your requirements.
Rust's efficiency combined with Cloudflare's edge network provides:
- Low latency responses
- Minimal cold starts
- Global distribution
- Small binary size
- Rust - Systems programming language
- Juniper - GraphQL server library for Rust
- Axum - Web framework for Rust
- Cloudflare Workers - Serverless edge computing platform
- Wrangler - CLI tool for Cloudflare Workers
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your 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
- Juniper - GraphQL server library for Rust
- Axum - Web application framework for Rust
- Cloudflare Workers - Serverless platform
Created by Geoff Seemueller