From 4a3b4cb16d7da9c356b514ab48bdc0e527acd377 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 6 Nov 2020 08:33:51 +0100 Subject: Fix singleFieldSubscriptionsRule fragment lookup singleFieldSubscriptionsRule picks up a wrong fragment definition. --- tests/Language/GraphQL/ValidateSpec.hs | 36 ++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Language/GraphQL/ValidateSpec.hs b/tests/Language/GraphQL/ValidateSpec.hs index 3bfa018..318045c 100644 --- a/tests/Language/GraphQL/ValidateSpec.hs +++ b/tests/Language/GraphQL/ValidateSpec.hs @@ -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] -- cgit v1.2.3