32 lines
1.1 KiB
Haskell
Raw Normal View History

2020-07-20 21:29:12 +02:00
{- 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/. -}
2020-07-24 21:34:31 +02:00
-- | This module contains default rules defined in the GraphQL specification.
2020-07-20 21:29:12 +02:00
module Language.GraphQL.Validate.Rules
( Rule(..)
, executableDefinitionsRule
, specifiedRules
) where
import Language.GraphQL.AST.Document
2020-07-24 21:34:31 +02:00
-- | '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.
2020-07-20 21:29:12 +02:00
newtype Rule
= DefinitionRule (Definition -> Maybe String)
2020-07-24 21:34:31 +02:00
-- | Default reules given in the specification.
2020-07-20 21:29:12 +02:00
specifiedRules :: [Rule]
specifiedRules =
[ executableDefinitionsRule
]
2020-07-24 21:34:31 +02:00
-- | Definition must be OperationDefinition or FragmentDefinition.
2020-07-20 21:29:12 +02:00
executableDefinitionsRule :: Rule
executableDefinitionsRule = DefinitionRule go
where
go (ExecutableDefinition _definition _) = Nothing
go _ = Just "Definition must be OperationDefinition or FragmentDefinition."