summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/Validate/Rules.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-09-19 18:18:26 +0200
committerEugen Wissner <belka@caraus.de>2020-09-19 18:18:26 +0200
commit21a7d9cce421352e837945a2334e7ccf10160d8c (patch)
tree5fa09a68cd7e5f7ab9aa1db082f74093bcbeb52c /src/Language/GraphQL/Validate/Rules.hs
parent9a08aa5de73e225a9a76017aee4886ce7f6eccec (diff)
downloadgraphql-21a7d9cce421352e837945a2334e7ccf10160d8c.tar.gz
Validate variable names are unique
Diffstat (limited to 'src/Language/GraphQL/Validate/Rules.hs')
-rw-r--r--src/Language/GraphQL/Validate/Rules.hs13
1 files changed, 13 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)