pub struct CodeGenerator { /* private fields */ }Expand description
Code generator.
Implementations§
Source§impl CodeGenerator
impl CodeGenerator
Sourcepub fn generate(
&self,
ir: &AuthoringIR,
_templates: &[SqlTemplate],
) -> Result<CompiledSchema>
pub fn generate( &self, ir: &AuthoringIR, _templates: &[SqlTemplate], ) -> 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_templates- SQL templates (currently unused; kept for API compatibility)
§Errors
Returns a Result with compilation errors if schema validation fails.
§Examples
use fraiseql_core::compiler::*;
// Given an AuthoringIR from the compiler pipeline:
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