fix(csharp): support nullable DateOnly and TimeSpan scalar mappings - #1549
Open
grounzero wants to merge 2 commits into
Open
fix(csharp): support nullable DateOnly and TimeSpan scalar mappings#1549grounzero wants to merge 2 commits into
grounzero wants to merge 2 commits into
Conversation
Add DateOnly, TimeSpan, and DateTimeOffset to the C# value-type allow list, enabling nullable suffix generation for GraphQL scalar fields mapped to these .NET value types. These are built-in .NET value types and should be treated consistently with DateTime for nullable field generation. This fix corrects broken code generation for schemas using these scalar mappings.
🦋 Changeset detectedLatest commit: 3584743 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Add DateOnly, TimeSpan, and DateTimeOffset to the C# value-type allow list, enabling nullable suffix generation for GraphQL scalar fields mapped to these .NET value types.
These are built-in .NET value types and should be treated consistently with DateTime for nullable field generation. This fix corrects broken code generation for schemas using these scalar mappings.
Description
This PR adds support for nullable C# value-type scalar mappings to
DateOnly,TimeSpan, andDateTimeOffsetin the C# code generator plugins.Related #1548
Problem
When GraphQL nullable scalar fields are mapped to these .NET value types via scalar configuration, the code generator was failing to append the nullable suffix (
?), producing invalid C# code. The nullable logic was already correctly implemented in the field type resolver—it just needed these types added to the value-type allow list.Root Cause
The
csharpValueTypesarray inpackages/plugins/c-sharp/c-sharp-common/src/scalars.tswas incomplete. TheisValueType()helper function checks membership in this list. WhileDateTimewas included, the other built-in .NET value types were missing.Solution
Extended the
csharpValueTypesallow list to includeDateOnly,TimeSpan, andDateTimeOffset. This is a minimal, focused change (3 lines) that leverages existing nullable suffix logic.Impact
public DateOnly duration { get; set; }❌ (invalid—should be nullable)public DateOnly? duration { get; set; }✅ (correct)Backwards Compatibility
✅ Fully backwards compatible—only extends the type list. No breaking changes. This fix corrects previously broken behavior for schemas using these scalar mappings.
Type of change
Screenshots/Sandbox
N/A — Data structure modification with## Description
Screenshots/Sandbox
How Has This Been Tested?
This fix has been validated with comprehensive regression tests covering all four value-type scenarios:
C# Schema Plugin Test: "Should properly treat value-type scalar mappings nullability"
Tests Added
File: c-sharp.spec.ts lines 723-765)
✅ DateTime nullable mapping → DateTime?
✅ DateOnly nullable mapping → DateOnly?
✅ TimeSpan nullable mapping → TimeSpan?
✅ DateTimeOffset nullable mapping → DateTimeOffset?
File: c-sharp-operations.spec.ts (lines 250-304)
✅ Response class with optional DateTime fields → DateTime?
✅ Response class with optional DateOnly fields → DateOnly?
✅ Response class with optional TimeSpan fields → TimeSpan?
✅ Response class with optional DateTimeOffset fields → DateTimeOffset?
Test Environment:
Checklist:
CONTRIBUTING doc and the
style guidelines of this project