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

do not remove __typename from input values #919

Merged
merged 4 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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: 5 additions & 2 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ Spans generated by the Router are now aligned with plugin services.
All windows processes are spawned via xtask rather than a separate CircleCI stage.

### Enable default feature in graphql_client [PR #905](https://github.com/apollographql/router/pull/905)
removing the default feature can cause build issues in plugins.
Removing the default feature can cause build issues in plugins.

## 📚 Documentation
### Do not remove __typename from the aggregated response [PR #919](https://github.com/apollographql/router/pull/919)
If the client was explicitely requesting the `__typename` field, it was removed from the aggregated subgraph data, and so was not usable by fragment to check the type.

## 📚 Documentation
### Enhanced rust docs ([PR #819](https://github.com/apollographql/router/pull/819))
Many more rust docs have been added.
67 changes: 59 additions & 8 deletions apollo-router-core/src/spec/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,24 @@ impl Query {
if input_value.is_null() && output.contains_key(field_name.as_str()) {
continue;
}

let selection_set = selection_set.as_deref().unwrap_or_default();
let output_value =
output.entry((*field_name).clone()).or_insert(Value::Null);
self.format_value(
field_type,
variables,
input_value,
output_value,
selection_set,
schema,
)?;
if field_name.as_str() == "__typename" {
Geal marked this conversation as resolved.
Show resolved Hide resolved
if input_value.is_string() {
*output_value = input_value.clone();
}
} else {
self.format_value(
field_type,
variables,
input_value,
output_value,
selection_set,
schema,
)?;
}
} else {
if !output.contains_key(field_name.as_str()) {
output.insert((*field_name).clone(), Value::Null);
Expand Down Expand Up @@ -3716,4 +3723,48 @@ mod tests {
}},
);
}

#[test]
fn union_with_typename() {
let schema = "type Query {
get: ProductResult
}

type Product{
symbol: String!
}
type ProductError{
reason: String
}
union ProductResult = Product | ProductError
";

assert_format_response!(
schema,
"query {
get {
__typename
... on Product {
symbol
}
... on ProductError {
reason
}
}
}",
json! {{
"get": {
"__typename": "Product",
"symbol": "1"
},
}},
None,
json! {{
"get": {
"__typename": "Product",
"symbol": "1"
},
}},
);
}
}