pub struct CodeGenerator { /* private fields */ }
Expand description
High-level interface for generating Rust ORM code from GraphQL schemas.
The CodeGenerator
provides a unified API for generating code regardless of the
underlying ORM (Diesel or Sea-ORM). It handles the complete code generation
pipeline: schema introspection, parsing, and code emission.
§ORM Support
- Diesel: Generates table schemas, entity structs, and database migrations
- Sea-ORM: Generates entity models, active records, and migration files
§Example
use graphql_codegen_rust::{CodeGenerator, Config};
use graphql_codegen_rust::cli::{OrmType, DatabaseType};
let config = Config {
url: "https://api.example.com/graphql".to_string(),
orm: OrmType::Diesel,
db: DatabaseType::Postgres,
output_dir: "./generated".into(),
..Default::default()
};
let generator = CodeGenerator::new(&config.orm);
generator.generate_from_config(&config).await?;
Implementations§
Source§impl CodeGenerator
impl CodeGenerator
Sourcepub fn new(orm: &OrmType) -> Self
pub fn new(orm: &OrmType) -> Self
Creates a new code generator for the specified ORM type.
§Parameters
orm
: The ORM to generate code for (Diesel or Sea-ORM)
§Returns
A configured CodeGenerator
ready to produce ORM code.
§Example
use graphql_codegen_rust::{CodeGenerator, cli::OrmType};
let generator = CodeGenerator::new(&OrmType::Diesel);
Sourcepub async fn generate_from_config(&self, config: &Config) -> Result<()>
pub async fn generate_from_config(&self, config: &Config) -> Result<()>
Generates complete ORM code from a GraphQL configuration.
This method orchestrates the full code generation pipeline:
- Introspects the GraphQL schema from the configured endpoint
- Parses the schema into an internal representation
- Generates ORM-specific code (entities, migrations, schemas)
- Writes generated files to the configured output directory
§Parameters
config
: Complete configuration including GraphQL endpoint, ORM type, database settings, and output preferences
§Returns
Ok(())
on successful code generationErr(anyhow::Error)
with detailed context on failure
§Errors
This method can fail due to:
- Network issues when accessing the GraphQL endpoint
- Authentication failures (invalid headers)
- Schema parsing errors (invalid GraphQL schema)
- File system errors (permission issues, disk space)
- Code generation constraints (unsupported GraphQL types)
§Example
use graphql_codegen_rust::{CodeGenerator, Config};
use graphql_codegen_rust::cli::{OrmType, DatabaseType};
let config = Config {
url: "https://api.example.com/graphql".to_string(),
orm: OrmType::Diesel,
db: DatabaseType::Postgres,
output_dir: "./generated".into(),
..Default::default()
};
let generator = CodeGenerator::new(&config.orm);
generator.generate_from_config(&config).await?;
Auto Trait Implementations§
impl Freeze for CodeGenerator
impl !RefUnwindSafe for CodeGenerator
impl !Send for CodeGenerator
impl !Sync for CodeGenerator
impl Unpin for CodeGenerator
impl !UnwindSafe for CodeGenerator
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