Document derivation functions
All checks were successful
Build / audit (push) Successful in 6s
Build / test (push) Successful in 7m35s
Build / doc (push) Successful in 7m19s

This commit is contained in:
Eugen Wissner 2024-07-19 12:55:36 +02:00
parent 16bcdca066
commit 470580affd
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0

View File

@ -311,6 +311,15 @@ instance FromGraphQL LocalTime
stringLE :: Name -> Q Exp stringLE :: Name -> Q Exp
stringLE = litE . stringL . nameBase stringLE = litE . stringL . nameBase
-- | Given a type derives a 'FromGraphQL' instance for it.
--
-- The derivation can only work when all nested types already have 'FromGraphQL'
-- instances.
--
-- The following cases are supported:
--
-- * Records encode input objects.
-- * Sum types with all data constructors without parameters encode Enums.
deriveFromGraphQL :: Name -> Q [Dec] deriveFromGraphQL :: Name -> Q [Dec]
deriveFromGraphQL typeName = do deriveFromGraphQL typeName = do
TyConI plainConstructor <- reify typeName TyConI plainConstructor <- reify typeName
@ -362,6 +371,16 @@ deriveFromGraphQL typeName = do
makeRecordBody dataConE _ [] = dataConE makeRecordBody dataConE _ [] = dataConE
conTName = conT typeName conTName = conT typeName
-- | Given a type derives a 'ToGraphQL' instance for it.
--
-- The derivation can only work when all nested types already have 'ToGraphQL'
-- instances.
--
-- The following cases are supported:
--
-- * Records are decoded as objects.
-- * Sum types with all data constructors without parameters are decoded as Enums.
-- * Sum types whose data constructors have exactly one parameter are decoded as Unions.
deriveToGraphQL :: Name -> Q [Dec] deriveToGraphQL :: Name -> Q [Dec]
deriveToGraphQL typeName = do deriveToGraphQL typeName = do
TyConI plainConstructor <- reify typeName TyConI plainConstructor <- reify typeName