aboutsummaryrefslogtreecommitdiff
path: root/tests/Language/GraphQL/ExecuteSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Language/GraphQL/ExecuteSpec.hs')
-rw-r--r--tests/Language/GraphQL/ExecuteSpec.hs55
1 files changed, 37 insertions, 18 deletions
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs
index 65033ae..52bd410 100644
--- a/tests/Language/GraphQL/ExecuteSpec.hs
+++ b/tests/Language/GraphQL/ExecuteSpec.hs
@@ -69,6 +69,7 @@ queryType = Out.ObjectType "Query" Nothing []
, ("throwing", ValueResolver throwingField throwingResolver)
, ("count", ValueResolver countField countResolver)
, ("sequence", ValueResolver sequenceField sequenceResolver)
+ , ("withInputObject", ValueResolver withInputObjectField withInputObjectResolver)
]
where
philosopherField =
@@ -89,6 +90,17 @@ queryType = Out.ObjectType "Query" Nothing []
let fieldType = Out.ListType $ Out.NonNullScalarType int
in Out.Field Nothing fieldType HashMap.empty
sequenceResolver = pure intSequence
+ withInputObjectResolver = pure $ Type.Int 0
+ withInputObjectField =
+ Out.Field Nothing (Out.NonNullScalarType int) $ HashMap.fromList
+ [("values", In.Argument Nothing withInputObjectArgumentType Nothing)]
+ withInputObjectArgumentType = In.NonNullListType
+ $ In.NonNullInputObjectType inputObjectType
+
+inputObjectType :: In.InputObjectType
+inputObjectType = In.InputObjectType "InputObject" Nothing $
+ HashMap.singleton "name" $
+ In.InputField Nothing (In.NonNullScalarType int) Nothing
intSequence :: Value
intSequence = Type.List [Type.Int 1, Type.Int 2, Type.Int 3]
@@ -295,7 +307,7 @@ spec =
let data'' = Object $ HashMap.singleton "philosopher" Null
executionErrors = pure $ Error
{ message =
- "Value completion error. Expected type !School, found: EXISTENTIALISM."
+ "Value completion error. Expected type School!, found: EXISTENTIALISM."
, locations = [Location 1 17]
, path = [Segment "philosopher", Segment "school"]
}
@@ -307,7 +319,7 @@ spec =
let data'' = Object $ HashMap.singleton "philosopher" Null
executionErrors = pure $ Error
{ message =
- "Value completion error. Expected type !Interest, found: { instrument: \"piano\" }."
+ "Value completion error. Expected type Interest!, found: { instrument: \"piano\" }."
, locations = [Location 1 17]
, path = [Segment "philosopher", Segment "interest"]
}
@@ -319,7 +331,7 @@ spec =
let data'' = Object $ HashMap.singleton "philosopher" Null
executionErrors = pure $ Error
{ message
- = "Value completion error. Expected type !Work, found:\
+ = "Value completion error. Expected type Work!, found:\
\ { title: \"Also sprach Zarathustra: Ein Buch f\252r Alle und Keinen\" }."
, locations = [Location 1 17]
, path = [Segment "philosopher", Segment "majorWork"]
@@ -328,22 +340,10 @@ spec =
sourceQuery = "{ philosopher { majorWork { title } } }"
in sourceQuery `shouldResolveTo` expected
- it "gives location information for invalid scalar arguments" $
- let data'' = Object $ HashMap.singleton "philosopher" Null
- executionErrors = pure $ Error
- { message =
- "Argument \"id\" has invalid type. Expected type ID, found: True."
- , locations = [Location 1 15]
- , path = [Segment "philosopher"]
- }
- expected = Response data'' executionErrors
- sourceQuery = "{ philosopher(id: true) { lastName } }"
- in sourceQuery `shouldResolveTo` expected
-
it "gives location information for failed result coercion" $
let data'' = Object $ HashMap.singleton "philosopher" Null
executionErrors = pure $ Error
- { message = "Unable to coerce result to !Int."
+ { message = "Unable to coerce result to Int!."
, locations = [Location 1 26]
, path = [Segment "philosopher", Segment "century"]
}
@@ -364,7 +364,7 @@ spec =
it "sets data to null if a root field isn't nullable" $
let executionErrors = pure $ Error
- { message = "Unable to coerce result to !Int."
+ { message = "Unable to coerce result to Int!."
, locations = [Location 1 3]
, path = [Segment "count"]
}
@@ -375,7 +375,7 @@ spec =
it "detects nullability errors" $
let data'' = Object $ HashMap.singleton "philosopher" Null
executionErrors = pure $ Error
- { message = "Value completion error. Expected type !String, found: null."
+ { message = "Value completion error. Expected type String!, found: null."
, locations = [Location 1 26]
, path = [Segment "philosopher", Segment "firstLanguage"]
}
@@ -389,6 +389,25 @@ spec =
sourceQuery = "{ sequence }"
in sourceQuery `shouldResolveTo` expected
+ context "Arguments" $ do
+ it "gives location information for invalid scalar arguments" $
+ let data'' = Object $ HashMap.singleton "philosopher" Null
+ executionErrors = pure $ Error
+ { message =
+ "Argument \"id\" has invalid type. Expected type ID, found: True."
+ , locations = [Location 1 15]
+ , path = [Segment "philosopher"]
+ }
+ expected = Response data'' executionErrors
+ sourceQuery = "{ philosopher(id: true) { lastName } }"
+ in sourceQuery `shouldResolveTo` expected
+
+ it "puts an object in a list if needed" $
+ let data'' = Object $ HashMap.singleton "withInputObject" $ Type.Int 0
+ expected = Response data'' mempty
+ sourceQuery = "{ withInputObject(values: { name: 0 }) }"
+ in sourceQuery `shouldResolveTo` expected
+
context "queryError" $ do
let namedQuery name = "query " <> name <> " { philosopher(id: \"1\") { interest } }"
twoQueries = namedQuery "A" <> " " <> namedQuery "B"