summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2021-05-09 12:34:39 +0200
committerEugen Wissner <belka@caraus.de>2021-05-09 12:42:02 +0200
commit0d23df3da29cfe0b78af922cea71db5fa1d5c98c (patch)
tree9dd71e8bbf92d3c0e71144b552d195f8baa8afe7 /src
parent5a5f265fe4bf291c1ef58f5fe452f1e8c69c9ed6 (diff)
downloadgraphql-0d23df3da29cfe0b78af922cea71db5fa1d5c98c.tar.gz
Provide an internal function to add errors
The old function, addErrMsg, takes only a string with an error description, but more information is required for the execution errors: locations and path. addErrMsg should be deprecated after the switching to the new addError.
Diffstat (limited to 'src')
-rw-r--r--src/Language/GraphQL/Execute/Execution.hs3
-rw-r--r--src/Language/GraphQL/Execute/Internal.hs25
2 files changed, 27 insertions, 1 deletions
diff --git a/src/Language/GraphQL/Execute/Execution.hs b/src/Language/GraphQL/Execute/Execution.hs
index 0ea361d..38355ce 100644
--- a/src/Language/GraphQL/Execute/Execution.hs
+++ b/src/Language/GraphQL/Execute/Execution.hs
@@ -21,6 +21,7 @@ import qualified Data.Text as Text
import Language.GraphQL.AST (Name)
import Language.GraphQL.Error
import Language.GraphQL.Execute.Coerce
+import Language.GraphQL.Execute.Internal
import Language.GraphQL.Execute.OrderedMap (OrderedMap)
import qualified Language.GraphQL.Execute.OrderedMap as OrderedMap
import qualified Language.GraphQL.Execute.Transform as Transform
@@ -123,7 +124,7 @@ completeValue outputType@(Out.EnumBaseType enumType) _ (Type.Enum enum) =
let Type.EnumType _ _ enumMembers = enumType
in if HashMap.member enum enumMembers
then coerceResult outputType $ Enum enum
- else addErrMsg "Enum value completion failed."
+ else addError $ Error "Enum value completion failed." [] []
completeValue (Out.ObjectBaseType objectType) fields result =
executeSelectionSet result objectType $ mergeSelectionSets fields
completeValue (Out.InterfaceBaseType interfaceType) fields result
diff --git a/src/Language/GraphQL/Execute/Internal.hs b/src/Language/GraphQL/Execute/Internal.hs
new file mode 100644
index 0000000..3b75da1
--- /dev/null
+++ b/src/Language/GraphQL/Execute/Internal.hs
@@ -0,0 +1,25 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
+{-# LANGUAGE DuplicateRecordFields #-}
+{-# LANGUAGE NamedFieldPuns #-}
+
+module Language.GraphQL.Execute.Internal
+ ( addError
+ ) where
+
+import Control.Monad.Trans.State (modify)
+import Control.Monad.Catch (MonadCatch)
+import Data.Sequence ((|>))
+import Language.GraphQL.Error
+import Language.GraphQL.Execute.Coerce
+import Prelude hiding (null)
+
+addError :: (Serialize a, MonadCatch m) => Error -> CollectErrsT m a
+addError error' = modify appender >> pure null
+ where
+ appender :: Resolution m -> Resolution m
+ appender resolution@Resolution{ errors } = resolution
+ { errors = errors |> error'
+ }