diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-09-21 07:28:40 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-09-21 07:28:40 +0200 |
| commit | 3e393004ae03a717218a805043d9237ca29ac947 (patch) | |
| tree | dcff103322dc100eb83ba17f59f504b28b69a191 /tests | |
| parent | 38c3097bcf2d3c92a180c5d328cfb15ef80f0b95 (diff) | |
| download | graphql-3e393004ae03a717218a805043d9237ca29ac947.tar.gz | |
Validate all variables are defined
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Language/GraphQL/AST/EncoderSpec.hs | 3 | ||||
| -rw-r--r-- | tests/Language/GraphQL/ValidateSpec.hs | 21 |
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs index b21e68f..d189679 100644 --- a/tests/Language/GraphQL/AST/EncoderSpec.hs +++ b/tests/Language/GraphQL/AST/EncoderSpec.hs @@ -122,7 +122,8 @@ spec = do describe "definition" $ it "indents block strings in arguments" $ let location = Location 0 0 - arguments = [Argument "message" (String "line1\nline2") location] + argumentValue = Node (String "line1\nline2") location + arguments = [Argument "message" argumentValue location] field = Field Nothing "field" arguments [] [] location operation = DefinitionOperation $ SelectionSet (pure $ FieldSelection field) location 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 |
