FSharp.Data.GraphQL
FSharp.Data.GraphQL copied to clipboard
If enum processed by System.Text.Json then it cannot be coerced from enum value
Description
I have rewritten sample server to use System.Text.Json including JsonStringEnumConverter
let serializerOptions =
let options = JsonSerializerOptions(PropertyNamingPolicy = JsonNamingPolicy.CamelCase)
let converters = options.Converters
converters.Add (JsonStringEnumConverter ())
converters.Add (IsbnConverter ())
converters.Add (JsonFSharpConverter ())
options
But the value that comes to this code is enum instance then, but not a string.
| Enum enumdef ->
match input with
| :? string as s ->
ReflectionHelper.parseUnion enumdef.Type s
| _ ->
raise (GraphQLException <| errMsg + (sprintf "Cannot coerce value of type '%O' to type Enum '%s'" (input.GetType()) enumdef.Name))
So that I get FSharp.Data.GraphQL.GraphQLException: 'Variable '$reactionKind': Cannot coerce value of type 'Frebo.Biblioteko.Domain.Reaction' to type Enum 'ReactionEnum''
Repro steps
- Define Enum type
- Use System.Text.Json with
JsonStringEnumConverter - Send mutation with Enum parameter
Expected behavior
Enum successfully coerced
Actual behavior
Only string values are coerced
Known workarounds
Unknown
Related information
- FSharp.Data.GraphQL.Server 1.0.5
I guess there must be a case like | o when Enum.IsDefined(enumdef.Type, o) -> o before default
Fixed in https://github.com/fsprojects/FSharp.Data.GraphQL/pull/283 @johnberzy-bazinga could you have a look?