Share scalar value compatibility via IScalarTypeDefinition default - #10147
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes scalar literal compatibility by adding a default IScalarTypeDefinition.IsValueCompatible(IValueNode) implementation so Mutable and Fusion share the same behavior (while ScalarType keeps its own implementation), and it standardizes how SerializationType is resolved from schema directives and known @specifiedBy URLs.
Changes:
- Add a default
IsValueCompatible(IValueNode)implementation toIScalarTypeDefinitionand update Fusion variable coercion to use it; remove Fusion’sScalarValueKindlogic. - Resolve scalar
SerializationTypewith precedence:@serializeAs> recognized@specifiedByURL / spec-scalar name >Undefined; expand the shared URL→type mapping for ChilliCream scalars. - Align float compatibility with GraphQL coercion (accept int literals for float serialization) and add Mutable tests for
@specifiedBymapping and directive precedence.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Mutable/test/Types.Mutable.Tests/ScalarSerializationTypeTests.cs | Adds tests for resolving serialization type from @specifiedBy and for @serializeAs precedence. |
| src/HotChocolate/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs | Applies fallback serialization-type resolution when @serializeAs does not provide one. |
| src/HotChocolate/Mutable/src/Types.Mutable/MutableScalarTypeDefinition.cs | Initializes spec-scalar serialization types by name; removes per-type IsValueCompatible implementation to rely on the shared default. |
| src/HotChocolate/Fusion/src/Fusion.Execution/Execution/JsonVariableCoercion.cs | Switches scalar literal compatibility checks to the shared IScalarTypeDefinition implementation. |
| src/HotChocolate/Fusion/src/Fusion.Execution.Types/ScalarResultType.cs | Removes ScalarValueKind enum. |
| src/HotChocolate/Fusion/src/Fusion.Execution.Types/FusionScalarTypeDefinition.cs | Drops ScalarValueKind handling; resolves SerializationType via @serializeAs or @specifiedBy/name mapping. |
| src/HotChocolate/Fusion/src/Fusion.Execution.Types/Completion/CompositeSchemaContext.cs | Simplifies spec-scalar creation to rely on shared serialization-type resolution. |
| src/HotChocolate/Fusion/src/Fusion.Execution.Types/Completion/CompositeSchemaBuilder.cs | Updates scalar completion context construction after removing ScalarValueKind. |
| src/HotChocolate/Fusion/src/Fusion.Execution.Types/Completion/CompositeScalarTypeCompletionContext.cs | Removes ScalarValueKind from completion context. |
| src/HotChocolate/Core/src/Types/Types/Scalars/ScalarType.cs | Updates scalar literal compatibility for undefined serialization types and allows int literals for float serialization. |
| src/HotChocolate/Core/src/Types.Abstractions/Types/IScalarTypeDefinition.cs | Adds the shared default IsValueCompatible(IValueNode) implementation. |
| src/HotChocolate/Core/src/Types.Abstractions/Types/Extensions/HotChocolateTypesAbstractionsScalarDefinitionExtensions.cs | Expands recognized @specifiedBy URL mappings to cover ChilliCream scalars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Patch coverage97.2% of changed lines covered (70/72)
Uncovered changed lines (JSON){
"sha": "dfa1b7e1f8076f3ab9d5864be75ac07c35df61a7",
"files": [
{ "path": "src/HotChocolate/Core/src/Types/Types/Scalars/ScalarType.cs", "ranges": [[129, 130]] }
]
}Project coverage: 53.8% (231801/430644 lines) |
This was referenced Aug 9, 2026
Merged
Open
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
IsValueCompatible(IValueNode)gains a default implementation onIScalarTypeDefinition, so Mutable and Fusion share one definition of scalar literal compatibility (Fusion drops itsScalarValueKindenum).ScalarTypekeeps its own matching copy, since it also implementsILeafTypeand is subclassed.SerializationTypeis resolved from a schema (Mutable, Fusion), an explicit@serializeAsdirective takes precedence, then a recognized@specifiedByURL or spec-scalar name, otherwise it stays undefined. The shared URL mapping now covers all ChilliCream scalars.Floataccepts integer literals (GraphQL int→float input coercion), and a scalar with an unknown serialization type accepts any literal.SerializationTypeconsistently describes what a scalar serializes to (ID= string or int,Float= float).Test plan
ScalarSerializationTypeTestscovers serialization-type resolution, including the@specifiedByURL mapping and@serializeAsprecedence.VariableCoercionTests,AnyScalarTests,VariableCoercionHelperTests) and core scalar suites (FloatTypeTests,DecimalTypeTests,IdTypeTests) pass.Types.Tests,Types.Mutable.Tests,Fusion.Execution.Tests,Fusion.Composition.Tests, and both Adapters suites pass.