Skip to content

Commit

Permalink
Navigating past an @optional edge should disable many hints. (#254)
Browse files Browse the repository at this point in the history
Or else it's a footgun that adapters are pretty much guaranteed to fall
for.
  • Loading branch information
obi1kenobi committed Apr 11, 2023
1 parent 6565458 commit 2611481
Show file tree
Hide file tree
Showing 10 changed files with 1,706 additions and 11 deletions.
466 changes: 457 additions & 9 deletions trustfall_core/src/interpreter/hints/mod.rs

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions trustfall_core/src/interpreter/hints/vertex_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ impl<T: InternalVertexInfo + super::sealed::__Sealed> VertexInfo for T {
}

fn first_mandatory_edge(&self, name: &str) -> Option<EdgeInfo> {
self.edges_with_name(name)
.find(|edge| !edge.folded && !edge.optional && edge.recursive.is_none())
if self.non_binding_filters() {
None
} else {
self.edges_with_name(name)
.find(|edge| !edge.folded && !edge.optional && edge.recursive.is_none())
}
}

fn first_edge(&self, name: &str) -> Option<EdgeInfo> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Ok(TestParsedGraphQLQuery(
schema_name: "numbers",
query: Query(
root_connection: FieldConnection(
position: Pos(
line: 3,
column: 5,
),
name: "Two",
),
root_field: FieldNode(
position: Pos(
line: 3,
column: 5,
),
name: "Two",
connections: [
(FieldConnection(
position: Pos(
line: 4,
column: 9,
),
name: "successor",
recurse: Some(RecurseDirective(
depth: 2,
)),
), FieldNode(
position: Pos(
line: 4,
column: 9,
),
name: "successor",
connections: [
(FieldConnection(
position: Pos(
line: 5,
column: 13,
),
name: "predecessor",
), FieldNode(
position: Pos(
line: 5,
column: 13,
),
name: "predecessor",
connections: [
(FieldConnection(
position: Pos(
line: 6,
column: 17,
),
name: "predecessor",
), FieldNode(
position: Pos(
line: 6,
column: 17,
),
name: "predecessor",
connections: [
(FieldConnection(
position: Pos(
line: 7,
column: 21,
),
name: "value",
), FieldNode(
position: Pos(
line: 7,
column: 21,
),
name: "value",
output: [
OutputDirective(),
],
)),
],
)),
],
)),
],
)),
],
),
),
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TestGraphQLQuery (
schema_name: "numbers",
query: r#"
{
Two {
successor @recurse(depth: 2) {
predecessor {
predecessor {
value @output
}
}
}
}
}"#,
arguments: {},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Ok(TestIRQuery(
schema_name: "numbers",
ir_query: IRQuery(
root_name: "Two",
root_component: IRQueryComponent(
root: Vid(1),
vertices: {
Vid(1): IRVertex(
vid: Vid(1),
type_name: "Prime",
),
Vid(2): IRVertex(
vid: Vid(2),
type_name: "Number",
),
Vid(3): IRVertex(
vid: Vid(3),
type_name: "Number",
),
Vid(4): IRVertex(
vid: Vid(4),
type_name: "Number",
),
},
edges: {
Eid(1): IREdge(
eid: Eid(1),
from_vid: Vid(1),
to_vid: Vid(2),
edge_name: "successor",
recursive: Some(Recursive(
depth: 2,
)),
),
Eid(2): IREdge(
eid: Eid(2),
from_vid: Vid(2),
to_vid: Vid(3),
edge_name: "predecessor",
),
Eid(3): IREdge(
eid: Eid(3),
from_vid: Vid(3),
to_vid: Vid(4),
edge_name: "predecessor",
),
},
outputs: {
"value": ContextField(
vertex_id: Vid(4),
field_name: "value",
field_type: "Int",
),
},
),
),
))
Loading

0 comments on commit 2611481

Please sign in to comment.