summaryrefslogtreecommitdiff
path: root/tests/Language
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-08-25 21:03:42 +0200
committerEugen Wissner <belka@caraus.de>2020-08-25 21:03:42 +0200
commit73555332681a3702db5e277f21a53c628c3a524f (patch)
tree8d558dca6df02dd55eaaae035e8dc608c50f53dd /tests/Language
parent54dbf1df16038c9f583c1b53ab4fac1d71b194fd (diff)
downloadgraphql-73555332681a3702db5e277f21a53c628c3a524f.tar.gz
Validate single root field in subscriptions
Diffstat (limited to 'tests/Language')
-rw-r--r--tests/Language/GraphQL/AST/EncoderSpec.hs4
-rw-r--r--tests/Language/GraphQL/ValidateSpec.hs42
2 files changed, 44 insertions, 2 deletions
diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs
index 71ee948..5fa3706 100644
--- a/tests/Language/GraphQL/AST/EncoderSpec.hs
+++ b/tests/Language/GraphQL/AST/EncoderSpec.hs
@@ -123,7 +123,9 @@ spec = do
it "indents block strings in arguments" $
let arguments = [Argument "message" (String "line1\nline2")]
field = Field Nothing "field" arguments [] []
- operation = DefinitionOperation $ SelectionSet $ pure field
+ operation = DefinitionOperation
+ $ SelectionSet (pure field)
+ $ Location 0 0
in definition pretty operation `shouldBe` [r|{
field(message: """
line1
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