Description
We have currently issues when scalar types are not convertible to a desired type of an input or variable etc. The main reason for that is, that we do not have a clear strategy for that until now. There are currently two or three ways how we tackle this problem.
This PBI shall clarify how we will handle type conversion going forward.
Type converters shall be declared schema wise. This means each schema instance has its own set of converters. Since, also every schema defines its own set of scalars this seems to be natural.
The conversion of values shall be done through the new interface ITypeConversion
which can be retrieved through dependency injection.
In order to register a type converter one can register a type conversion delegate with the ITypeConversion
interface or register an ITypeConverter
as service.
public interface ITypeConversion
{
bool TryConvert(Type from, Type to, object value, out object converted);
void Register(Type from, Type to, Func<object, object> converter);
}
public interface ITypeConverter
{
Type From { get; }
Type To { get; }
object Convert(object input);
}