use std::env; use std::fs; use std::path::Path; fn main() { let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap(); let schema = fs::read_to_string(Path::new(&manifest_dir).join("schema.graphql")).unwrap(); let query = fs::read_to_string(Path::new(&manifest_dir).join("query.graphql")).unwrap(); let code = cynic_querygen::document_to_fragment_structs( query, schema, &cynic_querygen::QueryGenOptions { schema_path: "schema.graphql".to_string(), query_module: "schema".to_string(), }, ) .unwrap(); let patched_code = code .replace("mod queries", "pub mod queries") .replace("mod schema", "pub mod schema"); fs::write(Path::new(&out_dir).join("graphql.rs"), patched_code).unwrap(); cargo_emit::rerun_if_changed!("schema.graphql", "query.graphql"); }