diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-09-16 09:12:49 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-09-16 09:12:49 +0200 |
| commit | 6e644c5b4b3a8284ed0a1f0a84fef775f70a68d6 (patch) | |
| tree | 56cac7b46b3621c8621e5f8026e275c3b464394d /src/Language/GraphQL.hs | |
| parent | 4c10ce92041dc73a95aeb64aca241dd937ffaa5c (diff) | |
| download | graphql-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.hs')
| -rw-r--r-- | src/Language/GraphQL.hs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/Language/GraphQL.hs b/src/Language/GraphQL.hs index 9fce1d3..1f2d7ba 100644 --- a/src/Language/GraphQL.hs +++ b/src/Language/GraphQL.hs @@ -11,6 +11,7 @@ import Control.Monad.Catch (MonadCatch) import qualified Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson import qualified Data.HashMap.Strict as HashMap +import Data.Maybe (catMaybes) import qualified Data.Sequence as Seq import Data.Text (Text) import Language.GraphQL.AST @@ -55,24 +56,19 @@ graphqlSubs schema operationName variableValues document' = [ ("data", data'') , ("errors", Aeson.toJSON $ fromError <$> errors') ] - fromError Error{ locations = [], ..} = - Aeson.object [("message", Aeson.toJSON message)] - fromError Error{..} = Aeson.object + fromError Error{..} = Aeson.object $ catMaybes + [ Just ("message", Aeson.toJSON message) + , toMaybe fromLocation "locations" locations + , toMaybe fromPath "path" path + ] + fromValidationError Validate.Error{..} = Aeson.object [ ("message", Aeson.toJSON message) , ("locations", Aeson.listValue fromLocation locations) ] - fromValidationError Validate.Error{..} - | [] <- path = Aeson.object - [ ("message", Aeson.toJSON message) - , ("locations", Aeson.listValue fromLocation locations) - ] - | otherwise = Aeson.object - [ ("message", Aeson.toJSON message) - , ("locations", Aeson.listValue fromLocation locations) - , ("path", Aeson.listValue fromPath path) - ] - fromPath (Validate.Segment segment) = Aeson.String segment - fromPath (Validate.Index index) = Aeson.toJSON index + toMaybe _ _ [] = Nothing + toMaybe f key xs = Just (key, Aeson.listValue f xs) + fromPath (Segment segment) = Aeson.String segment + fromPath (Index index) = Aeson.toJSON index fromLocation Location{..} = Aeson.object [ ("line", Aeson.toJSON line) , ("column", Aeson.toJSON column) |
