Add a few missing instances

This commit is contained in:
prescientmoon 2024-11-19 20:21:41 +01:00
parent e7fbf8b88a
commit 8aa2e521c4
Signed by: prescientmoon
SSH Key Fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4

View File

@ -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