FSharp.Data.GraphQL icon indicating copy to clipboard operation
FSharp.Data.GraphQL copied to clipboard

Modify scalar coerce functions

Open Horusiath opened this issue 9 years ago • 1 comments

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.

Horusiath avatar Oct 14 '16 12:10 Horusiath

https://github.com/fsprojects/FSharp.Data.GraphQL/issues/274

xperiandri avatar Apr 05 '20 11:04 xperiandri

Implemented in #418, use the latest preview packages from the GitHub feed

xperiandri avatar Nov 05 '23 23:11 xperiandri