graphql-codegen-rust 0.1.0

Generate Rust ORM code from GraphQL schemas
Documentation
# ⚖️ Tool Comparisons

Understanding how GraphQL Rust Codegen fits into the GraphQL ecosystem and compares to similar tools.

## 🏆 vs Cynic (Rust GraphQL Client)

**Cynic** is the closest Rust competitor - a type-safe GraphQL client library.

| Aspect | GraphQL Rust Codegen | Cynic |
|--------|---------------------|-------|
| **Core Purpose** | Database-first ORM generation | Client-first API consumption |
| **Generated Code** | Database entities & migrations | Query builders & response types |
| **Runtime Dependencies** | Diesel/Sea-ORM | HTTP client + cynic runtime |
| **Architecture Pattern** | Offline-first data persistence | Real-time API communication |
| **Performance Profile** | Compile-time codegen, native DB access | Runtime query execution, network calls |
| **Tauri Integration** | Native database layer | Requires additional HTTP setup |

### When to Choose Each

**Choose GraphQL Rust Codegen when:**
- Building offline-first applications
- Need local data persistence and caching
- Want type-safe database operations
- Developing desktop/mobile apps with Tauri

**Choose Cynic when:**
- Building traditional web clients
- Need real-time GraphQL subscriptions
- Focus on API consumption patterns
- Developing server-to-server integrations

**Best Together:** Use Cynic for API communication and GraphQL Rust Codegen for local data storage.

## 🌐 vs GraphQL Code Generator (JavaScript/TypeScript)

**GraphQL Code Generator** is the most popular GraphQL code generator, powering thousands of web applications.

| Aspect | GraphQL Rust Codegen | GraphQL Code Generator |
|--------|---------------------|------------------------|
| **Language Ecosystem** | Rust native | JavaScript/TypeScript |
| **Generated Output** | Database ORM code | Client types & React hooks |
| **Offline Capability** | ✅ Built-in persistence | ❌ Requires external storage |
| **Database Integration** | ✅ Native multi-ORM support | ❌ No database code |
| **Build Integration** | Cargo ecosystem | Webpack/Vite ecosystem |
| **Runtime Performance** | Native compiled speed | JavaScript runtime overhead |
| **Tauri Compatibility** | ✅ Seamless integration | ⚠️ Requires FFI bindings |

### Architectural Differences

**GraphQL Code Generator** excels at:
- Frontend type safety
- React/Vue/Angular integration
- Plugin ecosystem for UI frameworks
- Development server integration

**GraphQL Rust Codegen** excels at:
- Backend data persistence
- Cross-platform desktop apps
- High-performance data operations
- Offline-first architectures

**Complementary Use:** Many teams use both - GraphQL Code Generator for the frontend, GraphQL Rust Codegen for Tauri backends.

## 🗄️ vs Hasura (GraphQL Engine)

**Hasura** is a GraphQL engine that auto-generates APIs from databases.

| Aspect | GraphQL Rust Codegen | Hasura |
|--------|---------------------|---------|
| **Architecture** | Code generation tool | Runtime GraphQL server |
| **Database Role** | Generates code from GraphQL schemas | GraphQL API over existing databases |
| **Deployment Model** | Build-time codegen | Runtime server process |
| **Customization Level** | Full code control | Configuration-based |
| **Performance** | Native Rust compiled | Node.js runtime |
| **Offline Support** | ✅ Local database copies | ❌ Requires network |
| **Development Workflow** | Code generation + compilation | Configuration + deployment |

### Different Approaches to the Same Problem

**Hasura** provides:
- Instant GraphQL APIs over databases
- Real-time subscriptions
- Role-based access control
- Admin UI for database management

**GraphQL Rust Codegen** provides:
- Type-safe Rust database code
- Offline data synchronization
- Native performance
- Full control over data layer

**Choose Hasura for:** Rapid API development, multi-client applications, real-time features.
**Choose GraphQL Rust Codegen for:** Desktop applications, offline functionality, performance-critical data operations.

## 🔧 vs gqlgen (Go)

**gqlgen** is Go's premier GraphQL library for both client and server development.

| Aspect | GraphQL Rust Codegen | gqlgen |
|--------|---------------------|--------|
| **Language** | Rust | Go |
| **Primary Use** | Database code generation | Full-stack GraphQL development |
| **Server Support** || ✅ Built-in server generation |
| **Client Support** | ❌ (see Cynic) | ✅ Client code generation |
| **ORM Integration** | ✅ Multiple ORMs | ⚠️ Requires additional setup |
| **Performance** | Native compiled | Native compiled |
| **Ecosystem Maturity** | Growing | Mature enterprise adoption |

## 📊 vs Prisma (TypeScript/Node.js)

**Prisma** is a modern ORM and database toolkit for TypeScript.

| Aspect | GraphQL Rust Codegen | Prisma |
|--------|---------------------|---------|
| **Language Focus** | Rust | TypeScript |
| **GraphQL Integration** | ✅ Schema-driven generation | ⚠️ Requires additional setup |
| **Database Support** | SQLite, PostgreSQL, MySQL | PostgreSQL, MySQL, SQLite, SQL Server |
| **Migration System** | ✅ Automatic SQL generation | ✅ Advanced migration toolkit |
| **Runtime Performance** | Native Rust speed | Node.js overhead |
| **Type Safety** | Compile-time guarantees | Runtime + build-time checks |
| **Offline Capability** | ✅ Built-in | ⚠️ Requires additional libraries |

### Performance Comparison

```rust
// GraphQL Rust Codegen - Compile-time optimized
let users = users::table
    .filter(users::active.eq(true))
    .load::<User>(&conn)?;

// Prisma - Runtime query building
const users = await prisma.user.findMany({
  where: { active: true }
});
```

## 🎯 Decision Framework

### Choose GraphQL Rust Codegen if you:

- ✅ Are building with **Rust and Tauri**
- ✅ Need **offline-first functionality**
- ✅ Want **native database performance**
- ✅ Require **type-safe data operations**
- ✅ Are developing **desktop or mobile applications**

### Choose Alternatives if you:

- 🔄 Need **real-time subscriptions** → Hasura or GraphQL Code Generator
- 🌐 Are building **web applications** → GraphQL Code Generator + Prisma
- 🚀 Want **rapid API development** → Hasura
- 📱 Are using **different languages** → Language-specific alternatives

## 🔄 Migration Paths

### From GraphQL Code Generator
If you're using GraphQL Code Generator for a Tauri app:

1. Keep your existing frontend codegen
2. Add GraphQL Rust Codegen for the backend
3. Use shared YAML configuration
4. Implement data synchronization patterns

### From Hasura
If you have a Hasura setup but need offline capabilities:

1. Export your GraphQL schema
2. Generate Rust database code
3. Implement sync logic between Hasura API and local database
4. Use Rust code for offline operations

## 🚀 Future Convergence

As the offline-first ecosystem grows, we may see more convergence between these tools. GraphQL Rust Codegen is designed to complement rather than compete with existing solutions, focusing on the unique challenges of local data persistence in modern applications.

---

💡 **Not sure which tool to choose?** Consider your primary use case: if it's **local data management and offline functionality**, GraphQL Rust Codegen is likely your best choice.