Skip to main content

typewriter_graphql/
lib.rs

1//! # typewriter-graphql
2//!
3//! GraphQL Schema Definition Language (SDL) emitter for the typewriter type sync SDK.
4//! Generates `.graphql` type definitions, enums, and unions from Rust structs and enums.
5//!
6//! ## Type Mappings
7//!
8//! | Rust Type | GraphQL Type |
9//! |-----------|--------------|
10//! | `String` | `String` |
11//! | `bool` | `Boolean` |
12//! | `u8`, `u16`, `u32`, `i8`, `i16`, `i32` | `Int` |
13//! | `f32`, `f64` | `Float` |
14//! | `Uuid` | `ID` |
15//! | `DateTime<Utc>` | `DateTime` (custom scalar) |
16//! | `Option<T>` | Nullable (no `!`) |
17//! | `Vec<T>` | `[T!]` |
18//! | `HashMap<K, V>` | `JSON` (custom scalar) |
19//!
20//! ## Configuration
21//!
22//! In `typewriter.toml`:
23//!
24//! ```toml
25//! [graphql]
26//! output_dir = "./generated/graphql"
27//! file_style = "snake_case"   # snake_case (default), kebab-case, or PascalCase
28//! ```
29//!
30//! ## Example
31//!
32//! **Rust Input:**
33//! ```rust,ignore
34//! #[derive(TypeWriter)]
35//! #[sync_to(graphql)]
36//! pub struct User {
37//!     pub id: String,
38//!     pub email: String,
39//!     pub age: Option<u32>,
40//! }
41//! ```
42//!
43//! **Generated GraphQL SDL:**
44//! ```graphql
45//! scalar DateTime
46//! scalar JSON
47//!
48//! type User {
49//!   id: ID!
50//!   email: String!
51//!   age: Int
52//! }
53//! ```
54
55mod emitter;
56mod mapper;
57
58pub use mapper::GraphQLMapper;