Skip to content

Commit 316e4e6

Browse files
committed
Add two tests
1 parent a00e673 commit 316e4e6

File tree

1 file changed

+94
-7
lines changed

1 file changed

+94
-7
lines changed

lib/executor/src/projection/response.rs

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ mod tests {
537537
},
538538
consumer_schema::ConsumerSchema,
539539
state::supergraph_state::SupergraphState,
540-
utils::parsing::parse_operation,
540+
utils::parsing::{parse_operation, parse_schema},
541541
};
542542
use sonic_rs::json;
543543

@@ -625,10 +625,7 @@ mod tests {
625625
assert_eq!(projected_str, expected_response);
626626
}
627627

628-
#[test]
629-
fn project_conflicting_selections() {
630-
let supergraph = hive_router_query_planner::utils::parsing::parse_schema(
631-
r#"
628+
static CONFLICTING_SELECTIONS_SUPERGRAPH: &'static str = r#"
632629
interface IContent {
633630
id: ID!
634631
}
@@ -667,8 +664,98 @@ type ContentContainer {
667664
id: ID!
668665
section: IContent
669666
}
670-
"#,
667+
"#;
668+
669+
// This tests if the projection works correctly when there are conflicting selections with typenames
670+
#[test]
671+
fn project_conflicting_selections_1() {
672+
let supergraph = parse_schema(CONFLICTING_SELECTIONS_SUPERGRAPH);
673+
let supergraph_state = SupergraphState::new(&supergraph);
674+
let consumer_schema = ConsumerSchema::new_from_supergraph(&supergraph);
675+
let schema_metadata = consumer_schema.schema_metadata();
676+
let query = parse_operation(
677+
r#"
678+
query {
679+
contentPage {
680+
contentBody {
681+
section {
682+
...ContentAData
683+
...ContentBData
684+
}
685+
}
686+
}
687+
}
688+
689+
fragment ContentAData on ContentA {
690+
contentChildren {
691+
title
692+
}
693+
}
694+
695+
fragment ContentBData on ContentB {
696+
contentChildren {
697+
title
698+
}
699+
}
700+
"#,
671701
);
702+
let normalized_operation: NormalizedDocument =
703+
normalize_operation(&supergraph_state, &query, None).unwrap();
704+
let (operation_type_name, selections) =
705+
FieldProjectionPlan::from_operation(&normalized_operation.operation, &schema_metadata);
706+
let data_json = json!({
707+
"__typename": "Query",
708+
"contentPage": [
709+
{
710+
"__typename": "ContentPage",
711+
"contentBody": [
712+
{
713+
"__typename": "ContentContainer",
714+
"id": "container1",
715+
"section": {
716+
"__typename": "ContentA",
717+
"contentChildren": []
718+
}
719+
},
720+
{
721+
"__typename": "ContentContainer",
722+
"id": "container2",
723+
"section": {
724+
"__typename": "ContentB",
725+
"contentChildren": [
726+
{
727+
"__typename": "ContentBChild",
728+
"title": "contentBChild1"
729+
}
730+
]
731+
}
732+
}
733+
]
734+
}
735+
]
736+
});
737+
let data = Value::from(data_json.as_ref());
738+
let projection = project_by_operation(
739+
&data,
740+
vec![],
741+
&None,
742+
operation_type_name,
743+
&selections,
744+
&None,
745+
1000,
746+
);
747+
let projected_bytes = projection.unwrap();
748+
let projected_str = String::from_utf8(projected_bytes).unwrap();
749+
insta::assert_snapshot!(
750+
projected_str,
751+
@r#"{"data":{"contentPage":[{"contentBody":[{"section":{"contentChildren":[]}},{"section":{"contentChildren":[{"title":"contentBChild1"}]}}]}]}}"#
752+
)
753+
}
754+
755+
// This tests if the projection works correctly when there are conflicting selections without typenames
756+
#[test]
757+
fn project_conflicting_selections_2() {
758+
let supergraph = parse_schema(CONFLICTING_SELECTIONS_SUPERGRAPH);
672759
let supergraph_state = SupergraphState::new(&supergraph);
673760
let consumer_schema = ConsumerSchema::new_from_supergraph(&supergraph);
674761
let schema_metadata = consumer_schema.schema_metadata();
@@ -705,7 +792,7 @@ fragment ContentBData on ContentB {
705792
title
706793
}
707794
}
708-
"#,
795+
"#,
709796
);
710797
let normalized_operation: NormalizedDocument =
711798
normalize_operation(&supergraph_state, &query, None).unwrap();

0 commit comments

Comments
 (0)