summaryrefslogtreecommitdiff
path: root/tests/Test/RootOperationSpec.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-05-14 09:17:14 +0200
committerEugen Wissner <belka@caraus.de>2020-05-14 22:16:56 +0200
commita5c44f30facdaabd94ed25953a3bd88005efa868 (patch)
treebf768b92b5b3ecab5c939d04bf4ec6ebdb7e5257 /tests/Test/RootOperationSpec.hs
parent4c19c88e98bea77ebccc786cd55b30e23ab6e897 (diff)
downloadgraphql-a5c44f30facdaabd94ed25953a3bd88005efa868.tar.gz
Add basic output object type support
Diffstat (limited to 'tests/Test/RootOperationSpec.hs')
-rw-r--r--tests/Test/RootOperationSpec.hs62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/Test/RootOperationSpec.hs b/tests/Test/RootOperationSpec.hs
new file mode 100644
index 0000000..fc86d04
--- /dev/null
+++ b/tests/Test/RootOperationSpec.hs
@@ -0,0 +1,62 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE QuasiQuotes #-}
+module Test.RootOperationSpec
+ ( spec
+ ) where
+
+import Data.Aeson ((.=), object)
+import Data.List.NonEmpty (NonEmpty(..))
+import Language.GraphQL
+import qualified Language.GraphQL.Schema as Schema
+import Test.Hspec (Spec, describe, it, shouldBe)
+import Text.RawString.QQ (r)
+import Language.GraphQL.Type.Definition
+import Language.GraphQL.Type.Schema
+
+schema :: Schema IO
+schema = Schema
+ (ObjectType "Query" queryResolvers)
+ (Just $ ObjectType "Mutation" mutationResolvers)
+ where
+ queryResolvers = Schema.resolversToMap $ garment :| []
+ mutationResolvers = Schema.resolversToMap $ increment :| []
+ garment = Schema.object "garment" $ pure
+ [ Schema.scalar "circumference" $ pure (60 :: Int)
+ ]
+ increment = Schema.scalar "incrementCircumference"
+ $ pure (61 :: Int)
+
+spec :: Spec
+spec =
+ describe "Root operation type" $ do
+ it "returns objects from the root resolvers" $ do
+ let querySource = [r|
+ {
+ garment {
+ circumference
+ }
+ }
+ |]
+ expected = object
+ [ "data" .= object
+ [ "garment" .= object
+ [ "circumference" .= (60 :: Int)
+ ]
+ ]
+ ]
+ actual <- graphql schema querySource
+ actual `shouldBe` expected
+
+ it "chooses Mutation" $ do
+ let querySource = [r|
+ mutation {
+ incrementCircumference
+ }
+ |]
+ expected = object
+ [ "data" .= object
+ [ "incrementCircumference" .= (61 :: Int)
+ ]
+ ]
+ actual <- graphql schema querySource
+ actual `shouldBe` expected