forked from OSS/graphql-spice
Document derivation functions
This commit is contained in:
parent
16bcdca066
commit
470580affd
@ -311,6 +311,15 @@ instance FromGraphQL LocalTime
|
||||
stringLE :: Name -> Q Exp
|
||||
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 typeName = do
|
||||
TyConI plainConstructor <- reify typeName
|
||||
@ -362,6 +371,16 @@ deriveFromGraphQL typeName = do
|
||||
makeRecordBody dataConE _ [] = dataConE
|
||||
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 typeName = do
|
||||
TyConI plainConstructor <- reify typeName
|
||||
|
Loading…
Reference in New Issue
Block a user