From b1c5a568dd8b6c63d05f08c097f26afd7277f0dd Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 21 Dec 2023 21:34:37 +0100 Subject: [PATCH] Add a failing test for unused variables bug --- src/Language/GraphQL/Validate/Rules.hs | 4 ++++ tests/Language/GraphQL/Validate/RulesSpec.hs | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Language/GraphQL/Validate/Rules.hs b/src/Language/GraphQL/Validate/Rules.hs index 8c3156b..4d5a91d 100644 --- a/src/Language/GraphQL/Validate/Rules.hs +++ b/src/Language/GraphQL/Validate/Rules.hs @@ -618,6 +618,10 @@ noUndefinedVariablesRule = , "\"." ] +-- Used to find the difference between defined and used variables. The first +-- argument are variables defined in the operation, the second argument are +-- variables used in the query. It should return the difference between these +-- 2 sets. type UsageDifference = HashMap Full.Name [Full.Location] -> HashMap Full.Name [Full.Location] diff --git a/tests/Language/GraphQL/Validate/RulesSpec.hs b/tests/Language/GraphQL/Validate/RulesSpec.hs index 2b77e44..b0ed59e 100644 --- a/tests/Language/GraphQL/Validate/RulesSpec.hs +++ b/tests/Language/GraphQL/Validate/RulesSpec.hs @@ -18,7 +18,7 @@ import Language.GraphQL.Type import qualified Language.GraphQL.Type.In as In import qualified Language.GraphQL.Type.Out as Out import Language.GraphQL.Validate -import Test.Hspec (Spec, context, describe, it, shouldBe, shouldContain) +import Test.Hspec (Spec, context, describe, it, shouldBe, shouldContain, xit) import Text.Megaparsec (parse, errorBundlePretty) petSchema :: Schema IO @@ -560,7 +560,7 @@ spec = } in validate queryString `shouldBe` [expected] - context "noUnusedVariablesRule" $ + context "noUnusedVariablesRule" $ do it "rejects unused variables" $ let queryString = [gql| query variableUnused($atOtherHomes: Boolean) { @@ -577,6 +577,16 @@ spec = } in validate queryString `shouldBe` [expected] + xit "detects variables in properties of input objects" $ + let queryString = [gql| + query withVar ($name: String!) { + findDog (complex: { name: $name }) { + name + } + } + |] + in validate queryString `shouldBe` [] + context "uniqueInputFieldNamesRule" $ it "rejects duplicate fields in input objects" $ let queryString = [gql|