pub struct CodeGenerator { /* private fields */ }Expand description
Code generator.
Implementations§
Source§impl CodeGenerator
impl CodeGenerator
Sourcepub fn generate(&self, ir: &AuthoringIR) -> Result<CompiledSchema>
pub fn generate(&self, ir: &AuthoringIR) -> Result<CompiledSchema>
Generate a compiled schema from the intermediate representation.
§Architecture: Schema vs. Templates vs. Metadata
FraiseQL separates schema definition from execution artifacts:
§What This Function Generates
The CompiledSchema contains the schema definition - types, fields, enums,
interfaces, unions, and query/mutation/subscription signatures. This is what
GraphQL introspection tools query and what the runtime uses for query validation.
§What This Function Does NOT Generate
§1. SQL Templates
SQL templates are managed separately by the compilation pipeline. They are:
- Generated in a separate compiler pass after schema validation
- Kept separate to allow schema reuse across database backends
- Passed to the runtime executor independently
Why: Allows updating SQL generation strategy without recompiling schema definitions. For example, you could optimize SQL templates without changing type definitions.
§2. Fact Tables
Fact table metadata is populated by the compiler from ir.fact_tables in a
separate initialization pass. This maintains:
- Clean separation of concerns (schema def vs. analytics metadata)
- Ability to update fact table configuration independently
- Clear data flow through compilation pipeline
Why: Fact tables are configuration-driven metadata. Keeping them separate allows analytics tuning without affecting core schema.
§Parameters
ir- The intermediate representation generated by the compiler
§Errors
Returns a Result with compilation errors if schema validation fails.
§Examples
use fraiseql_core::compiler::{CodeGenerator, AuthoringIR};
let authoring_ir = AuthoringIR::new();
let codegen = CodeGenerator::new(true);
let compiled_schema = codegen.generate(&authoring_ir)?;
// Runtime uses compiled_schema for query execution§See Also
- (Compilation): SQL template generation
- Compiler module documentation for pipeline overview
§Errors
Returns FraiseQLError::Validation if the IR contains invalid field types,
unknown types, or conflicting definitions. Returns FraiseQLError::Internal
for unexpected code-generation failures.
Auto Trait Implementations§
impl Freeze for CodeGenerator
impl RefUnwindSafe for CodeGenerator
impl Send for CodeGenerator
impl Sync for CodeGenerator
impl Unpin for CodeGenerator
impl UnsafeUnpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more