Skip to content

Commit

Permalink
Update textual references to "optimize()" to "reuse_fragments()"
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jul 26, 2024
1 parent 9bf2da2 commit 3da5d4e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions apollo-federation/src/operation/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ enum SelectionSetOrFragment {
}

impl SelectionSet {
/// Reduce the list of applicable fragments by eliminating ones that are subsumed by another.
/// Reduce the list of applicable fragments by eliminating fragments that directly include
/// another fragment.
//
// We have found the list of fragments that applies to some subset of sub-selection. In
// general, we want to now produce the selection set with spread for those fragments plus
Expand Down Expand Up @@ -1405,10 +1406,10 @@ impl SelectionSet {
}

if self.contains_fragment_spread() {
return Err(FederationError::internal("optimize() must only be used on selection sets that do not contain named fragment spreads"));
return Err(FederationError::internal("reuse_fragments() must only be used on selection sets that do not contain named fragment spreads"));
}

// Calling optimize() will not match a fragment that would have expanded at
// Calling reuse_fragments() will not match a fragment that would have expanded at
// top-level. That is, say we have the selection set `{ x y }` for a top-level `Query`, and
// we have a fragment
// ```
Expand All @@ -1417,12 +1418,12 @@ impl SelectionSet {
// y
// }
// ```
// then calling `self.optimize(fragments)` would only apply check if F apply to
// then calling `self.reuse_fragments(fragments)` would only apply check if F apply to
// `x` and then `y`.
//
// To ensure the fragment match in this case, we "wrap" the selection into a trivial
// fragment of the selection parent, so in the example above, we create selection `... on
// Query { x y}`. With that, `optimize` will correctly match on the `on Query`
// Query { x y }`. With that, `reuse_fragments` will correctly match on the `on Query`
// fragment; after which we can unpack the final result.
let wrapped = InlineFragmentSelection::from_selection_set(
self.type_position.clone(), // parent type
Expand Down Expand Up @@ -1453,7 +1454,7 @@ impl SelectionSet {
}

impl Operation {
// PORT_NOTE: The JS version of `optimize` takes an optional `minUsagesToOptimize` argument.
// PORT_NOTE: The JS version of `reuse_fragments` takes an optional `minUsagesToOptimize` argument.
// However, it's only used in tests. So, it's removed in the Rust version.
const DEFAULT_MIN_USAGES_TO_OPTIMIZE: u32 = 2;

Expand Down

0 comments on commit 3da5d4e

Please sign in to comment.