FSharp.Data.GraphQL
FSharp.Data.GraphQL copied to clipboard
Modify scalar coerce functions
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.
https://github.com/fsprojects/FSharp.Data.GraphQL/issues/274
Implemented in #418, use the latest preview packages from the GitHub feed