From eebad8a27f164088e356e7936afb9a399c70363a Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 27 Aug 2020 09:04:31 +0200 Subject: Validate operation name uniqueness Fixes #52. --- src/Language/GraphQL/Validate/Validation.hs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/Language/GraphQL/Validate/Validation.hs') diff --git a/src/Language/GraphQL/Validate/Validation.hs b/src/Language/GraphQL/Validate/Validation.hs index f6edc7a..2b5365a 100644 --- a/src/Language/GraphQL/Validate/Validation.hs +++ b/src/Language/GraphQL/Validate/Validation.hs @@ -4,17 +4,36 @@ -- | Definitions used by the validation rules and the validator itself. module Language.GraphQL.Validate.Validation - ( Validation(..) + ( Error(..) + , Path(..) , Rule(..) , RuleT + , Validation(..) ) where import Control.Monad.Trans.Reader (ReaderT(..)) import Data.HashMap.Strict (HashMap) +import Data.Text (Text) import Language.GraphQL.AST.Document import Language.GraphQL.Type.Schema (Schema) import qualified Language.GraphQL.Type.Schema as Schema +-- | 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) + +-- | Validation error. +data Error = Error + { message :: String + , locations :: [Location] + , path :: [Path] + } deriving (Eq, Show) + -- | Validation rule context. data Validation m = Validation { ast :: Document @@ -31,4 +50,4 @@ data Rule m | OperationDefinitionRule (OperationDefinition -> RuleT m) -- | Monad transformer used by the rules. -type RuleT m = ReaderT (Validation m) Maybe String +type RuleT m = ReaderT (Validation m) Maybe Error -- cgit v1.2.3