Repository navigation
Make cursor key extraction null-safe for nullable nested fields - #9953
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes cursor key extraction for cursor-paginated connections when sorting by nullable nested fields by compiling cursor key selectors into a null-safe delegate that short-circuits to a null key instead of throwing on null intermediates.
Changes:
- Compile cursor key selector expressions into a null-safe delegate (
NullSafeKeySelector) that mirrors C#’s null-conditional behavior and evaluates intermediates once. - Add unit tests covering null/non-null nested intermediates, deep chains, single evaluation, overloaded equality, nullable value-type intermediates, and cast intermediates.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/GreenDonut/src/GreenDonut.Data/Cursors/CursorKey.cs | Switches key selector compilation to a null-safe compiler to prevent null dereference crashes during cursor formatting. |
| src/GreenDonut/test/GreenDonut.Data.Tests/Cursors/CursorFormatterTests.cs | Adds focused tests validating null-safe nested cursor key formatting behavior across several edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the Show a code coverage summary of the most impacted files.
Updated |
This was referenced Jun 22, 2026
This was referenced Jul 2, 2026
Closed
Closed
This was referenced Jul 7, 2026
This was referenced Jul 14, 2026
This was referenced Jul 23, 2026
chore(deps): Bump HotChocolate.Subscriptions.InMemory from 15.1.14 to 16.5.1
Kuestenlogik/Bowire#506
Merged
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.
Summary
order: [{ meter: { name: ASC } }]) crashed with "Unexpected Execution Error" whenever an intermediate navigation was null: the cursor key selector was compiled and invoked verbatim, so it dereferenced the null and threw. The crash surfaced forConnection-returning resolvers (which eagerly create start/end cursors) even when no cursor field was selected.CursorKeynow compiles the selector into a null-safe delegate (NullSafeKeySelector) that mirrors the C# null-conditional operator: each nullable intermediate is bound to a local and evaluated once, reference /HasValuenull checks short-circuit to a null key value (which the serializer already formats as the null marker), and intermediate casts/conversions are preserved so member access rebinds against the correct type.Test plan
CursorFormatterTestscovering null and non-null nested intermediates, deep chains, single evaluation (counting getter), overloaded==, a nullable value-type intermediate, and a cast intermediate.GreenDonut.Data.Tests: 364/364 pass.