Skip to content

Commit

Permalink
Add more test cases for edge cases around @optional semantics. (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi authored Apr 11, 2023
1 parent 4d2e9c8 commit 6565458
Show file tree
Hide file tree
Showing 12 changed files with 1,235 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Ok(TestParsedGraphQLQuery(
schema_name: "numbers",
query: Query(
root_connection: FieldConnection(
position: Pos(
line: 3,
column: 5,
),
name: "One",
),
root_field: FieldNode(
position: Pos(
line: 3,
column: 5,
),
name: "One",
connections: [
(FieldConnection(
position: Pos(
line: 4,
column: 9,
),
name: "predecessor",
optional: Some(OptionalDirective()),
), FieldNode(
position: Pos(
line: 4,
column: 9,
),
name: "predecessor",
connections: [
(FieldConnection(
position: Pos(
line: 5,
column: 13,
),
name: "successor",
), FieldNode(
position: Pos(
line: 5,
column: 13,
),
name: "successor",
connections: [
(FieldConnection(
position: Pos(
line: 6,
column: 17,
),
name: "value",
), FieldNode(
position: Pos(
line: 6,
column: 17,
),
name: "value",
filter: [
FilterDirective(
operation: GreaterThan((), VariableRef("one")),
),
],
output: [
OutputDirective(),
],
)),
],
)),
],
)),
],
),
),
arguments: {
"one": Int64(1),
},
))
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TestGraphQLQuery (
schema_name: "numbers",
// This query tests an edge case of the semantics of `@optional` with nested `@filter`.
//
// `@optional` applies *only* to whether the edge exists. After the edge is resolved,
// subsequent edges and filters are resolved normally. If the thus-resolved vertices fail
// to satisfy a subsequent required edge or filter, they are discarded.
//
// We *do not* get to "retroactively" pretend that the edge did not exist at the `@optional`
// and thereby preserve that result set with nulls for the `@optional` contents.
//
// If the below query returns *any* data, that's a bug.
query: r#"
{
One {
predecessor @optional {
successor {
value @filter(op: ">", value: ["$one"]) @output
}
}
}
}"#,
arguments: {
"one": Int64(1),
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Ok(TestIRQuery(
schema_name: "numbers",
ir_query: IRQuery(
root_name: "One",
root_component: IRQueryComponent(
root: Vid(1),
vertices: {
Vid(1): IRVertex(
vid: Vid(1),
type_name: "Number",
),
Vid(2): IRVertex(
vid: Vid(2),
type_name: "Number",
),
Vid(3): IRVertex(
vid: Vid(3),
type_name: "Number",
filters: [
GreaterThan(LocalField(
field_name: "value",
field_type: "Int",
), Variable(VariableRef(
variable_name: "one",
variable_type: "Int!",
))),
],
),
},
edges: {
Eid(1): IREdge(
eid: Eid(1),
from_vid: Vid(1),
to_vid: Vid(2),
edge_name: "predecessor",
optional: true,
),
Eid(2): IREdge(
eid: Eid(2),
from_vid: Vid(2),
to_vid: Vid(3),
edge_name: "successor",
),
},
outputs: {
"value": ContextField(
vertex_id: Vid(3),
field_name: "value",
field_type: "Int",
),
},
),
variables: {
"one": "Int!",
},
),
arguments: {
"one": Int64(1),
},
))
Loading

0 comments on commit 6565458

Please sign in to comment.