From 3e393004ae03a717218a805043d9237ca29ac947 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 21 Sep 2020 07:28:40 +0200 Subject: Validate all variables are defined --- tests/Language/GraphQL/ValidateSpec.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/Language/GraphQL/ValidateSpec.hs') diff --git a/tests/Language/GraphQL/ValidateSpec.hs b/tests/Language/GraphQL/ValidateSpec.hs index 340104d..dc19d95 100644 --- a/tests/Language/GraphQL/ValidateSpec.hs +++ b/tests/Language/GraphQL/ValidateSpec.hs @@ -471,3 +471,24 @@ spec = , locations = [AST.Location 2 34] } in validate queryString `shouldBe` Seq.singleton expected + + it "rejects undefined variables" $ + let queryString = [r| + query variableIsNotDefinedUsedInSingleFragment { + dog { + ...isHousetrainedFragment + } + } + + fragment isHousetrainedFragment on Dog { + isHousetrained(atOtherHomes: $atOtherHomes) + } + |] + expected = Error + { message = + "Variable \"$atOtherHomes\" is not defined by \ + \operation \ + \\"variableIsNotDefinedUsedInSingleFragment\"." + , locations = [AST.Location 9 46] + } + in validate queryString `shouldBe` Seq.singleton expected -- cgit v1.2.3