Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectScalarType<TSelf, TValue>

Namespace: AdCodicem.ValueObjects.HotChocolate
Assembly: AdCodicem.ValueObjects.HotChocolate.dll

A value object as a GraphQL scalar of its own, whose literal is its underlying value's.

public sealed class ValueObjectScalarType<TSelf, TValue> : ScalarType, IScalarTypeDefinition, ISyntaxNodeProvider<ScalarTypeDefinitionNode>, ILeafType, IInputTypeDefinition, IInputType, IOutputTypeDefinition, ITypeDefinition, INameProvider, IDescriptionProvider, IDirectivesProvider, IFeatureProvider, ISyntaxNodeProvider, ISchemaCoordinateProvider, IRuntimeTypeProvider, IOutputType, IType, ITypeSystemMember, IEquatable<IType> where TSelf : struct, IValueObject<TSelf, TValue>

Type Parameters​

TSelf

The value object type.

TValue

Its underlying type.

Inheritance​

object ← TypeSystemObject ← TypeSystemObject<ScalarTypeConfiguration> ← ScalarType ← ValueObjectScalarType<TSelf, TValue>

Implements​

IScalarTypeDefinition, ISyntaxNodeProvider<ScalarTypeDefinitionNode>, ILeafType, IInputTypeDefinition, IInputType, IOutputTypeDefinition, ITypeDefinition, INameProvider, IDescriptionProvider, IDirectivesProvider, IFeatureProvider, ISyntaxNodeProvider, ISchemaCoordinateProvider, IRuntimeTypeProvider, IOutputType, IType, ITypeSystemMember, IEquatable<IType>

Inherited Members​

ScalarType.IsAssignableFrom(ITypeDefinition), ScalarType.Equals(IType?), ScalarType.IsValueCompatible(IValueNode), ScalarType.IsValueCompatible(JsonElement), ScalarType.CoerceInputLiteral(IValueNode), ScalarType.CoerceInputValue(JsonElement, IFeatureProvider), ScalarType.CoerceOutputValue(object, ResultElement), ScalarType.ValueToLiteral(object), ScalarType.InputValueToLiteral(JsonElement, IFeatureProvider), ScalarType.ToString(), ScalarType.ToSyntaxNode(), ScalarType.Kind, ScalarType.Bind, ScalarType.RuntimeType, ScalarType.Coordinate, ScalarType.SpecifiedBy, ScalarType.SerializationType, ScalarType.Pattern, ScalarType.Directives, TypeSystemObject<ScalarTypeConfiguration>.Features, TypeSystemObject.Scope, TypeSystemObject.Name, TypeSystemObject.Description, TypeSystemObject.Features, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

A value object over a is serialized as a Boolean, one over an integer of 64 bits at most as an Int, whatever its width, and one over a real as a Float, read from an Int literal too. Every other one, over text, a character, a , a 128-bit integer, a date or a time, or a value object written by hand over another type, is serialized as a String, read through TSelf.TryParse in the invariant culture, its normalizer included. A number is read exactly as the underlying type, then goes through TSelf.TryCreate.

A value the type refuses is answered with a whose GraphQL error carries the message of the violated rule and, as its extensions.code, the rule's code; the exception carries the code in its under , and the error's Exception is a with the type and the code, never the value. A literal or a JSON value of another kind, or a number the underlying type cannot hold, is refused with . GraphQL input always comes from a client, so a scalar always validates.

A value is written as its underlying value, never through a formatting hook of the value object. An uninitialized instance, equal to the default, whose value the type refuses is never written, nor is a real that is not finite.

The description is the type's, from its schema. The pattern it declares, or the one the wire form of a duration, a time of day or a follows, is the scalar's , which HotChocolate publishes as @serializeAs under ApplySerializeAsToScalars. GraphQL has no place for a length, a bound or a known value.

Properties​

RuntimeType​

The .NET type representation of this scalar.

public override Type RuntimeType { get; }

Property Value​

Type

SerializationType​

Gets the possible types that this scalar can serialize to.

public override ScalarSerializationType SerializationType { get; }

Property Value​

ScalarSerializationType

Methods​

CoerceInputLiteral(IValueNode)​

Coerces a GraphQL literal (AST value node) into a runtime value.

public override object CoerceInputLiteral(IValueNode valueLiteral)

Parameters​

valueLiteral IValueNode

The GraphQL literal to coerce.

Returns​

object

Returns the runtime value representation.

Exceptions​

ArgumentNullException

valueLiteral is null.

LeafCoercionException

Unable to coerce the given valueLiteral into a runtime value.

CoerceInputValue(JsonElement, IFeatureProvider)​

Coerces an external input value (deserialized JSON) into a runtime value.

public override object CoerceInputValue(JsonElement inputValue, IFeatureProvider context)

Parameters​

inputValue JsonElement

The deserialized JSON input value to coerce.

context IFeatureProvider

Provides access to the coercion context.

Returns​

object

Returns the runtime value representation.

Exceptions​

LeafCoercionException

Unable to coerce the given inputValue into a runtime value.

CoerceOutputValue(object, ResultElement)​

Coerces a runtime value into an external output representation and writes it to the result.

public override void CoerceOutputValue(object runtimeValue, ResultElement resultValue)

Parameters​

runtimeValue object

The runtime value to coerce. Must not be null; null handling is the responsibility of the caller.

resultValue ResultElement

The result element to write the output value to.

Exceptions​

ArgumentNullException

runtimeValue is null.

LeafCoercionException

Unable to coerce the given runtimeValue into an output value.

CreateConfiguration(ITypeDiscoveryContext)​

protected override ScalarTypeConfiguration CreateConfiguration(ITypeDiscoveryContext context)

Parameters​

context ITypeDiscoveryContext

Returns​

ScalarTypeConfiguration

ValueToLiteral(object)​

Converts a runtime value into a GraphQL literal (AST value node). Used for default value representation in SDL and introspection.

public override IValueNode ValueToLiteral(object runtimeValue)

Parameters​

runtimeValue object

The runtime value to convert. Must not be null; null handling is the responsibility of the caller.

Returns​

IValueNode

Returns a GraphQL literal representation of the runtime value.

Exceptions​

ArgumentNullException

runtimeValue is null.

LeafCoercionException

Unable to convert the given runtimeValue into a literal.