Skip to content

Add IsProjected support to selector-based projections - #10290

Merged
michaelstaib merged 6 commits into
mainfrom
gai/is-projected-selector-support
Aug 28, 2026
Merged

michaelstaib merged 6 commits into
mainfrom
gai/is-projected-selector-support

Conversation

@glen-84

@glen-84 glen-84 commented Aug 24, 2026

Copy link
Copy Markdown
Member

Summary

  • IsProjected() and [IsProjected] are now honored when projections are built from the selection set through QueryContext<T> or a DataLoader Select(selection) call, matching the projection middleware: always-projected leaf fields backed by a property are fetched even when not selected, and never-projected fields are skipped even when selected (resolving to their default value).
  • Breaking: the public HotChocolate.Data.Projections.ProjectionFeature record is removed. Its state is now carried by internal CoreFieldFlags (AlwaysProjected, NotProjected, HasProjectionMiddleware), read through a new internal helper on IOutputFieldDefinition. HasProjectionMiddleware gets its own flag instead of reusing UsesProjections, which [SkipDataLoaderCache] also sets.
  • The 15-to-16 migration guide documents the removal, noted as landing in 16.6.2.

Test plan

  • New IsProjectedSelectorTests (Sqlite with SQL capture) pin the exact SQL: always-projected fetched when unselected, never-projected omitted when selected, __typename-only selection, and the DataLoader Select(selection) path.
  • Regression: Data.EntityFramework.Tests, Data.Tests, Data.Projections.Tests, the legacy IsProjected suites (SqlServer, MongoDb, Raven), and the PostgreSQL AsSelector suites all pass.

Closes #8313

Copilot AI lite review requested due to automatic review settings August 24, 2026 15:24
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Aug 24, 2026

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

This PR aligns selector-based projections (e.g., QueryContext<T> and DataLoader Select(selection)) with projection middleware behavior by honoring IsProjected() / [IsProjected] for both always-projected and never-projected fields, and it replaces the removed public ProjectionFeature record with internal CoreFieldFlags-based state.

Changes:

  • Honor AlwaysProjected and NotProjected when building projections from selection sets (including __typename-only selections) and when using DataLoader selector paths.
  • Remove HotChocolate.Data.Projections.ProjectionFeature and move its state to internal CoreFieldFlags (AlwaysProjected, NotProjected, HasProjectionMiddleware) plus an internal helper on IOutputFieldDefinition.
  • Add EF Core Sqlite tests that snapshot the generated SQL to verify always/never projection behavior for selector-based projections.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
website/content/docs/hotchocolate/migrating/migrate-from-15-to-16.md Documents the breaking removal of ProjectionFeature and directs users to IsProjected() / [IsProjected].
src/HotChocolate/Data/test/Data.EntityFramework.Tests/IsProjectedSelectorTests.cs Adds SQL-snapshot integration tests for selector-based IsProjected behavior (QueryContext + DataLoader Select(selection)).
src/HotChocolate/Data/src/Data/Projections/ProjectionTypeInterceptor.cs Switches always-projected field detection to internal core flags.
src/HotChocolate/Data/src/Data/Projections/ProjectionFeature.cs Removes the public ProjectionFeature record (breaking API change).
src/HotChocolate/Data/src/Data/Projections/Extensions/ProjectionObjectFieldDescriptorExtensions.cs Writes projection behavior into CoreFieldFlags and sets HasProjectionMiddleware when compiling projection middleware.
src/HotChocolate/Data/src/Data/Projections/Extensions/OutputFieldExtensions.cs Reads projection behavior (NotProjected, AlwaysProjected, HasProjectionMiddleware) from core flags instead of Features.
src/HotChocolate/Core/src/Types/Types/Extensions/OutputFieldDefinitionExtensions.cs Adds internal helper to read CoreFieldFlags from IOutputFieldDefinition implementations.
src/HotChocolate/Core/src/Types/Types/Descriptors/Configurations/CoreFieldFlags.cs Introduces new internal flags used to represent projection state.
src/HotChocolate/Core/src/Execution.Projections/SelectionExpressionBuilder.cs Skips NotProjected fields and injects AlwaysProjected leaf-property fields into selector-based projections.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (34/34)

File Covered Changed Patch %
…/Core/src/Execution.Projections/SelectionExpressionBuilder.cs 17 17 100.0% 🟢
…/Types/Types/Extensions/OutputFieldDefinitionExtensions.cs 1 1 100.0% 🟢
…/src/Data/Projections/Extensions/OutputFieldExtensions.cs 3 3 100.0% 🟢
…/Extensions/ProjectionObjectFieldDescriptorExtensions.cs 11 11 100.0% 🟢
…/Data/src/Data/Projections/ProjectionTypeInterceptor.cs 2 2 100.0% 🟢

Project coverage: 57.5% (283887/493502 lines)

Comment thread src/HotChocolate/Core/src/Execution.Projections/SelectionExpressionBuilder.cs Outdated
@glen-84
glen-84 requested a review from michaelstaib August 26, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for IsProjected to selectors.

3 participants