From a5c44f30facdaabd94ed25953a3bd88005efa868 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 14 May 2020 09:17:14 +0200 Subject: Add basic output object type support --- tests/Test/RootOperationSpec.hs | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/Test/RootOperationSpec.hs (limited to 'tests/Test/RootOperationSpec.hs') 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 -- cgit v1.2.3