From 73555332681a3702db5e277f21a53c628c3a524f Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 25 Aug 2020 21:03:42 +0200 Subject: Validate single root field in subscriptions --- tests/Language/GraphQL/ValidateSpec.hs | 42 +++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'tests/Language/GraphQL/ValidateSpec.hs') diff --git a/tests/Language/GraphQL/ValidateSpec.hs b/tests/Language/GraphQL/ValidateSpec.hs index f84322d..c463dd9 100644 --- a/tests/Language/GraphQL/ValidateSpec.hs +++ b/tests/Language/GraphQL/ValidateSpec.hs @@ -148,7 +148,7 @@ validate queryString = spec :: Spec spec = - describe "document" $ + describe "document" $ do it "rejects type definitions" $ let queryString = [r| query getDogName { @@ -169,3 +169,43 @@ spec = , path = [] } in validate queryString `shouldBe` Seq.singleton expected + + it "rejects multiple subscription root fields" $ + let queryString = [r| + subscription sub { + newMessage { + body + sender + } + disallowedSecondRootField + } + |] + expected = Error + { message = + "Subscription sub must select only one top level field." + , locations = [AST.Location 2 15] + , path = [] + } + in validate queryString `shouldBe` Seq.singleton expected + + it "rejects multiple subscription root fields coming from a fragment" $ + let queryString = [r| + subscription sub { + ...multipleSubscriptions + } + + fragment multipleSubscriptions on Subscription { + newMessage { + body + sender + } + disallowedSecondRootField + } + |] + expected = Error + { message = + "Subscription sub must select only one top level field." + , locations = [AST.Location 2 15] + , path = [] + } + in validate queryString `shouldBe` Seq.singleton expected -- cgit v1.2.3