packages feed

morpheus-graphql-cli (empty) → 0.1.0

raw patch · 7 files changed

+298/−0 lines, 7 filesdep +basedep +bytestringdep +filepathsetup-changed

Dependencies added: base, bytestring, filepath, morpheus-graphql, optparse-applicative

Files

+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2019 Daviti Nalchevanidze++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,137 @@+# Morpheus GraphQL CLI++Morpheus GraphQL CLI 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++### Setup++To get started with Morpheus, you first need to add it to your project's dependencies, as follows (assuming you're using hpack):++_package.yml_++```yaml+dependencies:+  - morpheus-graphql-cli+```++Additionally, you should tell stack which version to pick:++_stack.yml_++```yaml+resolver: lts-14.8++extra-deps:+  - morpheus-graphql-0.5.0+```++As Morpheus and is quite new, make sure stack can find morpheus-graphql by running `stack upgrade` and `stack update`++## Code Generating++Generating dummy Morpheus Api from `schema.gql`++```+morpheus build src/schem.gql src/GQLApi.hs+```++_schema.gql_++```gql+type Query {+  deity(name: String!): Deity!+}++type Deity {+  name: String!+  power: String+}+```++_API.hs_++```haskell+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE TypeFamilies #-}++-- generated by 'Morpheus' CLI+module API (rootResolver) where++import  GHC.Generics  (Generic)+import  Data.Morpheus.Kind  (SCALAR, ENUM, INPUT_OBJECT, OBJECT, UNION)+import  Data.Morpheus.Types  (GQLRootResolver(..), toMutResolver, IORes, IOMutRes, IOSubRes, Event(..), SubRootRes, GQLType(..), GQLScalar(..), ScalarValue(..))+import  Data.Text  (Text)++rootResolver :: GQLRootResolver IO () () Query () ()+rootResolver =+  GQLRootResolver+    { queryResolver = resolveQuery+  ,  mutationResolver = return ()+  ,  subscriptionResolver = return ()+    }+++++---- GQL Query -------------------------------+data Query = Query+    { deity :: ArgDeity -> IORes Deity+    }+ deriving (Generic)++data ArgDeity = ArgDeity+    { name :: Text+    }+ deriving (Generic)++instance GQLType Query where+  type KIND Query = OBJECT++++resolveQuery :: IORes Query+resolveQuery = return Query+    { deity = const resolveDeity+    }+++++---- GQL Deity -------------------------------+data Deity = Deity+    { name :: () -> IORes Text+  ,  power :: () -> IORes (Maybe Text)+    }+ deriving (Generic)++instance GQLType Deity where+  type KIND Deity = OBJECT++++resolveDeity :: IORes Deity+resolveDeity = return Deity+    { name = const $ return ""+  ,  power = const $ return Nothing+    }+```++this command will generate Haskell API and resolvers,+resolvers will resolve default values for every object++# About++## The name++_Morpheus_ is the greek god of sleep and dreams whose name comes from the greek word _μορφή_ meaning form or shape.+He is said to be able to mimic different forms and GraphQL is good at doing exactly that: Transforming data in the shape+of many different APIs.++## Team++Morpheus is written and maintained by [_nalchevanidze_](https://github.com/nalchevanidze)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ changelog.md view
+ morpheus-graphql-cli.cabal view
@@ -0,0 +1,59 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: e906a558a100272401a991197866185771fc6b8b70bfac633f19ebf6e1c7b351++name:           morpheus-graphql-cli+version:        0.1.0+synopsis:       Morpheus GraphQL CLI+description:    code generator for Morpheus GraphQL+category:       web, graphql, cli+homepage:       https://morpheusgraphql.com+bug-reports:    https://github.com/https://github.com/morpheusgraphql/morpheus-graphql-cli/issues+author:         Daviti Nalchevanidze+maintainer:     d.nalchevanidze@gmail.com+copyright:      (c) 2019 Daviti Nalchevanidze+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    changelog.md+    README.md++source-repository head+  type: git+  location: https://github.com/https://github.com/morpheusgraphql/morpheus-graphql-cli++executable morpheus+  main-is: Main.hs+  other-modules:+      Paths_morpheus_graphql_cli+  hs-source-dirs:+      src+  ghc-options: -Wall+  build-depends:+      base >=4.7 && <5+    , bytestring+    , filepath >=1.1 && <1.5+    , morpheus-graphql+    , optparse-applicative >=0.12 && <0.15+  default-language: Haskell2010++test-suite morpheus-test+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Paths_morpheus_graphql_cli+  hs-source-dirs:+      test+  ghc-options: -Wall+  build-depends:+      base >=4.7 && <5+    , bytestring+    , filepath >=1.1 && <1.5+    , morpheus-graphql+    , optparse-applicative >=0.12 && <0.15+  default-language: Haskell2010
+ src/Main.hs view
@@ -0,0 +1,73 @@+{-# LANGUAGE NamedFieldPuns #-}++module Main+  ( main+  ) where++import qualified Data.ByteString.Lazy   as L (readFile, writeFile)+import           Data.Semigroup         ((<>))+import           Data.Version           (showVersion)+import           Options.Applicative    (Parser, command, customExecParser, fullDesc, help, helper, info, long, metavar,+                                         prefs, progDesc, short, showHelpOnError, strArgument, subparser, switch)+import qualified Options.Applicative    as OA+import           Paths_morpheus_graphql_cli (version)+import           System.FilePath.Posix  (takeBaseName)++-- MORPHEUS+import           Data.Morpheus.Document (toMorpheusHaskellAPi)++morpheusVersion :: String+morpheusVersion = showVersion version++main :: IO ()+main = defaultParser >>= buildHaskellApi+  where+    buildHaskellApi Options {optionCommand} = executeCommand optionCommand+      where+        executeCommand About = putStrLn $ "Morpheus GraphQL CLI, version " <> morpheusVersion+        executeCommand Build {source, target} =+          toMorpheusHaskellAPi (takeBaseName target) <$> L.readFile source >>= saveDocument+          where+            saveDocument (Left errors) = print errors+            saveDocument (Right doc)   = L.writeFile target doc++data Command+  = Build { source :: FilePath+          , target :: FilePath }+  | About+  deriving (Show)++data Options = Options+  { optionVerbose :: Bool+  , optionCommand :: Command+  } deriving (Show)++data Behavior = Behavior+  { bName  :: String+  , bValue :: Parser Command+  , bDesc  :: String+  }++defaultParser :: IO Options+defaultParser = customExecParser (prefs showHelpOnError) (info (helper <*> optionParser) morpheusDescription)+  where+    morpheusDescription = fullDesc <> progDesc "Morpheus GraphQL CLI - haskell Api Generator"+    -----------------------------------------------------+    optionParser :: OA.Parser Options+    optionParser = Options <$> versionParser <*> commandParser+      where+        versionParser = switch (long "version" <> short 'v' <> help "show Version number")+        ----------------------------------------------------------------------------------------------+        commandParser = subparser $ foldr ((<>) . produceCommand) mempty commands+          where+            pathParser label = strArgument $ metavar label <> help (label <> " file")+            produceCommand Behavior {bName, bValue, bDesc} =+              command bName (info (helper <*> bValue) (fullDesc <> progDesc bDesc))+            commands =+              [ Behavior+                  { bName = "build"+                  , bValue = pure Build <*> pathParser "Source.gql" <*> pathParser "Target.hs"+                  , bDesc = "builds haskell API from  from GhraphQL schema \"*.gql\"  "+                  }+              , Behavior {bName = "about", bValue = pure About, bDesc = "api information"}+              ]
+ test/Spec.hs view
@@ -0,0 +1,6 @@+module Main+  ( main+  ) where++main :: IO ()+main = pure ()