aboutsummaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/Validate/Validation.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/GraphQL/Validate/Validation.hs')
-rw-r--r--src/Language/GraphQL/Validate/Validation.hs32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/Language/GraphQL/Validate/Validation.hs b/src/Language/GraphQL/Validate/Validation.hs
index 03bbf33..0432a1a 100644
--- a/src/Language/GraphQL/Validate/Validation.hs
+++ b/src/Language/GraphQL/Validate/Validation.hs
@@ -5,41 +5,29 @@
-- | Definitions used by the validation rules and the validator itself.
module Language.GraphQL.Validate.Validation
( Error(..)
- , Path(..)
, Rule(..)
, RuleT
, Validation(..)
) where
-import Control.Monad.Trans.Reader (ReaderT(..))
-import Data.HashMap.Strict (HashMap)
-import Data.Text (Text)
+import Control.Monad.Trans.Reader (ReaderT)
+import Data.Sequence (Seq)
+import Language.GraphQL.AST.DirectiveLocation (DirectiveLocation(..))
import Language.GraphQL.AST.Document
+import qualified Language.GraphQL.Type.In as In
+import qualified Language.GraphQL.Type.Out as Out
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
, schema :: Schema m
- , types :: HashMap Name (Schema.Type m)
- , rules :: [Rule m]
}
-- | 'Rule' assigns a function to each AST node that can be validated. If the
@@ -49,6 +37,14 @@ data Rule m
= DefinitionRule (Definition -> RuleT m)
| OperationDefinitionRule (OperationDefinition -> RuleT m)
| FragmentDefinitionRule (FragmentDefinition -> RuleT m)
+ | SelectionRule (Maybe (Out.Type m) -> Selection -> RuleT m)
+ | FragmentRule (FragmentDefinition -> RuleT m) (InlineFragment -> RuleT m)
+ | FragmentSpreadRule (FragmentSpread -> RuleT m)
+ | FieldRule (Maybe (Out.Type m) -> Field -> RuleT m)
+ | ArgumentsRule (Maybe (Out.Type m) -> Field -> RuleT m) (Directive -> RuleT m)
+ | DirectivesRule (DirectiveLocation -> [Directive] -> RuleT m)
+ | VariablesRule ([VariableDefinition] -> RuleT m)
+ | ValueRule (Maybe In.Type -> Node Value -> RuleT m) (Maybe In.Type -> Node ConstValue -> RuleT m)
-- | Monad transformer used by the rules.
-type RuleT m = ReaderT (Validation m) Maybe Error
+type RuleT m = ReaderT (Validation m) Seq Error