diff options
| author | Eugen Wissner <belka@caraus.de> | 2019-11-23 09:49:12 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2019-11-23 09:49:12 +0100 |
| commit | 587aab005ed1e4e9bd8966d44ff878891cbc8ce7 (patch) | |
| tree | d86af4e8705104e78aa753017e5444ef707405e2 /src/Language/GraphQL/Trans.hs | |
| parent | 625d7100ca123e5aff265fb843ec4979d76a9f7d (diff) | |
| download | graphql-587aab005ed1e4e9bd8966d44ff878891cbc8ce7.tar.gz | |
Add a reader instance to the resolvers
The Reader contains a Name/Value hashmap, which will contain resolver
arguments.
Diffstat (limited to 'src/Language/GraphQL/Trans.hs')
| -rw-r--r-- | src/Language/GraphQL/Trans.hs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Language/GraphQL/Trans.hs b/src/Language/GraphQL/Trans.hs index eb78911..4232e75 100644 --- a/src/Language/GraphQL/Trans.hs +++ b/src/Language/GraphQL/Trans.hs @@ -1,6 +1,7 @@ -- | Monad transformer stack used by the @GraphQL@ resolvers. module Language.GraphQL.Trans ( ActionT(..) + , Context(Context) ) where import Control.Applicative (Alternative(..)) @@ -8,10 +9,19 @@ import Control.Monad (MonadPlus(..)) import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.Trans.Class (MonadTrans(..)) import Control.Monad.Trans.Except (ExceptT) +import Control.Monad.Trans.Reader (ReaderT) +import Data.HashMap.Strict (HashMap) import Data.Text (Text) +import Language.GraphQL.AST.Core (Name, Value) --- | Monad transformer stack used by the resolvers to provide error handling. -newtype ActionT m a = ActionT { runActionT :: ExceptT Text m a } +-- | Resolution context holds resolver arguments. +newtype Context = Context (HashMap Name Value) + +-- | Monad transformer stack used by the resolvers to provide error handling +-- and resolution context (resolver arguments). +newtype ActionT m a = ActionT + { runActionT :: ExceptT Text (ReaderT Context m) a + } instance Functor m => Functor (ActionT m) where fmap f = ActionT . fmap f . runActionT @@ -25,7 +35,7 @@ instance Monad m => Monad (ActionT m) where (ActionT action) >>= f = ActionT $ action >>= runActionT . f instance MonadTrans ActionT where - lift = ActionT . lift + lift = ActionT . lift . lift instance MonadIO m => MonadIO (ActionT m) where liftIO = lift . liftIO |
