Fix included conditional selections not being projected#9818
Merged
Conversation
…th-conditions # Conflicts: # src/HotChocolate/Data/test/Data.EntityFramework.Tests/IntegrationTests.cs
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes conditional @include/@skip selections not being projected (notably when directives are driven by variables), by tracking include-condition dependencies and caching selector variants per operation/selection.
Changes:
- Add condition-mask tracking during selector building and use it to build/cached the correct selector variant for the current runtime include flags.
- Introduce a projection selector cache (backed by a new generic in-memory cache) and auto-register it from Data builder extensions.
- Add comprehensive EF integration tests + snapshots to cover conditional projections, paging, and executor/operation reuse.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Data/test/Data.EntityFramework.Tests/IntegrationTests.cs | Adds integration tests validating conditional projection behavior and selector caching. |
| src/HotChocolate/Data/test/Data.EntityFramework.Tests/snapshots/*.md | Adds snapshots for new conditional projection scenarios (results + generated SQL). |
| src/HotChocolate/Data/src/Data/Filters/Extensions/HotChocolateDataQueryableExtensions.cs | Adds Select(..., includeFlags) overload to apply runtime include/skip flags. |
| src/HotChocolate/Data/src/Data/Extensions/HotChocolateDataRequestBuilderExtensions.cs | Ensures selector cache is registered when adding projections/query-context. |
| src/HotChocolate/Core/src/Types/Execution/Processing/Selection.cs | Adds IncludeConditionMask to expose condition-bit dependencies of a selection. |
| src/HotChocolate/Core/src/Types/Execution/Processing/OperationFeatureCollection.cs | Adds contextual GetOrSetSafe overload. |
| src/HotChocolate/Core/src/Types/Execution/Processing/Operation.cs | Adds process-unique CacheId used for selector cache keys. |
| src/HotChocolate/Core/src/Execution.Projections/SelectorExpression.cs | Adds typed wrapper for selector expression + include/dependency masks. |
| src/HotChocolate/Core/src/Execution.Projections/SelectionExpressionBuilder.cs | Emits dependency mask while building selector expressions. |
| src/HotChocolate/Core/src/Execution.Projections/ProjectionSelectorCache.cs | Adds operation/selection/includeFlags-based selector variant cache. |
| src/HotChocolate/Core/src/Execution.Projections/HotChocolate.Execution.Projections.csproj | Adds references needed for caching + configuration abstractions. |
| src/HotChocolate/Core/src/Execution.Projections/Extensions/HotChocolateExecutionSelectionExtensions.cs | Reworks AsSelector to use condition masking + selector caching. |
| src/HotChocolate/Core/src/Execution.Projections/Extensions/HotChocolateExecutionProjectionsRequestExecutorBuilderExtensions.cs | Adds AddProjectionSelectorCache() registration extension. |
| src/HotChocolate/Core/src/Execution.Projections/Extensions/HotChocolateExecutionDataLoaderExtensions.cs | Adds overloads that accept runtime include flags; fixes doc typos. |
| src/HotChocolate/Caching/src/Caching.Memory/Cache`2.cs | Introduces generic keyed ring-buffer cache implementation. |
| src/HotChocolate/Caching/test/Caching.Memory.Tests/CacheOfTKeyTests.cs | Adds unit tests for the new generic cache behavior. |
| CLAUDE.md / AGENTS.md | Adds repository guidance (testing + API parameter guidance). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+99
to
+107
| var operation = selection.DeclaringOperation; | ||
| var cache = operation.Features.GetOrSetSafe( | ||
| static o => o.Schema.Services.GetRequiredService<ProjectionSelectorCache>(), | ||
| operation); | ||
|
|
||
| selectorExpression = cache.GetOrCreate( | ||
| selection, | ||
| maskedFlags, | ||
| static (selection, includeFlags) => CreateSelectorExpression<TValue>(selection, includeFlags)); |
Comment on lines
+815
to
+821
| finally | ||
| { | ||
| if (File.Exists(dbFile)) | ||
| { | ||
| File.Delete(dbFile); | ||
| } | ||
| } |
Comment on lines
+1150
to
+1156
| finally | ||
| { | ||
| if (File.Exists(dbFile)) | ||
| { | ||
| File.Delete(dbFile); | ||
| } | ||
| } |
Comment on lines
+1236
to
+1242
| finally | ||
| { | ||
| if (File.Exists(dbFile)) | ||
| { | ||
| File.Delete(dbFile); | ||
| } | ||
| } |
Comment on lines
+1332
to
+1338
| finally | ||
| { | ||
| if (File.Exists(dbFile)) | ||
| { | ||
| File.Delete(dbFile); | ||
| } | ||
| } |
Comment on lines
+1491
to
+1500
| catch | ||
| { | ||
| await services.DisposeAsync(); | ||
| if (File.Exists(dbFile)) | ||
| { | ||
| File.Delete(dbFile); | ||
| } | ||
|
|
||
| throw; | ||
| } |
Comment on lines
+1591
to
+1599
| public async ValueTask DisposeAsync() | ||
| { | ||
| await services.DisposeAsync(); | ||
|
|
||
| if (File.Exists(dbFile)) | ||
| { | ||
| File.Delete(dbFile); | ||
| } | ||
| } |
Comment on lines
+828
to
+830
| var dbFile = System.IO.Path.Combine( | ||
| System.IO.Path.GetTempPath(), | ||
| $"conditional-projection-{Guid.NewGuid():N}.db"); |
Comment on lines
+910
to
+912
| var dbFile = System.IO.Path.Combine( | ||
| System.IO.Path.GetTempPath(), | ||
| $"conditional-projection-{Guid.NewGuid():N}.db"); |
Comment on lines
+996
to
+998
| var dbFile = System.IO.Path.Combine( | ||
| System.IO.Path.GetTempPath(), | ||
| $"conditional-projection-{Guid.NewGuid():N}.db"); |
Comment on lines
+1080
to
+1082
| var dbFile = System.IO.Path.Combine( | ||
| System.IO.Path.GetTempPath(), | ||
| $"conditional-projection-{Guid.NewGuid():N}.db"); |
Comment on lines
+1165
to
+1167
| var dbFile = System.IO.Path.Combine( | ||
| System.IO.Path.GetTempPath(), | ||
| $"conditional-projection-{Guid.NewGuid():N}.db"); |
Comment on lines
+1249
to
+1251
| var dbFile = System.IO.Path.Combine( | ||
| System.IO.Path.GetTempPath(), | ||
| $"conditional-projection-{Guid.NewGuid():N}.db"); |
Comment on lines
+1439
to
+1441
| var dbFile = System.IO.Path.Combine( | ||
| System.IO.Path.GetTempPath(), | ||
| $"conditional-projection-{Guid.NewGuid():N}.db"); |
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the Show a code coverage summary of the most impacted files.
Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
This was referenced Jun 26, 2026
This was referenced Jun 29, 2026
Open
This was referenced Jul 7, 2026
This was referenced Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9817