Sviatoslav Bulbakha

418 I'm a teapot

Use float as strings in elm-graphql

Many API's using String instead of Float to represent decimal numbers (read this answer at SO). Thats how you can decode it with elm-graphql:

type FloatStringType
    = FloatStringType

floatString : ValueSpec NonNull FloatStringType Float vars
floatString =
        |> J.andThen
            (\val ->
                case String.toFloat val of
                    Ok f ->
                        J.succeed f

                    Err reason ->
        |> customScalar FloatStringType

And then use it like any other type:

|> with (field "price" [] floatString)


comments powered by Disqus