summaryrefslogtreecommitdiff
path: root/tests/Language/GraphQL/ExecuteSpec.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2021-05-09 12:34:39 +0200
committerEugen Wissner <belka@caraus.de>2021-05-09 12:42:02 +0200
commit0d23df3da29cfe0b78af922cea71db5fa1d5c98c (patch)
tree9dd71e8bbf92d3c0e71144b552d195f8baa8afe7 /tests/Language/GraphQL/ExecuteSpec.hs
parent5a5f265fe4bf291c1ef58f5fe452f1e8c69c9ed6 (diff)
downloadgraphql-0d23df3da29cfe0b78af922cea71db5fa1d5c98c.tar.gz
Provide an internal function to add errors
The old function, addErrMsg, takes only a string with an error description, but more information is required for the execution errors: locations and path. addErrMsg should be deprecated after the switching to the new addError.
Diffstat (limited to 'tests/Language/GraphQL/ExecuteSpec.hs')
-rw-r--r--tests/Language/GraphQL/ExecuteSpec.hs30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs
index f6e3e6f..3288371 100644
--- a/tests/Language/GraphQL/ExecuteSpec.hs
+++ b/tests/Language/GraphQL/ExecuteSpec.hs
@@ -30,7 +30,7 @@ philosopherSchema = schema queryType Nothing (Just subscriptionType) mempty
queryType :: Out.ObjectType (Either SomeException)
queryType = Out.ObjectType "Query" Nothing []
- $ HashMap.singleton "philosopher"
+ $ HashMap.singleton "philosopher"
$ ValueResolver philosopherField
$ pure $ Type.Object mempty
where
@@ -44,6 +44,7 @@ philosopherType = Out.ObjectType "Philosopher" Nothing []
resolvers =
[ ("firstName", ValueResolver firstNameField firstNameResolver)
, ("lastName", ValueResolver lastNameField lastNameResolver)
+ , ("school", ValueResolver schoolField schoolResolver)
]
firstNameField =
Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty
@@ -51,6 +52,9 @@ philosopherType = Out.ObjectType "Philosopher" Nothing []
lastNameField
= Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty
lastNameResolver = pure $ Type.String "Nietzsche"
+ schoolField
+ = Out.Field Nothing (Out.NonNullEnumType schoolType) HashMap.empty
+ schoolResolver = pure $ Type.Enum "EXISTENTIALISM"
subscriptionType :: Out.ObjectType (Either SomeException)
subscriptionType = Out.ObjectType "Subscription" Nothing []
@@ -70,6 +74,13 @@ quoteType = Out.ObjectType "Quote" Nothing []
quoteField =
Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty
+schoolType :: EnumType
+schoolType = EnumType "School" Nothing $ HashMap.fromList
+ [ ("NOMINALISM", EnumValue Nothing)
+ , ("REALISM", EnumValue Nothing)
+ , ("IDEALISM", EnumValue Nothing)
+ ]
+
type EitherStreamOrValue = Either
(ResponseEventStream (Either SomeException) Aeson.Value)
(Response Aeson.Value)
@@ -118,6 +129,23 @@ spec =
Right (Right actual) = either (pure . parseError) execute'
$ parse document "" "{ philosopher { firstName } philosopher { lastName } }"
in actual `shouldBe` expected
+
+ it "errors on invalid output enum values" $
+ let data'' = Aeson.object
+ [ "philosopher" .= Aeson.object
+ [ "school" .= Aeson.Null
+ ]
+ ]
+ executionErrors = pure $ Error
+ { message = "Enum value completion failed."
+ , locations = []
+ , path = []
+ }
+ expected = Response data'' executionErrors
+ Right (Right actual) = either (pure . parseError) execute'
+ $ parse document "" "{ philosopher { school } }"
+ in actual `shouldBe` expected
+
context "Subscription" $
it "subscribes" $
let data'' = Aeson.object