Skip to content

Share scalar value compatibility via IScalarTypeDefinition default - #10147

Merged
glen-84 merged 5 commits into
mainfrom
gai/share-scalar-value-compatibility
Jul 23, 2026
Merged

Share scalar value compatibility via IScalarTypeDefinition default#10147
glen-84 merged 5 commits into
mainfrom
gai/share-scalar-value-compatibility

Conversation

@glen-84

@glen-84 glen-84 commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

  • IsValueCompatible(IValueNode) gains a default implementation on IScalarTypeDefinition, so Mutable and Fusion share one definition of scalar literal compatibility (Fusion drops its ScalarValueKind enum). ScalarType keeps its own matching copy, since it also implements ILeafType and is subclassed.
  • When a scalar's SerializationType is resolved from a schema (Mutable, Fusion), an explicit @serializeAs directive takes precedence, then a recognized @specifiedBy URL or spec-scalar name, otherwise it stays undefined. The shared URL mapping now covers all ChilliCream scalars.
  • Float accepts integer literals (GraphQL int→float input coercion), and a scalar with an unknown serialization type accepts any literal. SerializationType consistently describes what a scalar serializes to (ID = string or int, Float = float).

Test plan

  • ScalarSerializationTypeTests covers serialization-type resolution, including the @specifiedBy URL mapping and @serializeAs precedence.
  • Fusion variable coercion (VariableCoercionTests, AnyScalarTests, VariableCoercionHelperTests) and core scalar suites (FloatTypeTests, DecimalTypeTests, IdTypeTests) pass.
  • Full Types.Tests, Types.Mutable.Tests, Fusion.Execution.Tests, Fusion.Composition.Tests, and both Adapters suites pass.

Copilot AI review requested due to automatic review settings July 23, 2026 13:21

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 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 to IScalarTypeDefinition and update Fusion variable coercion to use it; remove Fusion’s ScalarValueKind logic.
  • Resolve scalar SerializationType with precedence: @serializeAs > recognized @specifiedBy URL / 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 @specifiedBy mapping 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.

Comment thread src/HotChocolate/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs Outdated
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Patch coverage

97.2% of changed lines covered (70/72)

File Covered Changed Patch %
src/HotChocolate/Core/src/Types/Types/Scalars/ScalarType.cs 2 4 50.0% 🔴
…/HotChocolateTypesAbstractionsScalarDefinitionExtensions.cs 18 18 100.0% 🟢
…/Core/src/Types.Abstractions/Types/IScalarTypeDefinition.cs 31 31 100.0% 🟢
…/Fusion.Execution.Types/Completion/CompositeSchemaContext.cs 1 1 100.0% 🟢
…/src/Fusion.Execution.Types/FusionScalarTypeDefinition.cs 3 3 100.0% 🟢
…/src/Fusion.Execution/Execution/JsonVariableCoercion.cs 1 1 100.0% 🟢
…/Mutable/src/Types.Mutable/MutableScalarTypeDefinition.cs 4 4 100.0% 🟢
…/Mutable/src/Types.Mutable/Serialization/SchemaParser.cs 10 10 100.0% 🟢
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)

@glen-84
glen-84 merged commit f96571a into main Jul 23, 2026
147 checks passed
@glen-84
glen-84 deleted the gai/share-scalar-value-compatibility branch July 23, 2026 15:45
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.

2 participants