Skip to main content

Crate typewriter_graphql

Crate typewriter_graphql 

Source
Expand description

§typewriter-graphql

GraphQL Schema Definition Language (SDL) emitter for the typewriter type sync SDK. Generates .graphql type definitions, enums, and unions from Rust structs and enums.

§Type Mappings

Rust TypeGraphQL Type
StringString
boolBoolean
u8, u16, u32, i8, i16, i32Int
f32, f64Float
UuidID
DateTime<Utc>DateTime (custom scalar)
Option<T>Nullable (no !)
Vec<T>[T!]
HashMap<K, V>JSON (custom scalar)

§Configuration

In typewriter.toml:

[graphql]
output_dir = "./generated/graphql"
file_style = "snake_case"   # snake_case (default), kebab-case, or PascalCase

§Example

Rust Input:

#[derive(TypeWriter)]
#[sync_to(graphql)]
pub struct User {
    pub id: String,
    pub email: String,
    pub age: Option<u32>,
}

Generated GraphQL SDL:

scalar DateTime
scalar JSON

type User {
  id: ID!
  email: String!
  age: Int
}

Structs§

GraphQLMapper
GraphQL SDL language mapper.