Skip to content

Commit

Permalink
Merge pull request #18 from s-ylide/feat/codegen-from-schema
Browse files Browse the repository at this point in the history
Update schema and codegen from it
  • Loading branch information
KOBA789 authored Apr 12, 2023
2 parents d4d287b + adcdd69 commit 1aa5bcb
Show file tree
Hide file tree
Showing 11 changed files with 58,326 additions and 379 deletions.
984 changes: 951 additions & 33 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
graphql_client_codegen = "0.12.0"
syn = "1.0.82"
reqwest = { version = "0.11.15", features = ["blocking"] }

[dependencies]
anyhow = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
gluesql = { version = "0.9", default-features = false, features = ["sorter"] }
async-trait = "0.1"
async-trait = "0.1.68"
rustyline = "9.1"
structopt = "0.3"
unicode-width = "0.1"
futures = "0.3"
graphql_client = "0.12.0"
54 changes: 54 additions & 0 deletions build.rs
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}")
}
}
}
Loading

0 comments on commit 1aa5bcb

Please sign in to comment.