-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.rs
54 lines (48 loc) · 1.46 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::{
env,
fs::File,
io::{self, Write},
path::Path,
process::Command,
};
use graphql_client_codegen::{
generate_module_token_stream, CodegenMode, GraphQLClientCodegenOptions,
};
use syn::Token;
fn main() {
// download it from https://docs.github.com/public/schema.docs.graphql
let schema_path = "schema.docs.graphql".to_string();
for file_name in [
"delete_item",
"list_items",
"list_fields",
"update_item_field",
] {
let mut options = GraphQLClientCodegenOptions::new(CodegenMode::Cli);
options.set_module_visibility(
syn::VisPublic {
pub_token: <Token![pub]>::default(),
}
.into(),
);
let gen = generate_module_token_stream(
format!("src/{file_name}.graphql").into(),
Path::new(&schema_path),
options,
)
.unwrap();
let generated_code = format!("{gen}");
let dest_file_path = format!("{}/{file_name}.rs", env::var("OUT_DIR").unwrap());
let mut file = File::create(&dest_file_path).unwrap();
write!(file, "{}", generated_code).unwrap();
let output = Command::new("rustfmt")
.arg(dest_file_path)
.output()
.unwrap();
io::stderr().write_all(&output.stderr).unwrap();
let status = output.status;
if !status.success() {
panic!("rustfmt error: {status}")
}
}
}