Skip to content

Commit

Permalink
fixes for #3718 (#3750)
Browse files Browse the repository at this point in the history
  • Loading branch information
o0Ignition0o authored Sep 5, 2023
2 parents aa7a796 + 14fb8ab commit 8f6add2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: apollo-router/src/services/supergraph_service.rs
expression: with_typename
---
{
"data": {
"dog": {
"id": "8765",
"__typename": "Dog",
"name": "Spot"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: apollo-router/src/services/supergraph_service.rs
expression: with_reversed_fragments
---
{
"data": {
"dog": {
"name": "Spot",
"id": "0000"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: apollo-router/src/services/supergraph_service.rs
expression: no_typename
---
{
"data": {
"dog": {
"id": "4321",
"name": "Spot"
}
}
}
7 changes: 5 additions & 2 deletions apollo-router/src/services/supergraph_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2933,10 +2933,10 @@ mod tests {
serde_json::json!{{"data":{"dog":{"id":"4321","name":"Spot"}}}}
).with_json(
serde_json::json!{{"query":"query dog__animal__0{dog{__typename id name}}", "operationName": "dog__animal__0"}},
serde_json::json!{{"data":{"dog":{"__typename":"Dog","id":"4321","name":"Spot"}}}}
serde_json::json!{{"data":{"dog":{"__typename":"Dog","id":"8765","name":"Spot"}}}}
).with_json(
serde_json::json!{{"query":"query dog__animal__0{dog{name id}}", "operationName": "dog__animal__0"}},
serde_json::json!{{"data":{"dog":{"id":"4321","name":"Spot"}}}}
serde_json::json!{{"data":{"dog":{"id":"0000","name":"Spot"}}}}
).build()),
].into_iter().collect());

Expand Down Expand Up @@ -3014,6 +3014,7 @@ mod tests {
let mut stream = service.clone().oneshot(request).await.unwrap();

let no_typename = stream.next_response().await.unwrap();
insta::assert_json_snapshot!(no_typename);

let request = supergraph::Request::fake_builder()
.context(defer_context())
Expand Down Expand Up @@ -3057,6 +3058,7 @@ mod tests {
with_typename,
no_typename
);
insta::assert_json_snapshot!(with_typename);

let request = supergraph::Request::fake_builder()
.context(defer_context())
Expand Down Expand Up @@ -3099,5 +3101,6 @@ mod tests {
with_reversed_fragments,
no_typename
);
insta::assert_json_snapshot!(with_reversed_fragments);
}
}
10 changes: 2 additions & 8 deletions apollo-router/src/spec/query/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,9 @@ fn reformat_response_data_best_effort() {
"baz": "2",
},
"array": [
{
"bar":null,
"baz":"3"
},
{},
null,
{
"bar":"5",
"baz":null
}
{}
],
"other": null,
},
Expand Down
18 changes: 16 additions & 2 deletions apollo-router/src/spec/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,29 @@ impl Selection {
.ok_or_else(|| SpecError::InvalidType(current_type.to_string()))?;

let fragment_type = FieldType::new_named(type_condition.clone());
let known_type = current_type.inner_type_name().map(|s| s.to_string());

// this is the type we pass when extracting the fragment's selections
// If the type condition is a union or interface and the current type implements it, then we want
// to keep the current type when extracting the fragment's selections, as it is more precise
// than the interface.
// If it is not, then we use the type condition
let relevant_type = if schema.is_interface(type_condition.as_str()) {
// Query validation should have already verified that current type implements that interface
debug_assert!(
schema.is_subtype(
type_condition.as_str(),
current_type.inner_type_name().unwrap_or("")
) ||
// if the current type and the type condition are both the same interface, it is still valid
type_condition.as_str()
== current_type.inner_type_name().unwrap_or("")
);
current_type
} else {
&fragment_type
};

let known_type = relevant_type.inner_type_name().map(|s| s.to_string());

let selection_set = inline_fragment
.selection_set()
.selection()
Expand Down

0 comments on commit 8f6add2

Please sign in to comment.