-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from s-ylide/feat/codegen-from-schema
Update schema and codegen from it
- Loading branch information
Showing
11 changed files
with
58,326 additions
and
379 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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}") | ||
} | ||
} | ||
} |
Oops, something went wrong.