summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/Validate
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/GraphQL/Validate')
-rw-r--r--src/Language/GraphQL/Validate/Rules.hs13
-rw-r--r--src/Language/GraphQL/Validate/Validation.hs1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/Language/GraphQL/Validate/Rules.hs b/src/Language/GraphQL/Validate/Rules.hs
index f9498b9..3af6145 100644
--- a/src/Language/GraphQL/Validate/Rules.hs
+++ b/src/Language/GraphQL/Validate/Rules.hs
@@ -22,6 +22,7 @@ module Language.GraphQL.Validate.Rules
, uniqueDirectiveNamesRule
, uniqueFragmentNamesRule
, uniqueOperationNamesRule
+ , uniqueVariableNamesRule
) where
import Control.Monad (foldM)
@@ -64,6 +65,8 @@ specifiedRules =
, noFragmentCyclesRule
-- Directives.
, uniqueDirectiveNamesRule
+ -- Variables.
+ , uniqueVariableNamesRule
]
-- | Definition must be OperationDefinition or FragmentDefinition.
@@ -492,3 +495,13 @@ filterDuplicates extract nodeType = lift
, Text.unpack $ fst $ extract directive
, "\"."
]
+
+-- | If any operation defines more than one variable with the same name, it is
+-- ambiguous and invalid. It is invalid even if the type of the duplicate
+-- variable is the same.
+uniqueVariableNamesRule :: forall m. Rule m
+uniqueVariableNamesRule = VariablesRule
+ $ filterDuplicates extract "variable"
+ where
+ extract (VariableDefinition variableName _ _ location) =
+ (variableName, location)
diff --git a/src/Language/GraphQL/Validate/Validation.hs b/src/Language/GraphQL/Validate/Validation.hs
index f2bccd3..385c4ae 100644
--- a/src/Language/GraphQL/Validate/Validation.hs
+++ b/src/Language/GraphQL/Validate/Validation.hs
@@ -43,6 +43,7 @@ data Rule m
| FieldRule (Field -> RuleT m)
| ArgumentsRule (Field -> RuleT m) (Directive -> RuleT m)
| DirectivesRule ([Directive] -> RuleT m)
+ | VariablesRule ([VariableDefinition] -> RuleT m)
-- | Monad transformer used by the rules.
type RuleT m = ReaderT (Validation m) Seq Error