[StrawberryShake] Custom scalar (non-null reference type) fails client to build when used as Input Type #5999
-
I have project with In directive @serializationType(name: String!) on SCALAR
directive @runtimeType(name: String!) on SCALAR
extend scalar LocalDate
@serializationType(name: "System.String")
@runtimeType(name: "NodaTime.LocalDate") Serializer: public class LocalDateSerializer : ScalarSerializer<string, LocalDate>
{
public LocalDateSerializer() : base(nameof(LocalDate)) { }
public override LocalDate Parse(string serializedValue)
{
var parseResult = LocalDatePattern.Iso.Parse(serializedValue);
if (!parseResult.Success)
throw parseResult.Exception;
return parseResult.Value;
}
protected override string Format(LocalDate runtimeValue)
{
return runtimeValue.ToString("R", CultureInfo.InvariantCulture);
}
} Query looks like query findMyAppointments($pointDate: LocalDate!)
{
findMyAppointments(pointDate: $pointDate)
{
id
}
} And there is error in generated client: Generated fragment: private global::System.Object? FormatPointDate(global::NodaTime.LocalDate value)
{
// This line fails project build: non-nullable type tries to check for null
if (value is null)
{
throw new global::System.ArgumentNullException(nameof(value));
}
return _localDateFormatter.Format(value);
} How to resolve this? StrawberryShake.Blazor version 13.0.5 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I am also running into this same problem 😢 |
Beta Was this translation helpful? Give feedback.
-
I believe I've found a workaround, though this should be documented imo. Change And then define your types as like extend scalar DateTimeZone
@serializationType(name: "global::System.String")
@runtimeType(name: "global::NodaTime.DateTimeZone", valueType: true)
extend scalar Duration
@serializationType(name: "global::System.String")
@runtimeType(name: "global::NodaTime.Duration", valueType: true)
extend scalar Instant
@serializationType(name: "global::System.String")
@runtimeType(name: "global::NodaTime.Instant", valueType: true) This seems to be working for me so far. |
Beta Was this translation helpful? Give feedback.
I believe I've found a workaround, though this should be documented imo.
Change
directive @runtimeType(name: String!) on SCALAR
to
directive @runtimeType(name: String!, valueType: Boolean) on SCALAR
And then define your types as like
This seems to be wo…