Skip to content

Commit d1fb6df

Browse files
committed
Add test for executing query against API.Enum
1 parent b477b11 commit d1fb6df

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tests/EnumTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE DeriveGeneric #-}
2-
module EnumTests () where
2+
module EnumTests ( Mode(Directory, NormalFile, ExecutableFile, Symlink) ) where
33

44
import Protolude hiding (Enum)
55

tests/ResolverTests.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import GraphQL.API
1717
( Object
1818
, Field
1919
, Argument
20+
, Enum
2021
, (:>)
2122
)
2223
import GraphQL.Resolver
@@ -26,6 +27,8 @@ import GraphQL.Resolver
2627
)
2728
import GraphQL.Internal.Output (singleError)
2829

30+
import EnumTests ( Mode(NormalFile) )
31+
2932
-- Test a custom error monad
3033
type TMonad = ExceptT Text IO
3134
type T = Object "T" '[] '[ Field "z" Int32
@@ -63,6 +66,13 @@ handler = pure $ \fooId -> do
6366
-- have to wrap the result in a pure.
6467
sequence $ fmap (pure . viewFoo) foo
6568

69+
-- Enum test
70+
type EnumQuery = Object "File" '[]
71+
'[ Field "mode" (Enum "modeEnumName" Mode) ]
72+
73+
enumHandler :: Handler IO EnumQuery
74+
enumHandler = pure $ pure NormalFile
75+
-- /Enum test
6676

6777
tests :: IO TestTree
6878
tests = testSpec "TypeAPI" $ do
@@ -80,3 +90,7 @@ tests = testSpec "TypeAPI" $ do
8090
it "Just works" $ do
8191
Success object <- interpretAnonymousQuery @Query handler "{ test(id: \"10\") { name } }"
8292
encode object `shouldBe` "{\"test\":{\"name\":\"Mort\"}}"
93+
describe "Parse, validate and execute queries against API" $ do
94+
it "API.Enum works" $ do
95+
Success object <- interpretAnonymousQuery @EnumQuery enumHandler "{ mode }"
96+
encode object `shouldBe` "{\"mode\":\"NormalFile\"}"

0 commit comments

Comments
 (0)