Skip to content

Commit

Permalink
Refactor and document Schema singleton's vertex_type edge.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Jul 29, 2023
1 parent c637ede commit 35aaa64
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions trustfall_core/src/schema/adapter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,23 @@ impl<'a> crate::interpreter::Adapter<'a> for SchemaAdapter<'a> {
},
"Schema" => match edge_name.as_ref() {
"vertex_type" => {
let candidate_destination = resolve_info.destination();

let candidate_value_for_name =
candidate_destination.statically_required_property("name");

let mut iter = Some(vertex_type_iter(
self.schema,
candidate_value_for_name.map(|x| x.cloned()),
));

resolve_neighbors_with(contexts, move |_| iter.take().unwrap())
let schema = self.schema;
let destination = resolve_info.destination();

// The `Schema` vertex is a singleton -- there can only be one instance of it.
// So this hint can only be used once, and we don't want to clone it needlessly.
// Take it from this option and assert that it hasn't been taken more than once.
let mut vertex_type_name =
Some(destination.statically_required_property("name").map(|x| x.cloned()));

resolve_neighbors_with(contexts, move |_| {
vertex_type_iter(
schema,
vertex_type_name.take().expect(
"found more than one Schema vertex when resolving vertex_type",
),
)
})
}
"entrypoint" => {
let mut iter = Some(self.entrypoints_iter());
Expand Down

0 comments on commit 35aaa64

Please sign in to comment.