diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-05-07 17:19:57 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-05-07 17:19:57 +0200 |
| commit | 64d7545bc696070f3df6cc90ee65dabd852ea2d3 (patch) | |
| tree | 421733f027c68a6ae1f1b4a30e1a2a4877e53382 | |
| parent | 4bd243b7ec9e564e82d53d1b5ab4076f33888d20 (diff) | |
| download | graphql-spice-64d7545bc696070f3df6cc90ee65dabd852ea2d3.tar.gz | |
Add instances for Float and Double
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | src/Language/GraphQL/Class.hs | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 80a6bc3..af4c443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ and this project adheres to ## [Unreleased] ### Added -- `ToGraphQL` and `FromGraphQL` instances for `Word`. +- `ToGraphQL` and `FromGraphQL` instances for `Word` types, `Float` and + `Double`. - `Resolver`: Export `ServerException`. - `Resolver.defaultResolver`: Throw `FieldNotResolvedException` if the requested field is not in the parent object. diff --git a/src/Language/GraphQL/Class.hs b/src/Language/GraphQL/Class.hs index b363fd0..89b4337 100644 --- a/src/Language/GraphQL/Class.hs +++ b/src/Language/GraphQL/Class.hs @@ -79,6 +79,12 @@ instance ToGraphQL a => ToGraphQL (Maybe a) where instance ToGraphQL Bool where toGraphQL = Type.Boolean +instance ToGraphQL Float where + toGraphQL = Type.Float . realToFrac + +instance ToGraphQL Double where + toGraphQL = Type.Float + -- | Instances of this typeclass can be used to convert GraphQL internal -- representation to user-defined type. class FromGraphQL a where @@ -134,3 +140,11 @@ instance FromGraphQL a => FromGraphQL (Maybe a) where instance FromGraphQL Bool where fromGraphQL (Type.Boolean value) = Just value fromGraphQL _ = Nothing + +instance FromGraphQL Float where + fromGraphQL (Type.Float value) = Just $ realToFrac value + fromGraphQL _ = Nothing + +instance FromGraphQL Double where + fromGraphQL (Type.Float value) = Just value + fromGraphQL _ = Nothing |
