summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/Validate
diff options
context:
space:
mode:
authorMatei Adriel <rafaeladriel11@gmail.com>2023-12-15 05:17:04 +0100
committerEugen Wissner <belka@caraus.de>2023-12-27 12:50:17 +0100
commit59aa010f0bd0e12e60fb9c9de95c92d3bf10c36d (patch)
tree24175cb5aba8056d102873d9f2912f6003df7991 /src/Language/GraphQL/Validate
parentb1c5a568dd8b6c63d05f08c097f26afd7277f0dd (diff)
downloadgraphql-59aa010f0bd0e12e60fb9c9de95c92d3bf10c36d.tar.gz
Fix "variable is not used" error
Diffstat (limited to 'src/Language/GraphQL/Validate')
-rw-r--r--src/Language/GraphQL/Validate/Rules.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/Language/GraphQL/Validate/Rules.hs b/src/Language/GraphQL/Validate/Rules.hs
index 4d5a91d..2be8bec 100644
--- a/src/Language/GraphQL/Validate/Rules.hs
+++ b/src/Language/GraphQL/Validate/Rules.hs
@@ -668,11 +668,26 @@ variableUsageDifference difference errorMessage = OperationDefinitionRule $ \cas
= filterSelections' selections
>>= lift . mapReaderT (<> mapDirectives directives') . pure
findDirectiveVariables (Full.Directive _ arguments _) = mapArguments arguments
- mapArguments = Seq.fromList . mapMaybe findArgumentVariables
+
+ mapArguments = Seq.fromList . (>>= findArgumentVariables)
mapDirectives = foldMap findDirectiveVariables
- findArgumentVariables (Full.Argument _ Full.Node{ node = Full.Variable value', ..} _) =
- Just (value', [location])
- findArgumentVariables _ = Nothing
+
+ findArgumentVariables (Full.Argument _ Full.Node{node = value, ..} _) =
+ findValueVariables location value
+
+ findValueVariables location (Full.Variable value') = [(value', [location])]
+ findValueVariables location (Full.List values) =
+ values
+ >>= (\(Full.Node{node = value}) -> findValueVariables location value)
+ findValueVariables _ (Full.Object fields) =
+ fields
+ >>= ( \( Full.ObjectField
+ { location = location
+ , value = Full.Node{node = value}
+ }
+ ) -> findValueVariables location value
+ )
+ findValueVariables _ _ = []
makeError operationName (variableName, locations') = Error
{ message = errorMessage operationName variableName
, locations = locations'