1+ {-# LANGUAGE DeriveGeneric #-}
12module ValueTests (tests ) where
23
34import Protolude
@@ -11,15 +12,24 @@ import qualified GraphQL.Internal.Syntax.AST as AST
1112import GraphQL.Internal.Arbitrary (arbitraryText , arbitraryNonEmpty )
1213import GraphQL.Value
1314 ( Object
15+ , Value' (ValueObject' )
1416 , ObjectField' (.. )
1517 , astToVariableValue
1618 , unionObjects
1719 , objectFields
1820 , objectFromList
1921 , toValue
2022 )
21- import GraphQL.Internal.Value.FromValue (prop_roundtripValue )
23+ import GraphQL.Internal.Value.FromValue (FromValue ( .. ), prop_roundtripValue )
2224
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
2333
2434tests :: IO TestTree
2535tests = testSpec " Value" $ do
@@ -47,6 +57,23 @@ tests = testSpec "Value" $ do
4757 describe " Objects" $ do
4858 prop " have unique fields" $ do
4959 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+
5077 describe " ToValue / FromValue instances" $ do
5178 prop " Bool" $ prop_roundtripValue @ Bool
5279 prop " Int32" $ prop_roundtripValue @ Int32
0 commit comments