From 09135c581aaae471f7d964bc2a3a141bef299097 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 17 Jul 2020 07:05:03 +0200 Subject: Constrain base monad to MonadCatch Let's try MonadThrow/MonadCatch. It looks nice at a first glance. The monad transformer stack contains only the ReaderT, less lifts are required. Exception subtyping is easier, the user can (and should) define custom error types and throw them. And it is still possible to use pure error handling, if someone doesn't like runtime exceptions or need to run a query in a pure environment. Fixes #42. --- src/Language/GraphQL.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/Language/GraphQL.hs') diff --git a/src/Language/GraphQL.hs b/src/Language/GraphQL.hs index 6ee2dd7..1b8c562 100644 --- a/src/Language/GraphQL.hs +++ b/src/Language/GraphQL.hs @@ -7,6 +7,7 @@ module Language.GraphQL , graphqlSubs ) where +import Control.Monad.Catch (MonadCatch) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson import Data.Either (fromRight) @@ -20,7 +21,7 @@ import Text.Megaparsec (parse) -- | If the text parses correctly as a @GraphQL@ query the query is -- executed using the given 'Schema'. -graphql :: Monad m +graphql :: MonadCatch m => Schema m -- ^ Resolvers. -> Text -- ^ Text representing a @GraphQL@ request document. -> m Aeson.Value -- ^ Response. @@ -29,7 +30,7 @@ graphql schema = graphqlSubs schema mempty mempty -- | If the text parses correctly as a @GraphQL@ query the substitution is -- applied to the query and the query is then executed using to the given -- 'Schema'. -graphqlSubs :: Monad m +graphqlSubs :: MonadCatch m => Schema m -- ^ Resolvers. -> Maybe Text -- ^ Operation name. -> Aeson.Object -- ^ Variable substitution function. -- cgit v1.2.3