diff options
Diffstat (limited to 'src/Language/GraphQL/Validate/Rules.hs')
| -rw-r--r-- | src/Language/GraphQL/Validate/Rules.hs | 13 |
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) |
