summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2021-09-17 10:01:14 +0200
committerEugen Wissner <belka@caraus.de>2021-09-17 10:01:14 +0200
commit60d11678398e8215ffc3d9c92d003453f843162b (patch)
tree95920408f1523751bba2b749350867f12a299481
parent7b00e8a0abb91e93e3ea6f86814b4f50219e1bc8 (diff)
downloadgraphql-60d11678398e8215ffc3d9c92d003453f843162b.tar.gz
Test nullability on value completion
-rw-r--r--tests/Language/GraphQL/ExecuteSpec.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs
index e4739d6..e0a9ce4 100644
--- a/tests/Language/GraphQL/ExecuteSpec.hs
+++ b/tests/Language/GraphQL/ExecuteSpec.hs
@@ -106,6 +106,7 @@ philosopherType = Out.ObjectType "Philosopher" Nothing []
, ("interest", ValueResolver interestField interestResolver)
, ("majorWork", ValueResolver majorWorkField majorWorkResolver)
, ("century", ValueResolver centuryField centuryResolver)
+ , ("firstLanguage", ValueResolver firstLanguageField firstLanguageResolver)
]
firstNameField =
Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty
@@ -131,6 +132,9 @@ philosopherType = Out.ObjectType "Philosopher" Nothing []
centuryField =
Out.Field Nothing (Out.NonNullScalarType int) HashMap.empty
centuryResolver = pure $ Float 18.5
+ firstLanguageField
+ = Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty
+ firstLanguageResolver = pure Null
workType :: Out.InterfaceType (Either SomeException)
workType = Out.InterfaceType "Work" Nothing []
@@ -333,6 +337,20 @@ spec =
$ parse document "" "{ count }"
in actual `shouldBe` expected
+ it "detects nullability errors" $
+ let data'' = Aeson.object
+ [ "philosopher" .= Aeson.Null
+ ]
+ executionErrors = pure $ Error
+ { message = "Value completion error. Expected type !String, found: null."
+ , locations = [Location 1 26]
+ , path = [Segment "philosopher", Segment "firstLanguage"]
+ }
+ expected = Response data'' executionErrors
+ Right (Right actual) = either (pure . parseError) execute'
+ $ parse document "" "{ philosopher(id: \"1\") { firstLanguage } }"
+ in actual `shouldBe` expected
+
context "Subscription" $
it "subscribes" $
let data'' = Aeson.object