pub struct GraphQLMapper {
pub file_style: FileStyle,
}Expand description
GraphQL SDL language mapper.
Generates GraphQL Schema Definition Language types from Rust structs and enums.
§Type Mappings
| Rust | GraphQL |
|---|---|
struct | type TypeName { ... } |
| Simple enum | enum TypeName { ... } |
| Data-carrying enum | union TypeName = ... + variant types |
String | String |
bool | Boolean |
u8–u32, i8–i32 | Int |
f32, f64 | Float |
u64, i64 etc. | String (BigInt not in GraphQL spec) |
Option<T> | nullable (no !) |
Vec<T> | [T!] |
HashMap<K,V> | JSON (custom scalar) |
Uuid | ID |
DateTime | DateTime (custom scalar) |
JsonValue | JSON (custom scalar) |
Fields§
§file_style: FileStyleFile naming style (default: snake_case)
Implementations§
Source§impl GraphQLMapper
impl GraphQLMapper
pub fn new() -> Self
pub fn with_file_style(self, style: FileStyle) -> Self
Trait Implementations§
Source§impl Default for GraphQLMapper
impl Default for GraphQLMapper
Source§impl TypeMapper for GraphQLMapper
impl TypeMapper for GraphQLMapper
Source§fn map_primitive(&self, ty: &PrimitiveType) -> String
fn map_primitive(&self, ty: &PrimitiveType) -> String
Map a Rust primitive type to the target language’s equivalent. Read more
Source§fn map_option(&self, inner: &TypeKind) -> String
fn map_option(&self, inner: &TypeKind) -> String
Map an
Option<T> type to the target language. Read moreSource§fn map_vec(&self, inner: &TypeKind) -> String
fn map_vec(&self, inner: &TypeKind) -> String
Map a
Vec<T> type to the target language. Read moreSource§fn map_hashmap(&self, _key: &TypeKind, _value: &TypeKind) -> String
fn map_hashmap(&self, _key: &TypeKind, _value: &TypeKind) -> String
Map a
HashMap<K, V> type to the target language. Read moreSource§fn map_tuple(&self, _elements: &[TypeKind]) -> String
fn map_tuple(&self, _elements: &[TypeKind]) -> String
Map a tuple type
(A, B, ...) to the target language.Source§fn map_named(&self, name: &str) -> String
fn map_named(&self, name: &str) -> String
Map a named custom type (reference to another struct or enum). Read more
Source§fn emit_struct(&self, def: &StructDef) -> String
fn emit_struct(&self, def: &StructDef) -> String
Render a complete struct as target language source code.
Source§fn emit_enum(&self, def: &EnumDef) -> String
fn emit_enum(&self, def: &EnumDef) -> String
Render a complete enum as target language source code.
Source§fn file_header(&self, type_name: &str) -> String
fn file_header(&self, type_name: &str) -> String
File header content (auto-generated comment, import statements, pragmas).
Source§fn file_extension(&self) -> &str
fn file_extension(&self) -> &str
File extension for the output file (without the leading dot).
Source§fn emit_imports(&self, def: &TypeDef) -> String
fn emit_imports(&self, def: &TypeDef) -> String
Generate import statements for types referenced by this type definition. Read more
Source§fn file_naming(&self, type_name: &str) -> String
fn file_naming(&self, type_name: &str) -> String
Naming convention for output files. Read more
Source§fn map_generic(&self, name: &str, _params: &[TypeKind]) -> String
fn map_generic(&self, name: &str, _params: &[TypeKind]) -> String
Map a generic type
Name<A, B> to the target language. Read moreFile footer content (if needed). Default: empty.
Source§fn map_type(&self, ty: &TypeKind) -> String
fn map_type(&self, ty: &TypeKind) -> String
Map any
TypeKind to the target language string. Read moreSource§fn emit_type_def(&self, def: &TypeDef) -> String
fn emit_type_def(&self, def: &TypeDef) -> String
Emit a complete
TypeDef (struct or enum) as target language source code. Read moreSource§fn output_filename(&self, type_name: &str) -> String
fn output_filename(&self, type_name: &str) -> String
Get the full output filename for a type.
Auto Trait Implementations§
impl Freeze for GraphQLMapper
impl RefUnwindSafe for GraphQLMapper
impl Send for GraphQLMapper
impl Sync for GraphQLMapper
impl Unpin for GraphQLMapper
impl UnsafeUnpin for GraphQLMapper
impl UnwindSafe for GraphQLMapper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more