diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-07-19 12:55:36 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-07-19 12:55:36 +0200 |
| commit | 470580affde2af5bfce2a38c5d0c8867b7b114bb (patch) | |
| tree | e5404da7799874acb33a1efca8602fa78b062fc8 /src/Language/GraphQL/Class.hs | |
| parent | 16bcdca066715c74145b38bde5cdd6d901683704 (diff) | |
| download | graphql-spice-470580affde2af5bfce2a38c5d0c8867b7b114bb.tar.gz | |
Document derivation functions
Diffstat (limited to 'src/Language/GraphQL/Class.hs')
| -rw-r--r-- | src/Language/GraphQL/Class.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/Language/GraphQL/Class.hs b/src/Language/GraphQL/Class.hs index e08ec65..df52d2b 100644 --- a/src/Language/GraphQL/Class.hs +++ b/src/Language/GraphQL/Class.hs @@ -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 |
