Skip to content

Commit

Permalink
Add reproduction
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jul 26, 2024
1 parent 0773077 commit 9bf2da2
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions apollo-federation/src/operation/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,89 @@ mod tests {
"###);
}

#[test]
fn reuse_fragments_with_non_intersecting_types() {
let schema = r#"
type Query {
t: T
s: S
s2: S
i: I
}
interface I {
a: Int
b: Int
}
type T implements I {
a: Int
b: Int
c: Int
d: Int
}
type S implements I {
a: Int
b: Int
f: Int
g: Int
}
"#;
let query = r#"
query A ($if: Boolean!) {
t { ...x }
s { ...x }
i { ...x }
}
query B {
s {
# this matches fragment x once it is flattened,
# because the `...on T` condition does not intersect with our
# current type `S`
__typename
a b
}
s2 {
# same snippet to get it to use the fragment
__typename
a b
}
}
fragment x on I {
__typename
a
b
... on T { c d @include(if: $if) }
}
"#;
let schema = parse_schema(schema);
let query = ExecutableDocument::parse_and_validate(schema.schema(), query, "query.graphql")
.unwrap();

let operation_a =
Operation::from_operation_document(schema.clone(), &query, Some("A")).unwrap();
let operation_b =
Operation::from_operation_document(schema.clone(), &query, Some("B")).unwrap();
let expanded_b = operation_b.expand_all_fragments_and_normalize().unwrap();

assert_optimized!(expanded_b, operation_a.named_fragments, @r###"
query B {
s {
__typename
a
b
}
s2 {
__typename
a
b
}
}
"###);
}

///
/// empty branches removal
///
Expand Down

0 comments on commit 9bf2da2

Please sign in to comment.