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

fix(federation): fixed Selection::conditions to merge field's subselection's conditions when necessary #6323

Draft
wants to merge 5 commits into
base: 1.58.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
22 changes: 14 additions & 8 deletions apollo-federation/src/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,20 @@ impl Selection {
Ok(Conditions::Boolean(false))
} else {
match self {
Selection::Field(_) => {
// The sub-selections of this field don't affect whether we should query this
// field, so we explicitly do not merge them in.
//
// PORT_NOTE: The JS codebase merges the sub-selections' conditions in with the
// field's conditions when field's selections are non-boolean. This is arguably
// a bug, so we've fixed it here.
Ok(self_conditions)
Selection::Field(field) => {
// If it's `true`, then it means that element is included. If it is a field,
// then we should also stop and return `true`, because no matter what the
// sub-selection is, we need to get that field.
// Note: The `Boolean(false)` case has been already checked above. Thus, this
// case is really checking for `Boolean(true)`.
if matches!(self_conditions, Conditions::Boolean(_)) {
return Ok(self_conditions);
}
let Some(ref selection_set) = field.selection_set else {
// No subselection set => condition won't change.
return Ok(self_conditions);
};
Ok(self_conditions.merge(selection_set.conditions()?))
}
Selection::InlineFragment(inline) => {
Ok(self_conditions.merge(inline.selection_set.conditions()?))
Expand Down
28 changes: 28 additions & 0 deletions apollo-federation/tests/query_plan/build_query_plan_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,3 +1412,31 @@ fn rebase_non_intersecting_without_dropping_inline_fragment_due_to_directive() {
"###
);
}

#[test]
fn field_condition_propagation_to_parent_node() {
let planner = planner!(
Subgraph1: r#"
type Query {
test: T!
}

type T {
id: ID!
name: String!
x: Int!
}
"#,
);
assert_plan!(
&planner,
r#"
query($v1: Boolean!) {
test @include(if: $v1) {
id @include(if: false)
}
}
"#,
@"QueryPlan {}"
);
}
Loading