Idea here is to change signature of the existing scalar coerce function to return Choice<,> insteaf of option<>. Reason for that is that we want to use custom scalars to apply first-level validation i.e:
let FixedString n =
Define.Scalar<string>(
sprintf "String(%i)" n,
(fun (StringValue s) -> if s.Length <= n then Choice1Of2 s | _ -> Choice2Of2 "invalid"),
(fun v -> match v with :? string as s when s.Length <= n -> Choice1Of2 s | _ -> Choice2Of2 "invalid"))
As we don't want to simply return null (like JS implementation does), we want to explicitly inform about an invalid type.
Idea here is to change signature of the existing scalar coerce function to return
Choice<,>insteaf ofoption<>. Reason for that is that we want to use custom scalars to apply first-level validation i.e:As we don't want to simply return null (like JS implementation does), we want to explicitly inform about an invalid type.