From 59aa010f0bd0e12e60fb9c9de95c92d3bf10c36d Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Fri, 15 Dec 2023 05:17:04 +0100 Subject: [PATCH] Fix "variable is not used" error --- src/Language/GraphQL/Validate/Rules.hs | 23 +++++++++++++++++++---- 1 file 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'