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

Class ValueObjectScalarOptions

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

Names, specifications and messages of the scalars AddValueObjects() gives value objects in one schema.

public sealed class ValueObjectScalarOptions

Inheritance​

object ← ValueObjectScalarOptions

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

A scalar is named by the schema's naming conventions, as HotChocolate names the type it would otherwise infer: Iban, ReferenceOfOrder for Reference<Order>, or the name a [GraphQLName] on the struct gives. Two value objects of one name fail the schema at start, naming the second: names one from the composition root, and the name passed to AddValueObjectScalar wins over both.

Every call of AddValueObjects() on one schema configures these same options, in the order of the calls.

Properties​

ResourceType​

Gets the type whose resources hold the messages of refused values, or null to keep the English messages.

public Type? ResourceType { get; }

Property Value​

Type?

Methods​

Name<TSelf>(string)​

Names the scalar of a value object, where two value objects share a name.

public ValueObjectScalarOptions Name<TSelf>(string name) where TSelf : struct, IValueObject

Parameters​

name string

The name of its scalar, a GraphQL name.

Returns​

ValueObjectScalarOptions

These options, so calls can be chained.

Type Parameters​

TSelf

The value object, or a construction of a generic one.

Remarks​

HotChocolate refuses a name that is not a GraphQL name when it builds the schema.

Exceptions​

ArgumentException

name is null, empty or white space.

QuoteScalarNameIn(Func<IInputValueDefinition, bool>)​

Quotes the scalar's name as {0}, rather than the argument or the input field, in the localized message of a value refused in one a predicate selects: an input named after what it does with the value, as the eq or the in of a HotChocolate.Data filter, rather than after what the value is.

public ValueObjectScalarOptions QuoteScalarNameIn(Func<IInputValueDefinition, bool> inputValues)

Parameters​

inputValues Func<IInputValueDefinition, bool>

Selects, by the member the error's coordinate names, the arguments and input fields whose refused values are quoted by the scalar's name. Called in the request, on a refusal alone.

Returns​

ValueObjectScalarOptions

These options, so calls can be chained.

Remarks​

Each call adds a predicate, and a value any of them selects is quoted by the scalar's name. HotChocolate sets the coordinate of an error to the innermost argument or input field it read the refused value under, whatever variable or list holds it: IbanOperationFilterInput.eq for the eq of a filter on an Iban member. A variable HotChocolate reads before any field, as $v in eq: $v, has no coordinate and keeps its name, and a variable's default value keeps the scalar's.

Only the message of a localized refusal changes, which asks for: its code, its path, its inputPath and its coordinate stay HotChocolate's. A predicate that throws fails the error filter, as any error filter that throws does.

Exceptions​

ArgumentNullException

inputValues is null.

SpecifiedBy<TSelf>(string)​

Publishes the URL of the specification of a value object's format, as @specifiedBy.

public ValueObjectScalarOptions SpecifiedBy<TSelf>(string url) where TSelf : struct, IValueObject

Parameters​

url string

The absolute URL of a specification readers of the schema can follow.

Returns​

ValueObjectScalarOptions

These options, so calls can be chained.

Type Parameters​

TSelf

The value object, or a construction of a generic one.

Remarks​

None is published by default: HotChocolate's own scalars point to specifications of their wire forms, and no built-in one describes a value object's.

Exceptions​

ArgumentException

url is not an absolute URL.

UseResource<TResource>()​

Reads the messages of refused values from the resources of TResource, by the key of the rule's code.

public ValueObjectScalarOptions UseResource<TResource>()

Returns​

ValueObjectScalarOptions

These options, so calls can be chained.

Type Parameters​

TResource

The type the resources are named after, as IStringLocalizer<T> names them: an empty class of the application, beside a .resx file of the same name for each culture.

Remarks​

An error filter of the schema looks each refusal up under the keys of , in the current UI culture, and formats it in the current culture with the argument, the input field or the variable the refusal concerns as {0}, or the scalar's name for a variable's default value, which HotChocolate's error names no variable for, and for a value refused in an argument or an input field selects, followed by the arguments reads from the type's rules. A key with no entry keeps the English message, and the code stays the rule's.

The localizer comes from the application's services, which services.AddLocalization() registers; without it, the request executor fails to start, naming the call.

UseResource(Type)​

Reads the messages of refused values from the resources of a type.

public ValueObjectScalarOptions UseResource(Type resourceType)

Parameters​

resourceType Type

The type the resources are named after.

Returns​

ValueObjectScalarOptions

These options, so calls can be chained.

Exceptions​

ArgumentNullException

resourceType is null.