summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/Error.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-09-16 09:12:49 +0200
committerEugen Wissner <belka@caraus.de>2020-09-16 09:12:49 +0200
commit6e644c5b4b3a8284ed0a1f0a84fef775f70a68d6 (patch)
tree56cac7b46b3621c8621e5f8026e275c3b464394d /src/Language/GraphQL/Error.hs
parent4c10ce92041dc73a95aeb64aca241dd937ffaa5c (diff)
downloadgraphql-6e644c5b4b3a8284ed0a1f0a84fef775f70a68d6.tar.gz
Move path to the execution error
Since it isn't possible to get a path during validation, without executing the query.
Diffstat (limited to 'src/Language/GraphQL/Error.hs')
-rw-r--r--src/Language/GraphQL/Error.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Language/GraphQL/Error.hs b/src/Language/GraphQL/Error.hs
index 9df69de..4992169 100644
--- a/src/Language/GraphQL/Error.hs
+++ b/src/Language/GraphQL/Error.hs
@@ -8,6 +8,7 @@ module Language.GraphQL.Error
( parseError
, CollectErrsT
, Error(..)
+ , Path(..)
, Resolution(..)
, ResolverException(..)
, Response(..)
@@ -57,6 +58,7 @@ parseError ParseErrorBundle{..} =
errorObject s SourcePos{..} = Error
{ message = Text.pack $ init $ parseErrorTextPretty s
, locations = [Location (unPos' sourceLine) (unPos' sourceColumn)]
+ , path = []
}
unPos' = fromIntegral . unPos
go (result, state) x =
@@ -75,7 +77,7 @@ addErr v = modify appender
appender resolution@Resolution{..} = resolution{ errors = errors |> v }
makeErrorMessage :: Text -> Error
-makeErrorMessage s = Error s []
+makeErrorMessage s = Error s [] []
-- | Constructs a response object containing only the error with the given
-- message.
@@ -86,10 +88,20 @@ singleError message = Response null $ Seq.singleton $ makeErrorMessage message
addErrMsg :: (Monad m, Serialize a) => Text -> CollectErrsT m a
addErrMsg errorMessage = (addErr . makeErrorMessage) errorMessage >> pure null
+-- | If an error can be associated to a particular field in the GraphQL result,
+-- it must contain an entry with the key path that details the path of the
+-- response field which experienced the error. This allows clients to identify
+-- whether a null result is intentional or caused by a runtime error.
+data Path
+ = Segment Text -- ^ Field name.
+ | Index Int -- ^ List index if a field returned a list.
+ deriving (Eq, Show)
+
-- | @GraphQL@ error.
data Error = Error
{ message :: Text
, locations :: [Location]
+ , path :: [Path]
} deriving (Eq, Show)
-- | The server\'s response describes the result of executing the requested