diff options
| author | prescientmoon <git@moonythm.dev> | 2024-11-19 20:21:41 +0100 |
|---|---|---|
| committer | prescientmoon <git@moonythm.dev> | 2024-11-19 20:21:41 +0100 |
| commit | 8aa2e521c4a16b8a350b120f19c1fcb650a9db1a (patch) | |
| tree | a46500fc156fa2ef56cfba8fd6bbb92824ea0b1a /src/Language/GraphQL/Class.hs | |
| parent | e7fbf8b88a50ab844f859d614e7cbcf0241ef989 (diff) | |
| download | graphql-spice-8aa2e521c4a16b8a350b120f19c1fcb650a9db1a.tar.gz | |
Add a few missing instances
Diffstat (limited to 'src/Language/GraphQL/Class.hs')
| -rw-r--r-- | src/Language/GraphQL/Class.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Language/GraphQL/Class.hs b/src/Language/GraphQL/Class.hs index 938fcf0..6e8b080 100644 --- a/src/Language/GraphQL/Class.hs +++ b/src/Language/GraphQL/Class.hs @@ -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 |
