Skip to content

[Fusion] Reuse already fetched entities in Apollo entity lookups - #10653

Merged
michaelstaib merged 10 commits into
mainfrom
tte/apollo-entity-reuse
Oct 22, 2026
Merged

michaelstaib merged 10 commits into
mainfrom
tte/apollo-entity-reuse

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Request-scoped entity reuse (#10606) never applies to plans with Apollo _entities lookups. An Apollo lookup always sends its representations to the subgraph, even when an earlier fetch of the same request already returned those entities with all the selected fields, so the gateway refetches them.

This PR extends entity reuse to ApolloOperationExecutionNode and ApolloOperationBatchExecutionNode. The candidate map analyzes the rewritten _entities operation, and the Apollo nodes fill entities the result already holds and send only the remaining representations. A lookup whose entities were all reused completes as a success, so its dependents still run. Plans, dependencies and the plan JSON are unchanged.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

94.8% of changed lines covered (402/424)

File Covered Changed Patch %
…/Execution/Results/FetchResultStore.RepresentationValue.cs 116 130 89.2% 🟡
…/Execution/Results/EntityReuseCandidateMap.cs 99 103 96.1% 🟡
…/src/Fusion.Execution/Execution/Results/FetchResultStore.cs 108 111 97.3% 🟡
…/Execution/Nodes/ApolloOperationBatchExecutionNode.cs 39 40 97.5% 🟡
…/Execution/Nodes/ApolloOperationExecutionNode.cs 17 17 100.0% 🟢
…/src/Fusion.Execution/Execution/OperationPlanContext.cs 22 22 100.0% 🟢
…/Execution/Results/FetchResultStore.Pooling.cs 1 1 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "de2f87185c0759bd7d750b0d4241009e6b25be10",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/FetchResultStore.RepresentationValue.cs", "ranges": [[214, 215], [223, 224], [472, 472], [536, 536], [1789, 1789], [1797, 1797], [1817, 1817], [1823, 1823], [1843, 1843], [1873, 1873], [1928, 1928], [2053, 2053]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/EntityReuseCandidateMap.cs", "ranges": [[378, 379], [468, 469]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/FetchResultStore.cs", "ranges": [[2656, 2656], [3023, 3023], [3087, 3087]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/ApolloOperationBatchExecutionNode.cs", "ranges": [[692, 692]] }
  ]
}

Project coverage: 59.2% (314495/530812 lines)

Apollo lookups now match targets against producers while the
representations are written, instead of building throwaway variable
value sets and writing the representations a second time.

Add tests for both composite and Apollo lookups that cover batches
where one or every operation is reused, two mutations that change the
same entity, and subscription events that hold the same entity. Request
counts and representations are checked with asserts, only responses
use inline snapshots.
@tobias-tengler
tobias-tengler force-pushed the tte/apollo-entity-reuse branch from a33d78c to 7e03efd Compare October 21, 2026 09:23
@tobias-tengler
tobias-tengler marked this pull request as ready for review October 21, 2026 09:24
Copilot AI balanced review requested due to automatic review settings October 21, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants