diff --git a/CHANGELOG.md b/CHANGELOG.md index 2094038..dafe975 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log All notable changes to this project will be documented in this file. +## Unreleased + ## [0.5.0.1] - 2019-09-10 ### Added - Minimal documentation for all public symbols. diff --git a/graphql.cabal b/graphql.cabal index 74a6cf1..9d02aa5 100644 --- a/graphql.cabal +++ b/graphql.cabal @@ -4,7 +4,7 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -- --- hash: 0b3b2cb6ec02a4eeaee98d4c003d4cbe68ab81fde1810b06b0b6eeb61010298c +-- hash: ff53309ec0180b799fcc69ff3a53a6c9411940332e75ebc8097a83d40c085d98 name: graphql version: 0.5.0.1 @@ -70,6 +70,7 @@ test-suite tasty Language.GraphQL.ErrorSpec Language.GraphQL.LexerSpec Language.GraphQL.ParserSpec + Test.FragmentSpec Test.KitchenSinkSpec Test.StarWars.Data Test.StarWars.QuerySpec 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