diff options
Diffstat (limited to 'tests/Test/RootOperationSpec.hs')
| -rw-r--r-- | tests/Test/RootOperationSpec.hs | 62 |
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 |
