morpheus-graphql-code-gen 0.24.0 → 0.24.1
raw patch · 5 files changed
+29/−22 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- app/CLI/File.hs +3/−2
- app/CLI/Generator.hs +3/−6
- app/Main.hs +21/−11
- morpheus-graphql-code-gen.cabal +1/−1
- src/Data/Morpheus/CodeGen/Server/Internal/AST.hs +1/−2
app/CLI/File.hs view
@@ -12,6 +12,7 @@ Result (..), ) import Data.Morpheus.Types.Internal.AST (GQLError (..), msg)+import Data.Text (pack) import Relude hiding (ByteString, readFile, writeFile) import System.FilePath.Posix ( dropExtensions,@@ -50,5 +51,5 @@ | check = printWarnings warnings >> checkGenerated path result | otherwise = printWarnings warnings >> writeFile path result $> True -getModuleNameByPath :: FilePath -> FilePath -> [Char]-getModuleNameByPath root path = intercalate "." $ splitDirectories $ dropExtensions $ makeRelative root path+getModuleNameByPath :: FilePath -> FilePath -> Text+getModuleNameByPath root path = pack . intercalate "." $ splitDirectories $ dropExtensions $ makeRelative root path
app/CLI/Generator.hs view
@@ -23,7 +23,6 @@ ) import Data.Morpheus.CodeGen.Internal.AST import Data.Morpheus.Internal.Ext (GQLResult)-import qualified Data.Text as T import Prettyprinter import Relude hiding (ByteString, print) @@ -34,13 +33,13 @@ } deriving (Show) -processServerDocument :: BuildConfig -> String -> ByteString -> GQLResult ByteString+processServerDocument :: BuildConfig -> Text -> ByteString -> GQLResult ByteString processServerDocument BuildConfig {..} moduleName schema = do types <- parseServerTypeDefinitions CodeGenConfig {namespace = namespaces} schema pure $ print $ ModuleDefinition- { moduleName = T.pack moduleName,+ { moduleName, imports = [ ("Data.Data", ["Typeable"]), ("Data.Morpheus.Kind", ["TYPE"]),@@ -55,9 +54,7 @@ "DeriveGeneric", "DuplicateRecordFields", "OverloadedStrings",- "TypeFamilies",- "{-# HLINT ignore \"Use camelCase\" #-}",- "{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}"+ "TypeFamilies" ], types }
app/Main.hs view
@@ -30,7 +30,6 @@ ( readFile, ) import Data.Morpheus.Client (readSchemaSource)-import Data.Text (pack) import qualified Data.Text.IO as TIO import Data.Version (showVersion) import qualified Paths_morpheus_graphql_code_gen as CLI@@ -84,38 +83,49 @@ let namespaces = fromMaybe False (options >>= namespace) let patterns = map (normalise . (root </>)) includes files <- concat <$> traverse glob patterns- let globalImports = getImports options- pure (root, namespaces, files, globalImports)+ pure+ ( root,+ namespaces,+ files,+ getImports options+ ) +getSchemaPath :: MonadFail m => FilePath -> String -> Maybe FilePath -> m FilePath+getSchemaPath root name schema = do+ schemaPath <- maybe (fail $ "client service " <> name <> " should provide schema!") pure schema+ pure $ normalise $ root </> schemaPath+ handleClientService :: Context -> Service -> IO CommandResult handleClientService ctx s@Service {name, schema} = do (root, namespaces, files, globalImports) <- parseServiceData ctx s putStrLn ("\n build:" <> name)- schemaPath <- maybe (fail $ "client service " <> name <> " should provide schema!") pure schema+ schemaPath <- getSchemaPath root name schema let config = BuildConfig {..}- globals <- buildClientGlobals ctx config (normalise $ root </> schemaPath)- and . (globals :) <$> traverse (buildClientQuery ctx config (normalise $ root </> schemaPath)) files+ globals <- buildClientGlobals ctx config schemaPath+ and . (globals :) <$> traverse (buildClientQuery ctx config schemaPath) files buildClientGlobals :: Context -> BuildConfig -> FilePath -> IO CommandResult buildClientGlobals ctx options schemaPath = do putStr (" - " <> schemaPath <> "\n") schemaDoc <- readSchemaSource schemaPath let hsPath = processFileName schemaPath- let moduleName = pack $ getModuleNameByPath (root options) hsPath+ let moduleName = getModuleNameByPath (root options) hsPath let result = processClientDocument options schemaDoc Nothing moduleName processDocument (isCheck ctx) hsPath result +getSchemaImports :: BuildConfig -> FilePath -> [Text]+getSchemaImports options schemaPath = [getModuleNameByPath (root options) (processFileName schemaPath)]+ buildClientQuery :: Context -> BuildConfig -> FilePath -> FilePath -> IO CommandResult buildClientQuery ctx options schemaPath queryPath = do putStr (" - " <> queryPath <> "\n") file <- TIO.readFile queryPath schemaDoc <- readSchemaSource schemaPath+ let hsPath = processFileName queryPath let moduleName = getModuleNameByPath (root options) hsPath- let globalModuleName = pack (getModuleNameByPath (root options) (processFileName schemaPath))- let result = processClientDocument (options {globalImports = [globalModuleName]}) schemaDoc (Just file) (pack moduleName)+ let imports = getSchemaImports options schemaPath <> globalImports options+ let result = processClientDocument (options {globalImports = imports}) schemaDoc (Just file) moduleName processDocument (isCheck ctx) hsPath result- where- hsPath = processFileName queryPath handleServerService :: Context -> Service -> IO CommandResult handleServerService ctx s@Service {name} = do
morpheus-graphql-code-gen.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: morpheus-graphql-code-gen-version: 0.24.0+version: 0.24.1 synopsis: Morpheus GraphQL CLI description: code generator for Morpheus GraphQL category: web, graphql, cli
src/Data/Morpheus/CodeGen/Server/Internal/AST.hs view
@@ -141,8 +141,7 @@ <+> unpack (print interfaceName .<> "m") <+> unpack (print unionName .<> "m") <> line- -- TODO: on scalar we should render user provided type- pretty ScalarType {..} = "type" <+> ignore (print scalarTypeName) <+> "= Int"+ pretty ScalarType {} = "" pretty (DataType cgType) = pretty cgType pretty (GQLTypeInstance kind gql) | kind == Scalar = ""