summaryrefslogtreecommitdiff
path: root/tests/Test
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2019-09-13 20:33:39 +0200
committerEugen Wissner <belka@caraus.de>2019-09-13 20:33:39 +0200
commitc075a41582279be2ed1f2b5d5c758ab14d664770 (patch)
tree9811dcbe8ea517ca5c8eed32c36e6215544ae0db /tests/Test
parent721cbaee17561f3d9b58fb0c4ebe6e3a29d6c73d (diff)
downloadgraphql-c075a41582279be2ed1f2b5d5c758ab14d664770.tar.gz
Add pending inline fragment tests
Diffstat (limited to 'tests/Test')
-rw-r--r--tests/Test/FragmentSpec.hs57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/Test/FragmentSpec.hs b/tests/Test/FragmentSpec.hs
new file mode 100644
index 0000000..219be4a
--- /dev/null
+++ b/tests/Test/FragmentSpec.hs
@@ -0,0 +1,57 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE QuasiQuotes #-}
+module Test.FragmentSpec
+ ( spec
+ ) where
+
+import Data.Aeson (object, (.=))
+import Data.List.NonEmpty (NonEmpty(..))
+import Data.Text (Text)
+import Language.GraphQL
+import qualified Language.GraphQL.Schema as Schema
+import Test.Hspec (Spec, it, shouldBe, xdescribe)
+import Text.RawString.QQ (r)
+
+size :: Schema.Resolver IO
+size = Schema.scalar "size" $ return ("L" :: Text)
+
+circumference :: Schema.Resolver IO
+circumference = Schema.scalar "circumference" $ return (60 :: Int)
+
+garment :: Text -> Schema.Resolver IO
+garment typeName = Schema.object "garment" $ return
+ [ if typeName == "Hat" then circumference else size
+ , Schema.scalar "__typename" $ return typeName
+ ]
+
+inlineQuery :: Text
+inlineQuery = [r|{
+ garment {
+ ... on Hat {
+ circumference
+ }
+ ... on Shirt {
+ size
+ }
+ }
+}|]
+
+spec :: Spec
+spec = xdescribe "Inline fragment executor" $ do
+ it "chooses the first selection if the type matches" $ do
+ actual <- graphql (garment "Hat" :| []) inlineQuery
+ let expected = object
+ [ "garment" .= object
+ [ "circumference" .= (60 :: Int)
+ ]
+ ]
+ in actual `shouldBe` expected
+
+ it "chooses the last selection if the type matches" $ do
+ actual <- graphql (garment "Shirt" :| []) inlineQuery
+ let expected = object
+ [ "garment" .= object
+ [ "size" .= ("L" :: Text)
+ ]
+ ]
+ in actual `shouldBe` expected