Add a few missing instances #9
@ -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