diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-08-25 21:03:42 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-08-25 21:03:42 +0200 |
| commit | 73555332681a3702db5e277f21a53c628c3a524f (patch) | |
| tree | 8d558dca6df02dd55eaaae035e8dc608c50f53dd /src/Language/GraphQL/Validate/Validation.hs | |
| parent | 54dbf1df16038c9f583c1b53ab4fac1d71b194fd (diff) | |
| download | graphql-73555332681a3702db5e277f21a53c628c3a524f.tar.gz | |
Validate single root field in subscriptions
Diffstat (limited to 'src/Language/GraphQL/Validate/Validation.hs')
| -rw-r--r-- | src/Language/GraphQL/Validate/Validation.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Language/GraphQL/Validate/Validation.hs b/src/Language/GraphQL/Validate/Validation.hs new file mode 100644 index 0000000..f6edc7a --- /dev/null +++ b/src/Language/GraphQL/Validate/Validation.hs @@ -0,0 +1,34 @@ +{- This Source Code Form is subject to the terms of the Mozilla Public License, + v. 2.0. If a copy of the MPL was not distributed with this file, You can + obtain one at https://mozilla.org/MPL/2.0/. -} + +-- | Definitions used by the validation rules and the validator itself. +module Language.GraphQL.Validate.Validation + ( Validation(..) + , Rule(..) + , RuleT + ) where + +import Control.Monad.Trans.Reader (ReaderT(..)) +import Data.HashMap.Strict (HashMap) +import Language.GraphQL.AST.Document +import Language.GraphQL.Type.Schema (Schema) +import qualified Language.GraphQL.Type.Schema as Schema + +-- | 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 +-- validation fails, the function should return an error message, or 'Nothing' +-- otherwise. +data Rule m + = DefinitionRule (Definition -> RuleT m) + | OperationDefinitionRule (OperationDefinition -> RuleT m) + +-- | Monad transformer used by the rules. +type RuleT m = ReaderT (Validation m) Maybe String |
