Skip to content

Fix included conditional selections not being projected#9818

Merged
michaelstaib merged 11 commits into
mainfrom
tte/fix-projection-with-conditions
Jun 23, 2026
Merged

Fix included conditional selections not being projected#9818
michaelstaib merged 11 commits into
mainfrom
tte/fix-projection-with-conditions

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Jun 2, 2026

Copy link
Copy Markdown
Member

Fixes #9817

@michaelstaib
michaelstaib marked this pull request as ready for review June 23, 2026 12:34
Copilot AI review requested due to automatic review settings June 23, 2026 12:34
…th-conditions

# Conflicts:
#	src/HotChocolate/Data/test/Data.EntityFramework.Tests/IntegrationTests.cs

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.

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 thread src/HotChocolate/Core/src/Types/Execution/Processing/Operation.cs Fixed
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");
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in the tte/fix-projection-w... branch remains at 49%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main d60c4b3 tte/fix-projection-w... 07de279 +/-
/home/runner/wo...erExtensions.cs 62% 33% -29%
/home/runner/wo...n.Selections.cs 83% 56% -27%
/home/runner/wo...PromiseCache.cs 78% 81% +3%
/home/runner/wo...onMiddleware.cs 88% 94% +6%
/home/runner/wo...reCollection.cs 36% 47% +11%
/home/runner/wo...onExtensions.cs 60% 74% +14%
/home/runner/wo...electorCache.cs 0% 83% +83%
/home/runner/wo...mory/Cache`2.cs 0% 91% +91%
/home/runner/wo...erExtensions.cs 0% 100% +100%
/home/runner/wo...orExpression.cs 0% 100% +100%

Code Coverage is in Public Preview. Learn more and provide us with your feedback.

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.

include directive with argument from variable not working with selection through data loader in v16

3 participants