FSharp.Data.GraphQL
FSharp.Data.GraphQL copied to clipboard
int value could be valid float value
Description
For a data of type float
when value extracted from response is int
the code fail to run
Repro steps
- create schema with double or float
- respond with integer value
Expected behavior
value should be casted
Actual behavior
Fail with exception
Known workarounds
Can you be more specific? I'm not sure I get the error here. Do you mean you're trying to return an integer from a resolver that is typed to be a Float
?
In schema you got something like this :
"fields": [
{
"name": "amount",
"description": "",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Float",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
But the server (not one done in fsharp, from someone else) is responding with
{ "Amount": 100 , .....}
In RecordBase diconnary it will be deserialize as INT but the type that we expect is FLOAT. My ugly work around is that
let flt (dico:IDictionary<string,obj>) (key:string) =
let value = dico.[key]
let s = value.ToString()
let r = TryParser.parseDouble s |> Option.defaultValue 0.0
r
let fltOpt (dico:IDictionary<string,obj>) (key:string) =
let value = dico.[key]
let s = value.ToString()
let r = TryParser.parseDouble s
r
Fixed, use latest preview packages from the GitHub feed