Fix singleFieldSubscriptionsRule fragment lookup

singleFieldSubscriptionsRule picks up a wrong fragment definition.
This commit is contained in:
2020-11-06 08:33:51 +01:00
parent 7f0fb18716
commit 4a3b4cb16d
2 changed files with 52 additions and 17 deletions

View File

@ -92,6 +92,7 @@ petType = InterfaceType "Pet" Nothing []
subscriptionType :: ObjectType IO
subscriptionType = ObjectType "Subscription" Nothing [] $ HashMap.fromList
[ ("newMessage", newMessageResolver)
, ("disallowedSecondRootField", newMessageResolver)
]
where
newMessageField = Field Nothing (Out.NonNullObjectType messageType) mempty
@ -165,7 +166,8 @@ spec =
|]
expected = Error
{ message =
"Subscription sub must select only one top level field."
"Subscription \"sub\" must select only one top level \
\field."
, locations = [AST.Location 2 15]
}
in validate queryString `shouldContain` [expected]
@ -186,7 +188,8 @@ spec =
|]
expected = Error
{ message =
"Subscription sub must select only one top level field."
"Subscription \"sub\" must select only one top level \
\field."
, locations = [AST.Location 2 15]
}
in validate queryString `shouldContain` [expected]
@ -631,3 +634,32 @@ spec =
, locations = [AST.Location 3 34]
}
in validate queryString `shouldBe` [expected]
it "finds corresponding subscription fragment" $
let queryString = [r|
subscription sub {
...anotherSubscription
...multipleSubscriptions
}
fragment multipleSubscriptions on Subscription {
newMessage {
body
}
disallowedSecondRootField {
sender
}
}
fragment anotherSubscription on Subscription {
newMessage {
body
sender
}
}
|]
expected = Error
{ message =
"Subscription \"sub\" must select only one top level \
\field."
, locations = [AST.Location 2 15]
}
in validate queryString `shouldBe` [expected]