Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an iterator over all the required properties of a Vertex #449

Merged
merged 22 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions trustfall_core/src/interpreter/hints/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,9 @@ mod static_property_values {
assert_eq!(vid(1), info.vid());

assert_eq!(vec![RequiredProperty::new("value".into()),
RequiredProperty::new("multiple".into()),
RequiredProperty::new("predecessor".into()),
RequiredProperty::new("__typename".into())
], info.required_properties());
RequiredProperty::new("__typename".into()),
RequiredProperty::new("name".into())
], info.required_properties().collect::<Vec<RequiredProperty>>());
})),
}
.into(),
Expand Down
50 changes: 21 additions & 29 deletions trustfall_core/src/interpreter/hints/vertex_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait VertexInfo: super::sealed::__Sealed {
/// The type coercion (`... on SomeType`) applied by the query at this vertex, if any.
fn coerced_to_type(&self) -> Option<&Arc<str>>;

fn required_properties(&self) -> Vec<RequiredProperty>;
fn required_properties(&self) -> Box<dyn Iterator<Item = RequiredProperty>>;

/// Check whether the query demands this vertex property to have specific values:
/// a single value, or one of a set or range of values. The candidate values
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<T: InternalVertexInfo + super::sealed::__Sealed> VertexInfo for T {

/// required_properties returns an iterator over all properties needed
era marked this conversation as resolved.
Show resolved Hide resolved
/// for this vertex.
fn required_properties(&self) -> Vec<RequiredProperty> {
fn required_properties(&self) -> Box<dyn Iterator<Item = RequiredProperty>> {
let current_component = self.current_component();
era marked this conversation as resolved.
Show resolved Hide resolved

let current_vertex = self.current_vertex();
Expand All @@ -157,35 +157,10 @@ impl<T: InternalVertexInfo + super::sealed::__Sealed> VertexInfo for T {
let mut properties: Vec<RequiredProperty> = current_component
.outputs
.values()
.filter(|c| c.vertex_id == current_vertex.vid)
.map(|c| RequiredProperty::new(c.field_name.clone()))
.collect::<Vec<RequiredProperty>>();

// extend with the edges from this vertex
properties.extend(
current_component
.edges
.values()
.map(|a| RequiredProperty::new(a.edge_name.clone()))
.collect::<Vec<RequiredProperty>>(),
);

properties.extend(
current_component
.folds
.values()
.map(|i| RequiredProperty::new(i.edge_name.clone()))
.collect::<Vec<RequiredProperty>>(),
);

// properties.extend(
// current_component
// .vertices
// .values()
// .filter(|v| v.vid != current_vertex.vid)
// .map(|v| RequiredProperty::new(v.type_name.clone()))
// .collect::<Vec<RequiredProperty>>(),
// );

properties.extend(
current_vertex
.filters
Expand All @@ -194,7 +169,24 @@ impl<T: InternalVertexInfo + super::sealed::__Sealed> VertexInfo for T {
.collect::<Vec<RequiredProperty>>(),
);

properties
properties.extend(current_component.vertices.values().flat_map(|v| {
v.filters
.iter()
.filter(|f| match f.right() {
Some(Argument::Tag(FieldRef::ContextField(ctx))) => {
current_vertex.vid == ctx.vertex_id
}
Some(Argument::Tag(FieldRef::FoldSpecificField(fsf))) => {
current_vertex.vid == fsf.fold_root_vid
era marked this conversation as resolved.
Show resolved Hide resolved
}
_ => false,
})
.map(|f| f.right().unwrap().as_tag().unwrap().field_name().into())
era marked this conversation as resolved.
Show resolved Hide resolved
.map(RequiredProperty::new)
.collect::<Vec<RequiredProperty>>()
}));

Box::new(properties.into_iter())
era marked this conversation as resolved.
Show resolved Hide resolved
}

fn statically_required_property(&self, property: &str) -> Option<CandidateValue<&FieldValue>> {
Expand Down
Loading