Skip to content

Commit

Permalink
Add bin target for trustfall_stubgen and ensure deterministic stubs.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Jun 28, 2023
1 parent 97809b6 commit bee9693
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 236 deletions.
124 changes: 120 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions trustfall_stubgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ authors.workspace = true

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

[[bin]]
name = "trustfall_stubgen"
required-features = ["cli"]

[features]
default = []
cli = ["dep:clap"]

[dependencies]
quote = "1.0"
syn = "2.0"
Expand All @@ -23,6 +31,7 @@ anyhow = "1.0.71"
serde = { version = "1.0.164", features = ["derive"] }
prettyplease = "0.2.6"
regex = "1.8.4"
clap = { version = "4.0.0", features = ["derive"], optional = true }

[dev-dependencies]
glob = "0.3.1"
Expand Down
16 changes: 10 additions & 6 deletions trustfall_stubgen/src/adapter_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,20 @@ fn emit_property_handling(
"zero".into() => 0,
};

#[derive(Debug, serde::Deserialize)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)]
struct ResultRow {
name: String,
}

let mut arms = proc_macro2::TokenStream::new();
let rows = trustfall::execute_query(querying_schema, adapter, query, variables)
let mut rows: Vec<_> = trustfall::execute_query(querying_schema, adapter, query, variables)
.expect("invalid query")
.map(|x| {
x.try_into_struct::<ResultRow>()
.expect("invalid conversion")
});
})
.collect();
rows.sort_unstable();
for row in rows {
let name = &row.name;
let ident = syn::Ident::new(
Expand Down Expand Up @@ -198,18 +200,20 @@ fn emit_edge_handling(
"zero".into() => 0,
};

#[derive(Debug, serde::Deserialize)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)]
struct ResultRow {
name: String,
}

let mut arms = proc_macro2::TokenStream::new();
let rows = trustfall::execute_query(querying_schema, adapter, query, variables)
let mut rows: Vec<_> = trustfall::execute_query(querying_schema, adapter, query, variables)
.expect("invalid query")
.map(|x| {
x.try_into_struct::<ResultRow>()
.expect("invalid conversion")
});
})
.collect();
rows.sort_unstable();
for row in rows {
let name = &row.name;
let ident = syn::Ident::new(
Expand Down
11 changes: 7 additions & 4 deletions trustfall_stubgen/src/edges_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,24 @@ pub(super) fn make_edges_file(
"zero".into() => 0,
};

#[derive(Debug, serde::Deserialize)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)]
struct ResultRow {
name: String,
edge_name: Vec<String>,
parameter_name: Vec<Vec<String>>,
parameter_type: Vec<Vec<String>>,
}

let rows = trustfall::execute_query(querying_schema, adapter, query, variables)
let mut rows: Vec<_> = trustfall::execute_query(querying_schema, adapter, query, variables)
.expect("invalid query")
.map(|x| {
x.try_into_struct::<ResultRow>()
.expect("invalid conversion")
});
})
.collect();
rows.sort_unstable();
for row in rows {
let edges: Vec<(String, Vec<(String, String)>)> = row
let mut edges: Vec<(String, Vec<(String, String)>)> = row
.edge_name
.into_iter()
.zip(
Expand All @@ -61,6 +63,7 @@ pub(super) fn make_edges_file(
)
.map(|(edge, (param, ty))| (edge, param.into_iter().zip(ty.into_iter()).collect()))
.collect();
edges.sort_unstable();

let (type_edge_resolver_fn, type_edge_mod) = make_type_edge_resolver(&row.name, edges);
edges_file.top_level_items.push(type_edge_resolver_fn);
Expand Down
8 changes: 5 additions & 3 deletions trustfall_stubgen/src/entrypoints_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ pub(super) fn make_entrypoints_file(
}"#;
let variables: BTreeMap<Arc<str>, String> = btreemap! {};

#[derive(Debug, serde::Deserialize)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)]
struct ResultRow {
name: String,
parameter_name: Vec<String>,
parameter_type: Vec<String>,
}

let rows = trustfall::execute_query(querying_schema, adapter, query, variables)
let mut rows: Vec<_> = trustfall::execute_query(querying_schema, adapter, query, variables)
.expect("invalid query")
.map(|x| {
x.try_into_struct::<ResultRow>()
.expect("invalid conversion")
});
})
.collect();
rows.sort_unstable();
for row in rows {
let parameters: Vec<_> = row
.parameter_name
Expand Down
Loading

0 comments on commit bee9693

Please sign in to comment.