summaryrefslogtreecommitdiff
path: root/tests/Language
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-09-28 07:06:15 +0200
committerEugen Wissner <belka@caraus.de>2020-09-28 07:06:15 +0200
commit4602eb1df3a713989b155f0140ff8909eb0370cf (patch)
tree6c82cab7436516ba79e2c13454e9f47ecd2ec4b4 /tests/Language
parentced9b815db516ac4196856c535eedca85f4a1935 (diff)
downloadgraphql-4602eb1df3a713989b155f0140ff8909eb0370cf.tar.gz
Validate arguments are defined
Diffstat (limited to 'tests/Language')
-rw-r--r--tests/Language/GraphQL/ExecuteSpec.hs8
-rw-r--r--tests/Language/GraphQL/ValidateSpec.hs38
2 files changed, 40 insertions, 6 deletions
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs
index 7b67824..e6dd8d9 100644
--- a/tests/Language/GraphQL/ExecuteSpec.hs
+++ b/tests/Language/GraphQL/ExecuteSpec.hs
@@ -25,11 +25,12 @@ import Test.Hspec (Spec, context, describe, it, shouldBe)
import Text.Megaparsec (parse)
import Text.RawString.QQ (r)
-schema :: Schema (Either SomeException)
-schema = Schema
+philosopherSchema :: Schema (Either SomeException)
+philosopherSchema = Schema
{ query = queryType
, mutation = Nothing
, subscription = Just subscriptionType
+ , directives = HashMap.empty
}
queryType :: Out.ObjectType (Either SomeException)
@@ -79,7 +80,8 @@ type EitherStreamOrValue = Either
(Response Aeson.Value)
execute' :: Document -> Either SomeException EitherStreamOrValue
-execute' = execute schema Nothing (mempty :: HashMap Name Aeson.Value)
+execute' =
+ execute philosopherSchema Nothing (mempty :: HashMap Name Aeson.Value)
spec :: Spec
spec =
diff --git a/tests/Language/GraphQL/ValidateSpec.hs b/tests/Language/GraphQL/ValidateSpec.hs
index 1649ad1..84bdfba 100644
--- a/tests/Language/GraphQL/ValidateSpec.hs
+++ b/tests/Language/GraphQL/ValidateSpec.hs
@@ -21,11 +21,12 @@ import Test.Hspec (Spec, describe, it, shouldBe, shouldContain)
import Text.Megaparsec (parse)
import Text.RawString.QQ (r)
-schema :: Schema IO
-schema = Schema
+petSchema :: Schema IO
+petSchema = Schema
{ query = queryType
, mutation = Nothing
, subscription = Just subscriptionType
+ , directives = HashMap.empty
}
queryType :: ObjectType IO
@@ -132,7 +133,7 @@ validate :: Text -> [Error]
validate queryString =
case parse AST.document "" queryString of
Left _ -> []
- Right ast -> toList $ document schema specifiedRules ast
+ Right ast -> toList $ document petSchema specifiedRules ast
spec :: Spec
spec =
@@ -544,3 +545,34 @@ spec =
, locations = [AST.Location 4 19]
}
in validate queryString `shouldBe` [expected]
+
+ it "rejects field arguments missing in the type" $
+ let queryString = [r|
+ {
+ dog {
+ doesKnowCommand(command: CLEAN_UP_HOUSE)
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "Unknown argument \"command\" on field \
+ \\"Dog.doesKnowCommand\"."
+ , locations = [AST.Location 4 35]
+ }
+ in validate queryString `shouldBe` [expected]
+
+ it "rejects directive arguments missing in the definition" $
+ let queryString = [r|
+ {
+ dog {
+ isHousetrained(atOtherHomes: true) @include(unless: false)
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "Unknown argument \"unless\" on directive \"@include\"."
+ , locations = [AST.Location 4 63]
+ }
+ in validate queryString `shouldBe` [expected]