Add a few missing instances
All checks were successful
Build / audit (pull_request) Successful in 10s
Build / test (pull_request) Successful in 6m59s
Build / doc (pull_request) Successful in 7m7s
Build / audit (push) Successful in 6s
Build / test (push) Successful in 6m59s
Build / doc (push) Successful in 7m2s
All checks were successful
Build / audit (pull_request) Successful in 10s
Build / test (pull_request) Successful in 6m59s
Build / doc (pull_request) Successful in 7m7s
Build / audit (push) Successful in 6s
Build / test (push) Successful in 6m59s
Build / doc (push) Successful in 7m2s
This commit is contained in:
parent
e7fbf8b88a
commit
8aa2e521c4
@ -5,6 +5,7 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
|
||||
-- | ToGraphQL and FromGraphQL typeclasses used for user-defined type
|
||||
-- conversion.
|
||||
@ -101,6 +102,10 @@ class ToGraphQL a
|
||||
where
|
||||
toGraphQL :: a -> Type.Value
|
||||
|
||||
instance ToGraphQL Type.Value
|
||||
where
|
||||
toGraphQL a = a
|
||||
|
||||
instance ToGraphQL Text
|
||||
where
|
||||
toGraphQL = Type.String
|
||||
@ -198,12 +203,20 @@ instance ToGraphQL LocalTime
|
||||
where
|
||||
toGraphQL = iso8601ToGraphQL
|
||||
|
||||
instance ToGraphQL a => ToGraphQL (HashMap.HashMap Text a)
|
||||
where
|
||||
toGraphQL = Type.Object . fmap toGraphQL
|
||||
|
||||
-- | Instances of this typeclass can be used to convert GraphQL internal
|
||||
-- representation to user-defined type.
|
||||
class FromGraphQL a
|
||||
where
|
||||
fromGraphQL :: Type.Value -> Maybe a
|
||||
|
||||
instance FromGraphQL Type.Value
|
||||
where
|
||||
fromGraphQL = Just
|
||||
|
||||
instance FromGraphQL Text
|
||||
where
|
||||
fromGraphQL (Type.String value) = Just value
|
||||
@ -311,6 +324,11 @@ instance FromGraphQL LocalTime
|
||||
where
|
||||
fromGraphQL = fromGraphQLToISO8601
|
||||
|
||||
instance FromGraphQL a => FromGraphQL (HashMap.HashMap Text a)
|
||||
where
|
||||
fromGraphQL (Type.Object hm) = traverse fromGraphQL hm
|
||||
fromGraphQL _ = Nothing
|
||||
|
||||
stringLE :: Name -> Q Exp
|
||||
stringLE = litE . stringL . nameBase
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user