{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE NoImplicitPrelude #-} module Data.Morpheus.CodeGen.Internal.AST ( ModuleDefinition (..), CodeGenConfig (..), ServerTypeDefinition (..), GQLTypeDefinition (..), CONST, TypeKind (..), TypeName, TypeRef (..), TypeWrapper (..), unpackName, DerivingClass (..), FIELD_TYPE_WRAPPER (..), ServerConstructorDefinition (..), ServerFieldDefinition (..), Kind (..), ServerDirectiveUsage (..), TypeValue (..), ) where import Data.Morpheus.Types.Internal.AST ( CONST, Description, DirectiveLocation (..), FieldName, TypeKind (..), TypeName, TypeRef (..), TypeWrapper (..), Value, unpackName, ) import Prettyprinter (Doc, Pretty (..), punctuate, vsep, (<+>)) import Relude data ModuleDefinition = ModuleDefinition { ModuleDefinition -> Text moduleName :: Text, ModuleDefinition -> [(Text, [Text])] imports :: [(Text, [Text])], ModuleDefinition -> [Text] extensions :: [Text], ModuleDefinition -> [ServerTypeDefinition] types :: [ServerTypeDefinition] } data FIELD_TYPE_WRAPPER = MONAD | SUBSCRIPTION | PARAMETRIZED | ARG TypeName | TAGGED_ARG FieldName TypeRef | GQL_WRAPPER TypeWrapper deriving (Int -> FIELD_TYPE_WRAPPER -> ShowS [FIELD_TYPE_WRAPPER] -> ShowS FIELD_TYPE_WRAPPER -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [FIELD_TYPE_WRAPPER] -> ShowS $cshowList :: [FIELD_TYPE_WRAPPER] -> ShowS show :: FIELD_TYPE_WRAPPER -> String $cshow :: FIELD_TYPE_WRAPPER -> String showsPrec :: Int -> FIELD_TYPE_WRAPPER -> ShowS $cshowsPrec :: Int -> FIELD_TYPE_WRAPPER -> ShowS Show) data DerivingClass = SHOW | GENERIC deriving (Int -> DerivingClass -> ShowS [DerivingClass] -> ShowS DerivingClass -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [DerivingClass] -> ShowS $cshowList :: [DerivingClass] -> ShowS show :: DerivingClass -> String $cshow :: DerivingClass -> String showsPrec :: Int -> DerivingClass -> ShowS $cshowsPrec :: Int -> DerivingClass -> ShowS Show) data ServerFieldDefinition = ServerFieldDefinition { ServerFieldDefinition -> Text fieldType :: Text, ServerFieldDefinition -> FieldName fieldName :: FieldName, ServerFieldDefinition -> [FIELD_TYPE_WRAPPER] wrappers :: [FIELD_TYPE_WRAPPER] } deriving (Int -> ServerFieldDefinition -> ShowS [ServerFieldDefinition] -> ShowS ServerFieldDefinition -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [ServerFieldDefinition] -> ShowS $cshowList :: [ServerFieldDefinition] -> ShowS show :: ServerFieldDefinition -> String $cshow :: ServerFieldDefinition -> String showsPrec :: Int -> ServerFieldDefinition -> ShowS $cshowsPrec :: Int -> ServerFieldDefinition -> ShowS Show) data Kind = Scalar | Type deriving (Int -> Kind -> ShowS [Kind] -> ShowS Kind -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Kind] -> ShowS $cshowList :: [Kind] -> ShowS show :: Kind -> String $cshow :: Kind -> String showsPrec :: Int -> Kind -> ShowS $cshowsPrec :: Int -> Kind -> ShowS Show) data TypeValue = TypeValueObject TypeName [(FieldName, TypeValue)] | TypeValueNumber Double | TypeValueString Text | TypeValueBool Bool | TypeValueList [TypeValue] | TypedValueMaybe (Maybe TypeValue) deriving (Int -> TypeValue -> ShowS [TypeValue] -> ShowS TypeValue -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [TypeValue] -> ShowS $cshowList :: [TypeValue] -> ShowS show :: TypeValue -> String $cshow :: TypeValue -> String showsPrec :: Int -> TypeValue -> ShowS $cshowsPrec :: Int -> TypeValue -> ShowS Show) renderField :: (FieldName, TypeValue) -> Doc n renderField :: forall n. (FieldName, TypeValue) -> Doc n renderField (FieldName fName, TypeValue fValue) = forall a ann. Pretty a => a -> Doc ann pretty (forall a (t :: NAME). NamePacking a => Name t -> a unpackName FieldName fName :: Text) forall a. Semigroup a => a -> a -> a <> Doc n "=" forall ann. Doc ann -> Doc ann -> Doc ann <+> forall a ann. Pretty a => a -> Doc ann pretty TypeValue fValue instance Pretty TypeValue where pretty :: forall ann. TypeValue -> Doc ann pretty (TypeValueObject TypeName name [(FieldName, TypeValue)] xs) = forall a ann. Pretty a => a -> Doc ann pretty (forall a (t :: NAME). NamePacking a => Name t -> a unpackName TypeName name :: Text) forall ann. Doc ann -> Doc ann -> Doc ann <+> Doc ann "{" forall ann. Doc ann -> Doc ann -> Doc ann <+> forall ann. [Doc ann] -> Doc ann vsep (forall ann. Doc ann -> [Doc ann] -> [Doc ann] punctuate Doc ann "," (forall a b. (a -> b) -> [a] -> [b] map forall n. (FieldName, TypeValue) -> Doc n renderField [(FieldName, TypeValue)] xs)) forall ann. Doc ann -> Doc ann -> Doc ann <+> Doc ann "}" pretty (TypeValueNumber Double x) = forall a ann. Pretty a => a -> Doc ann pretty Double x pretty (TypeValueString Text x) = forall a ann. Pretty a => a -> Doc ann pretty (forall b a. (Show a, IsString b) => a -> b show Text x :: String) pretty (TypeValueBool Bool x) = forall a ann. Pretty a => a -> Doc ann pretty Bool x pretty (TypedValueMaybe (Just TypeValue x)) = Doc ann "Just" forall ann. Doc ann -> Doc ann -> Doc ann <+> forall a ann. Pretty a => a -> Doc ann pretty TypeValue x pretty (TypedValueMaybe Maybe TypeValue Nothing) = Doc ann "Nothing" pretty (TypeValueList [TypeValue] xs) = forall a ann. Pretty a => [a] -> Doc ann prettyList [TypeValue] xs data ServerDirectiveUsage = TypeDirectiveUsage TypeValue | FieldDirectiveUsage FieldName TypeValue | EnumDirectiveUsage TypeName TypeValue deriving (Int -> ServerDirectiveUsage -> ShowS [ServerDirectiveUsage] -> ShowS ServerDirectiveUsage -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [ServerDirectiveUsage] -> ShowS $cshowList :: [ServerDirectiveUsage] -> ShowS show :: ServerDirectiveUsage -> String $cshow :: ServerDirectiveUsage -> String showsPrec :: Int -> ServerDirectiveUsage -> ShowS $cshowsPrec :: Int -> ServerDirectiveUsage -> ShowS Show) data GQLTypeDefinition = GQLTypeDefinition { GQLTypeDefinition -> Kind gqlKind :: Kind, GQLTypeDefinition -> Maybe Text gqlTypeDescription :: Maybe Text, GQLTypeDefinition -> Map Text Text gqlTypeDescriptions :: Map Text Description, GQLTypeDefinition -> [ServerDirectiveUsage] gqlTypeDirectiveUses :: [ServerDirectiveUsage], GQLTypeDefinition -> Map Text (Value CONST) gqlTypeDefaultValues :: Map Text (Value CONST) } deriving (Int -> GQLTypeDefinition -> ShowS [GQLTypeDefinition] -> ShowS GQLTypeDefinition -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [GQLTypeDefinition] -> ShowS $cshowList :: [GQLTypeDefinition] -> ShowS show :: GQLTypeDefinition -> String $cshow :: GQLTypeDefinition -> String showsPrec :: Int -> GQLTypeDefinition -> ShowS $cshowsPrec :: Int -> GQLTypeDefinition -> ShowS Show) data ServerConstructorDefinition = ServerConstructorDefinition { ServerConstructorDefinition -> TypeName constructorName :: TypeName, ServerConstructorDefinition -> [ServerFieldDefinition] constructorFields :: [ServerFieldDefinition] } deriving (Int -> ServerConstructorDefinition -> ShowS [ServerConstructorDefinition] -> ShowS ServerConstructorDefinition -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [ServerConstructorDefinition] -> ShowS $cshowList :: [ServerConstructorDefinition] -> ShowS show :: ServerConstructorDefinition -> String $cshow :: ServerConstructorDefinition -> String showsPrec :: Int -> ServerConstructorDefinition -> ShowS $cshowsPrec :: Int -> ServerConstructorDefinition -> ShowS Show) data ServerTypeDefinition = ServerTypeDefinition { ServerTypeDefinition -> Text tName :: Text, ServerTypeDefinition -> [Text] typeParameters :: [Text], ServerTypeDefinition -> [ServerConstructorDefinition] tCons :: [ServerConstructorDefinition], ServerTypeDefinition -> TypeKind tKind :: TypeKind, ServerTypeDefinition -> [DerivingClass] derives :: [DerivingClass], ServerTypeDefinition -> Maybe GQLTypeDefinition typeGQLType :: Maybe GQLTypeDefinition } | DirectiveTypeDefinition { ServerTypeDefinition -> ServerConstructorDefinition directiveConstructor :: ServerConstructorDefinition, ServerTypeDefinition -> [DerivingClass] directiveDerives :: [DerivingClass], ServerTypeDefinition -> [DirectiveLocation] directiveLocations :: [DirectiveLocation], ServerTypeDefinition -> GQLTypeDefinition directiveGQLType :: GQLTypeDefinition } | ServerInterfaceDefinition TypeName TypeName TypeName deriving (Int -> ServerTypeDefinition -> ShowS [ServerTypeDefinition] -> ShowS ServerTypeDefinition -> String forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [ServerTypeDefinition] -> ShowS $cshowList :: [ServerTypeDefinition] -> ShowS show :: ServerTypeDefinition -> String $cshow :: ServerTypeDefinition -> String showsPrec :: Int -> ServerTypeDefinition -> ShowS $cshowsPrec :: Int -> ServerTypeDefinition -> ShowS Show) newtype CodeGenConfig = CodeGenConfig { CodeGenConfig -> Bool namespace :: Bool }