1
+ {-# LANGUAGE DeriveGeneric #-}
1
2
module ValueTests (tests ) where
2
3
3
4
import Protolude
@@ -11,15 +12,24 @@ import qualified GraphQL.Internal.Syntax.AST as AST
11
12
import GraphQL.Internal.Arbitrary (arbitraryText , arbitraryNonEmpty )
12
13
import GraphQL.Value
13
14
( Object
15
+ , Value' (ValueObject' )
14
16
, ObjectField' (.. )
15
17
, astToVariableValue
16
18
, unionObjects
17
19
, objectFields
18
20
, objectFromList
19
21
, toValue
20
22
)
21
- import GraphQL.Internal.Value.FromValue (prop_roundtripValue )
23
+ import GraphQL.Internal.Value.FromValue (FromValue ( .. ), prop_roundtripValue )
22
24
25
+ data Resource = Resource
26
+ { resText :: Text
27
+ , resInt :: Int32
28
+ , resDouble :: Double
29
+ , resBool :: Bool
30
+ } deriving (Generic , Eq , Show )
31
+
32
+ instance FromValue Resource
23
33
24
34
tests :: IO TestTree
25
35
tests = testSpec " Value" $ do
@@ -47,6 +57,23 @@ tests = testSpec "Value" $ do
47
57
describe " Objects" $ do
48
58
prop " have unique fields" $ do
49
59
prop_fieldsUnique
60
+ -- See https://github.com/haskell-graphql/graphql-api/pull/178 for background
61
+ it " derives fromValue instances for objects with more than three fields" $ do
62
+ let Just value = objectFromList
63
+ [ (" resText" , toValue @ Text " text" )
64
+ , (" resBool" , toValue @ Bool False )
65
+ , (" resDouble" , toValue @ Double 1.2 )
66
+ , (" resInt" , toValue @ Int32 32 )
67
+ ]
68
+ let Right observed = fromValue $ ValueObject' value
69
+ let expected = Resource
70
+ { resText = " text"
71
+ , resInt = 32
72
+ , resDouble = 1.2
73
+ , resBool = False
74
+ }
75
+ observed `shouldBe` expected
76
+
50
77
describe " ToValue / FromValue instances" $ do
51
78
prop " Bool" $ prop_roundtripValue @ Bool
52
79
prop " Int32" $ prop_roundtripValue @ Int32
0 commit comments