From ced9b815db516ac4196856c535eedca85f4a1935 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 26 Sep 2020 09:06:30 +0200 Subject: Validate leaf selections --- tests/Language/GraphQL/ValidateSpec.hs | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Language/GraphQL/ValidateSpec.hs b/tests/Language/GraphQL/ValidateSpec.hs index 9127a94..1649ad1 100644 --- a/tests/Language/GraphQL/ValidateSpec.hs +++ b/tests/Language/GraphQL/ValidateSpec.hs @@ -500,7 +500,9 @@ spec = it "rejects duplicate fields in input objects" $ let queryString = [r| { - findDog(complex: { name: "Fido", name: "Jack" }) + findDog(complex: { name: "Fido", name: "Jack" }) { + name + } } |] expected = Error @@ -509,3 +511,36 @@ spec = , locations = [AST.Location 3 36, AST.Location 3 50] } in validate queryString `shouldBe` [expected] + + it "rejects undefined fields" $ + let queryString = [r| + { + dog { + meowVolume + } + } + |] + expected = Error + { message = + "Cannot query field \"meowVolume\" on type \"Dog\"." + , locations = [AST.Location 4 19] + } + in validate queryString `shouldBe` [expected] + + it "rejects scalar fields with not empty selection set" $ + let queryString = [r| + { + dog { + barkVolume { + sinceWhen + } + } + } + |] + expected = Error + { message = + "Field \"barkVolume\" must not have a selection since \ + \type \"Int\" has no subfields." + , locations = [AST.Location 4 19] + } + in validate queryString `shouldBe` [expected] -- cgit v1.2.3