summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/Resolver.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/GraphQL/Resolver.hs')
-rw-r--r--src/Language/GraphQL/Resolver.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Language/GraphQL/Resolver.hs b/src/Language/GraphQL/Resolver.hs
index dbf9a6a..c3d6660 100644
--- a/src/Language/GraphQL/Resolver.hs
+++ b/src/Language/GraphQL/Resolver.hs
@@ -6,13 +6,14 @@
-- | Helper functions and exceptions to write resolvers.
module Language.GraphQL.Resolver
- ( argument
+ ( ServerException(..)
+ , argument
, defaultResolver
) where
import Control.Monad.Catch (Exception(..), MonadCatch(..), MonadThrow(..))
import Control.Monad.Trans.Reader (ReaderT, asks)
-import Data.HashMap.Strict ((!))
+import qualified Data.HashMap.Strict as HashMap
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Typeable (cast)
@@ -49,7 +50,8 @@ defaultResolver :: MonadCatch m => Name -> Type.Resolve m
defaultResolver fieldName = do
values' <- asks Type.values
case values' of
- Type.Object objectValue -> pure $ objectValue ! fieldName
+ Type.Object objectValue
+ | Just result <- HashMap.lookup fieldName objectValue -> pure result
_nonObject -> throwM $ FieldNotResolvedException fieldName
-- | Takes an argument name, validates that the argument exists, and optionally