forked from OSS/graphql-spice
Add instances for Float and Double
This commit is contained in:
parent
4bd243b7ec
commit
64d7545bc6
@ -8,7 +8,8 @@ and this project adheres to
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
- `ToGraphQL` and `FromGraphQL` instances for `Word`.
|
- `ToGraphQL` and `FromGraphQL` instances for `Word` types, `Float` and
|
||||||
|
`Double`.
|
||||||
- `Resolver`: Export `ServerException`.
|
- `Resolver`: Export `ServerException`.
|
||||||
- `Resolver.defaultResolver`: Throw `FieldNotResolvedException` if the requested
|
- `Resolver.defaultResolver`: Throw `FieldNotResolvedException` if the requested
|
||||||
field is not in the parent object.
|
field is not in the parent object.
|
||||||
|
@ -79,6 +79,12 @@ instance ToGraphQL a => ToGraphQL (Maybe a) where
|
|||||||
instance ToGraphQL Bool where
|
instance ToGraphQL Bool where
|
||||||
toGraphQL = Type.Boolean
|
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
|
-- | Instances of this typeclass can be used to convert GraphQL internal
|
||||||
-- representation to user-defined type.
|
-- representation to user-defined type.
|
||||||
class FromGraphQL a where
|
class FromGraphQL a where
|
||||||
@ -134,3 +140,11 @@ instance FromGraphQL a => FromGraphQL (Maybe a) where
|
|||||||
instance FromGraphQL Bool where
|
instance FromGraphQL Bool where
|
||||||
fromGraphQL (Type.Boolean value) = Just value
|
fromGraphQL (Type.Boolean value) = Just value
|
||||||
fromGraphQL _ = Nothing
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user