morpheus-graphql-code-gen-utils 0.24.3 → 0.25.0
raw patch · 4 files changed
+26/−78 lines, 4 filesdep ~morpheus-graphql-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: morpheus-graphql-core
API changes (from Hackage documentation)
+ Data.Morpheus.CodeGen.Internal.AST: PrintableTypeValue :: PrintableValue -> TypeValue
+ Data.Morpheus.CodeGen.Internal.AST: [PrintableValue] :: forall a. (Show a, Lift a) => a -> PrintableValue
+ Data.Morpheus.CodeGen.Internal.AST: data PrintableValue
+ Data.Morpheus.CodeGen.Internal.AST: instance GHC.Show.Show Data.Morpheus.CodeGen.Internal.AST.PrintableValue
+ Data.Morpheus.CodeGen.Internal.AST: instance Prettyprinter.Internal.Pretty Data.Morpheus.CodeGen.Internal.AST.PrintableValue
+ Data.Morpheus.CodeGen.TH: instance Data.Morpheus.CodeGen.TH.PrintExp Data.Morpheus.CodeGen.Internal.AST.PrintableValue
Files
- README.md +2/−75
- morpheus-graphql-code-gen-utils.cabal +2/−2
- src/Data/Morpheus/CodeGen/Internal/AST.hs +17/−1
- src/Data/Morpheus/CodeGen/TH.hs +5/−0
README.md view
@@ -1,76 +1,3 @@-# Morpheus GraphQL Code Gen--Morpheus GraphQL Code Gen helps you to generate GraphQL APIs .--Morpheus GraphQL CLI is still in an early stage of development, so any feedback is more than welcome, and we appreciate any contribution!-Just open an issue here on GitHub, or join [our Slack channel](https://morpheus-graphql-slack-invite.herokuapp.com/) to get in touch.--## Getting Started--Generating dummy Morpheus Api from `schema.gql`--```ssh-morpheus build src/*.gql --root src-```--_src/schema.gql_--```gql-type Query {- deity(name: String!): Deity- deities: [Deity!]!-}--"""-deity description-"""-type Deity {- """- name description- """- name: String!- power: String-}-```--_src/Schema.hs_--```haskell-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE DeriveAnyClass #-}-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE DuplicateRecordFields #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE TypeFamilies #-}--module Schema where--import Data.Data (Typeable)-import Data.Map (empty, fromList)-import Data.Morpheus.Kind (TYPE)-import Data.Morpheus.Types-import Data.Text (Text)-import GHC.Generics (Generic)------ GQL Query --------------------------------data Query m = Query- { queryDeity :: Arg "name" Text -> m (Maybe (Deity m)),- queryDeities :: m [Deity m]- }- deriving (Generic)--instance (Typeable m) => GQLType (Query m) where- type KIND (Query m) = TYPE------ GQL Deity --------------------------------data Deity m = Deity- { deityName :: m Text,- deityPower :: m (Maybe Text)- }- deriving (Generic)+# Morpheus GraphQL Code Gen Utils -instance (Typeable m) => GQLType (Deity m) where- type KIND (Deity m) = TYPE- description _ = Just "\ndeity description\n"- getDescriptions _ = fromList [("name", "\n name description\n ")]-```+Morpheus GraphQL common Code Gen utils.
morpheus-graphql-code-gen-utils.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: morpheus-graphql-code-gen-utils-version: 0.24.3+version: 0.25.0 synopsis: Morpheus GraphQL CLI description: code generator for Morpheus GraphQL category: web, graphql, cli@@ -41,7 +41,7 @@ base >=4.7.0 && <5.0.0 , bytestring >=0.10.4 && <0.12.0 , containers >=0.4.2.1 && <0.7.0- , morpheus-graphql-core >=0.24.0 && <0.25.0+ , morpheus-graphql-core >=0.25.0 && <0.26.0 , prettyprinter >=1.7.0 && <2.0.0 , relude >=0.3.0 && <2.0.0 , template-haskell >=2.0.0 && <3.0.0
src/Data/Morpheus/CodeGen/Internal/AST.hs view
@@ -1,4 +1,6 @@+{-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE NoImplicitPrelude #-} @@ -17,6 +19,7 @@ AssociatedType (..), MethodArgument (..), printTHName,+ PrintableValue (..), ) where @@ -31,6 +34,7 @@ unpackName, ) import qualified Data.Text as T+import Language.Haskell.TH.Syntax (Lift) import qualified Language.Haskell.TH.Syntax as TH import Prettyprinter ( Doc,@@ -49,7 +53,8 @@ vsep, (<+>), )-import Relude hiding (optional, print)+import Relude hiding (Show, optional, print, show)+import Prelude (Show (..)) data DerivingClass = SHOW@@ -69,6 +74,7 @@ | TypeValueBool Bool | TypeValueList [TypeValue] | TypedValueMaybe (Maybe TypeValue)+ | PrintableTypeValue PrintableValue deriving (Show) renderField :: (FieldName, TypeValue) -> Doc n@@ -86,6 +92,7 @@ pretty (TypedValueMaybe (Just x)) = "Just" <+> pretty x pretty (TypedValueMaybe Nothing) = "Nothing" pretty (TypeValueList xs) = prettyList xs+ pretty (PrintableTypeValue x) = pretty x data CodeGenType = CodeGenType { cgTypeName :: CodeGenTypeName,@@ -273,3 +280,12 @@ pretty NoArgument = "" pretty ProxyArgument = "_ " pretty (DestructArgument x xs) = unpack (print x .<> pack (hsep $ map printTHName xs)) <> " "++data PrintableValue where+ PrintableValue :: forall a. (Show a, Lift a) => a -> PrintableValue++instance Show PrintableValue where+ show (PrintableValue a) = show a++instance Pretty PrintableValue where+ pretty (PrintableValue x) = pretty (show x)
src/Data/Morpheus/CodeGen/TH.hs view
@@ -39,6 +39,7 @@ DerivingClass (..), FIELD_TYPE_WRAPPER (..), MethodArgument (..),+ PrintableValue (..), TypeClassInstance (..), TypeValue (..), getFullName,@@ -229,6 +230,7 @@ printExp (TypedValueMaybe (Just x)) = appE (conE 'Just) (printExp x) printExp (TypedValueMaybe Nothing) = conE 'Nothing printExp (TypeValueList xs) = listE $ map printExp xs+ printExp (PrintableTypeValue x) = printExp x genName :: DerivingClass -> Name genName GENERIC = ''Generic@@ -348,3 +350,6 @@ Nothing (map printConstructor cgConstructors) [printDerivClause cgDerivations]++instance PrintExp PrintableValue where+ printExp (PrintableValue x) = [|x|]