aqlgen_renderer/base/
generator.rs

1use std::fs;
2
3use super::render_to_files;
4use async_graphql_parser::parse_schema;
5use async_graphql_parser::types::ServiceDocument;
6
7use super::{Config, Context};
8
9pub fn generate_from_path(path: &str, config: &Config) {
10    let schema = open_schema(path);
11    let doc = parse(&schema);
12    let context = Context::new(config, &doc);
13    render_to_files(&context);
14}
15
16fn parse(schema: &str) -> ServiceDocument {
17    match parse_schema(schema) {
18        Ok(f) => f,
19        Err(e) => {
20            println!("{}", e);
21            panic!("Parse Error: {:?}", e);
22        }
23    }
24}
25
26fn open_schema(path: &str) -> String {
27    match fs::read_to_string(path) {
28        Ok(f) => f,
29        Err(f) => panic!("Not Found(Schema File): {:?}, {}", f, path),
30    }
31}