summaryrefslogtreecommitdiff
path: root/tests/Test/StarWars
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Test/StarWars')
-rw-r--r--tests/Test/StarWars/Data.hs3
-rw-r--r--tests/Test/StarWars/QueryTests.hs57
-rw-r--r--tests/Test/StarWars/Schema.hs1
3 files changed, 61 insertions, 0 deletions
diff --git a/tests/Test/StarWars/Data.hs b/tests/Test/StarWars/Data.hs
index a898cea..cec90ae 100644
--- a/tests/Test/StarWars/Data.hs
+++ b/tests/Test/StarWars/Data.hs
@@ -56,6 +56,9 @@ appearsIn :: Character -> [Int]
appearsIn (Left x) = _appearsIn . _droidChar $ x
appearsIn (Right x) = _appearsIn . _humanChar $ x
+secretBackstory :: Character -> Text
+secretBackstory = error "secretBackstory is secret."
+
luke :: Character
luke = Right luke'
diff --git a/tests/Test/StarWars/QueryTests.hs b/tests/Test/StarWars/QueryTests.hs
index b98f69c..dee9929 100644
--- a/tests/Test/StarWars/QueryTests.hs
+++ b/tests/Test/StarWars/QueryTests.hs
@@ -265,6 +265,60 @@ test = testGroup "Star Wars Query Tests"
"hero" .= ["__typename" .= ("Human" :: Text), lukeName]
]]
]
+ , testGroup "Errors in resolvers"
+ [ testCase "error on secretBackstory" . testQuery
+ [r| query HeroNameQuery {
+ hero {
+ name
+ secretBackstory
+ }
+ }
+ |]
+ $ object ["data" .= object [
+ "hero" .= [r2d2Name, secretBackstory]
+ ]
+ , "errors" .= object [
+ "message" .= Aeson.toJSON [secretText]
+ , "path" .= Aeson.toJSON [[ "hero" :: Text, "secretBackstory" :: Text ]]
+ ]]
+ , testCase "Error in a list" . testQuery
+ [r| query HeroNameQuery {
+ hero {
+ name
+ friends {
+ name
+ secretBackstory
+ }
+ }
+ }
+ |]
+ $ object ["data" .= object [
+ "hero" .= [r2d2Name, "friends" .= [
+ object [lukeName, secretBackstory]
+ , object [hanName, secretBackstory]
+ , object [leiaName, secretBackstory]
+ ]]
+ ]
+ , "errors" .= object [
+ "message" .= Aeson.toJSON [secretText, secretText, secretText]
+ , "path" .= Aeson.toJSON [secretPath 0, secretPath 1, secretPath 2]
+ ]]
+ , testCase "error on secretBackstory with alias" . testQuery
+ [r| query HeroNameQuery {
+ mainHero: hero {
+ name
+ story: secretBackstory
+ }
+ }
+ |]
+ $ object ["data" .= object [
+ "mainHero" .= [r2d2Name, "story" .= ()]
+ ]
+ , "errors" .= object [
+ "message" .= Aeson.toJSON [secretText]
+ , "path" .= Aeson.toJSON [[ "mainHero" :: Text, "story" :: Text ]]
+ ]]
+ ]
]
where
lukeName = "name" .= ("Luke Skywalker" :: Text)
@@ -274,6 +328,9 @@ test = testGroup "Star Wars Query Tests"
c3poName = "name" .= ("C-3PO" :: Text)
tatooine = "homePlanet" .= ("Tatooine" :: Text)
alderaan = "homePlanet" .= ("Alderaan" :: Text)
+ secretBackstory = "secretBackstory" .= ()
+ secretText = "secretBackstory is secret" :: Text
+ secretPath n = ("hero", "friends", n, "secretBackstory") :: (Text, Text, Int, Text)
testQuery :: Text -> Aeson.Value -> Assertion
testQuery q expected = graphql schema q @?= Just expected
diff --git a/tests/Test/StarWars/Schema.hs b/tests/Test/StarWars/Schema.hs
index 096ccb3..9021bd0 100644
--- a/tests/Test/StarWars/Schema.hs
+++ b/tests/Test/StarWars/Schema.hs
@@ -42,4 +42,5 @@ character char =
, Schema.scalar "name" $ name char
, Schema.array "friends" $ character <$> getFriends char
, Schema.enum "appearsIn" . traverse getEpisode $ appearsIn char
+ , Schema.scalar "secretBackstory" $ secretBackstory char
]