Validate single root field in subscriptions
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user