aboutsummaryrefslogtreecommitdiff
path: root/tests/Language/GraphQL/ValidateSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Language/GraphQL/ValidateSpec.hs')
-rw-r--r--tests/Language/GraphQL/ValidateSpec.hs114
1 files changed, 113 insertions, 1 deletions
diff --git a/tests/Language/GraphQL/ValidateSpec.hs b/tests/Language/GraphQL/ValidateSpec.hs
index f84322d..8f6626b 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,115 @@ 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
+
+ it "rejects multiple anonymous operations" $
+ let queryString = [r|
+ {
+ dog {
+ name
+ }
+ }
+
+ query getName {
+ dog {
+ owner {
+ name
+ }
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "This anonymous operation must be the only defined operation."
+ , locations = [AST.Location 2 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected
+
+ it "rejects operations with the same name" $
+ let queryString = [r|
+ query dogOperation {
+ dog {
+ name
+ }
+ }
+
+ mutation dogOperation {
+ mutateDog {
+ id
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "There can be only one operation named \"dogOperation\"."
+ , locations = [AST.Location 2 15, AST.Location 8 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected
+
+ it "rejects fragments with the same name" $
+ let queryString = [r|
+ {
+ dog {
+ ...fragmentOne
+ }
+ }
+
+ fragment fragmentOne on Dog {
+ name
+ }
+
+ fragment fragmentOne on Dog {
+ owner {
+ name
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "There can be only one fragment named \"fragmentOne\"."
+ , locations = [AST.Location 8 15, AST.Location 12 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected