diff options
| author | Eugen Wissner <belka@caraus.de> | 2021-06-24 09:29:24 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2021-06-24 09:29:24 +0200 |
| commit | 96bb061666aad7778d5f03c3f999aa79133d099b (patch) | |
| tree | 5ee1d14ed269a05cfefc80c46618a87c6480ad70 /tests/Language | |
| parent | 812f6967d40cfd1d1c0af5512496ff7b7cb0f6ae (diff) | |
| download | graphql-96bb061666aad7778d5f03c3f999aa79133d099b.tar.gz | |
Fail with a location for result coercion
The intermediate representation was further modified so that the
operation definitions contain location information. Probably I should
introduce a data type that generalizes fields and operations, so it
contains object type, location and the selection set, so the functions
don't accept so many arguments.
Diffstat (limited to 'tests/Language')
| -rw-r--r-- | tests/Language/GraphQL/ExecuteSpec.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs index 5e86848..1f8770b 100644 --- a/tests/Language/GraphQL/ExecuteSpec.hs +++ b/tests/Language/GraphQL/ExecuteSpec.hs @@ -82,6 +82,7 @@ philosopherType = Out.ObjectType "Philosopher" Nothing [] , ("school", ValueResolver schoolField schoolResolver) , ("interest", ValueResolver interestField interestResolver) , ("majorWork", ValueResolver majorWorkField majorWorkResolver) + , ("century", ValueResolver centuryField centuryResolver) ] firstNameField = Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty @@ -104,6 +105,9 @@ philosopherType = Out.ObjectType "Philosopher" Nothing [] $ HashMap.fromList [ ("title", "Also sprach Zarathustra: Ein Buch für Alle und Keinen") ] + centuryField = + Out.Field Nothing (Out.NonNullScalarType int) HashMap.empty + centuryResolver = pure $ Float 18.5 workType :: Out.InterfaceType (Either SomeException) workType = Out.InterfaceType "Work" Nothing [] @@ -268,6 +272,22 @@ spec = $ parse document "" "{ philosopher(id: true) { lastName } }" in actual `shouldBe` expected + it "gives location information for failed result coercion" $ + let data'' = Aeson.object + [ "philosopher" .= Aeson.object + [ "century" .= Aeson.Null + ] + ] + executionErrors = pure $ Error + { message = "Result coercion failed." + , locations = [Location 1 26] + , path = [] + } + expected = Response data'' executionErrors + Right (Right actual) = either (pure . parseError) execute' + $ parse document "" "{ philosopher(id: \"1\") { century } }" + in actual `shouldBe` expected + context "Subscription" $ it "subscribes" $ let data'' = Aeson.object |
