morpheus-graphql-cli: Morpheus GraphQL CLI

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

code generator for Morpheus GraphQL


[Skip to Readme]

Properties

Versions 0.1.0, 0.1.0
Change log changelog.md
Dependencies base (>=4.7 && <5), bytestring, filepath (>=1.1 && <1.5), morpheus-graphql, optparse-applicative (>=0.12 && <0.15) [details]
License BSD-3-Clause
Copyright (c) 2019 Daviti Nalchevanidze
Author Daviti Nalchevanidze
Maintainer d.nalchevanidze@gmail.com
Category web, graphql, cli
Home page https://morpheusgraphql.com
Bug tracker https://github.com/https://github.com/morpheusgraphql/morpheus-graphql-cli/issues
Source repo head: git clone https://github.com/https://github.com/morpheusgraphql/morpheus-graphql-cli
Uploaded by nalchevanidze at 2019-11-01T01:06:29Z

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for morpheus-graphql-cli-0.1.0

[back to package description]

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 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

dependencies:
  - morpheus-graphql-cli

Additionally, you should tell stack which version to pick:

stack.yml

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

type Query {
  deity(name: String!): Deity!
}

type Deity {
  name: String!
  power: String
}

API.hs

{-# 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