summaryrefslogtreecommitdiff
path: root/Data/GraphQL/Error.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/GraphQL/Error.hs')
-rw-r--r--Data/GraphQL/Error.hs21
1 files changed, 11 insertions, 10 deletions
diff --git a/Data/GraphQL/Error.hs b/Data/GraphQL/Error.hs
index 25632b4..74f08e4 100644
--- a/Data/GraphQL/Error.hs
+++ b/Data/GraphQL/Error.hs
@@ -26,17 +26,17 @@ parseError :: Applicative f => String -> f Aeson.Value
parseError s =
pure $ Aeson.object [("errors", Aeson.toJSON [makeErrorMsg $ pack s])]
--- | A wrapper for an applicative functor, for passing around error messages.
+-- | A wrapper for an 'Applicative' to pass error messages around.
type CollectErrsT f a = f (a,[Aeson.Value])
--- | Takes a (wrapped) list (foldable functor) of values and errors and
+-- | Takes a (wrapped) list (foldable functor) of values and errors,
-- joins the values into a list and concatenates the errors.
joinErrs
:: (Functor m, Functor f, Foldable f)
=> m (f (a,[Aeson.Value])) -> CollectErrsT m (f a)
joinErrs = fmap $ fmap fst &&& concatMap snd
--- | Wraps the given applicative to handle errors
+-- | Wraps the given 'Applicative' to handle errors
errWrap :: Functor f => f a -> f (a, [Aeson.Value])
errWrap = fmap (flip (,) [])
@@ -51,12 +51,13 @@ makeErrorMsg s = Aeson.object [("message",Aeson.toJSON s)]
addErrMsg :: Functor f => Text -> CollectErrsT f a -> CollectErrsT f a
addErrMsg = addErr . makeErrorMsg
--- | Runs the given query computation, but collects the errors into an error
--- list, which is then sent back with the data.
+-- | Runs the given query, but collects the errors into an error
+-- list which is then sent back with the data.
runCollectErrs :: Functor f => CollectErrsT f Aeson.Value -> f Aeson.Value
runCollectErrs = fmap finalD
- where finalD (dat,errs) =
- Aeson.object $
- if null errs
- then [("data",dat)]
- else [("data",dat),("errors",Aeson.toJSON $ reverse errs)]
+ where
+ finalD (dat,errs) =
+ Aeson.object
+ $ if null errs
+ then [("data",dat)]
+ else [("data",dat),("errors",Aeson.toJSON $ reverse errs)]