Skip to content

Commit

Permalink
Release 0.4.0 (#263)
Browse files Browse the repository at this point in the history
* update version in changelog

* update version in package.yml

* get Types

* update readme

* update client readme

* updateFather Of

* update changelog date
  • Loading branch information
nalchevanidze authored Oct 8, 2019
1 parent 7f8b12b commit 1279e13
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 34 deletions.
68 changes: 52 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _stack.yml_
resolver: lts-13.30

extra-deps:
- morpheus-graphql-0.3.1
- morpheus-graphql-0.4.0
- aeson-1.4.4.0
- time-compat-1.9.2.2
```
Expand Down Expand Up @@ -351,49 +351,85 @@ rootResolver =

## Morpheus `GraphQL Client` with Template haskell QuasiQuotes

```haskell
```hs
defineByDocumentFile
"./schema.gql"
[gql|
query GetHero ($byRealm: Realm)
query GetHero ($character: Character)
{
deity (realm:$byRealm) {
deity (fatherOf:$character) {
name
power
fullName
worships {
deity2Name: name
}
}
}
|]
```

with schema:

```gql
input Character {
name: String!
}
type Deity {
name: String!
worships: Deity
}
```

will validate query and Generate:

- response type `GetHero`, `Deity` with `Lens` Instances
- input types: `GetHeroArgs` , `Realm`
- namespaced response and variable types
- instance for `Fetch` typeClass

so that
```hs
data GetHero = GetHero {
deity: DeityDeity
}
-- from: {user
data DeityDeity = DeityDeity {
name: Text,
worships: Maybe DeityWorshipsDeity
}
-- from: {deity{worships
data DeityWorshipsDeity = DeityWorshipsDeity {
name: Text,
}
data GetHeroArgs = GetHeroArgs {
getHeroArgsCharacter: Character
}
data Character = Character {
characterName: Person
}
```

as you see, response type field name collision can be handled with GraphQL `alias`.

with `fetch` you can fetch well typed response `GetHero`.

```haskell
fetchHero :: Args GetHero -> m (Either String GetHero)
fetchHero = fetch jsonRes args
where
args = GetHeroArgs {byRealm = Just Realm {owner = "Zeus", surface = Just 10}}
args = GetHeroArgs {getHeroArgsCharacter = Person {characterName = "Zeus"}}
jsonRes :: ByteString -> m ByteString
jsonRes = <GraphQL APi>
```

resolves well typed response `GetHero`.

except: `defineByDocumentFile` you can use:
types can be generatet from `introspection` too:

```haskell
defineByIntrospectionFile "./introspection.json"
```

or

`defineByIntrospection` where you can directly connect it to server

## Morpheus CLI for Code Generating

Generating dummy Morpheus Api from `schema.gql`
Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [0.3.2] - \*.2019
## [0.4.0] - 09.10.2019

## Changed

Expand Down
69 changes: 53 additions & 16 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: home
---

# Morpheus GraphQL [![Hackage](https://img.shields.io/hackage/v/morpheus-graphql.svg)](https://hackage.haskell.org/package/morpheus-graphql) [![CircleCI](https://circleci.com/gh/morpheusgraphql/morpheus-graphql.svg?style=svg)](https://circleci.com/gh/morpheusgraphql/morpheus-graphql)

Build GraphQL APIs with your favourite functional language!
Expand Down Expand Up @@ -32,7 +33,7 @@ _stack.yml_
resolver: lts-13.30

extra-deps:
- morpheus-graphql-0.3.1
- morpheus-graphql-0.4.0
- aeson-1.4.4.0
- time-compat-1.9.2.2
```
Expand Down Expand Up @@ -354,49 +355,85 @@ rootResolver =

## Morpheus `GraphQL Client` with Template haskell QuasiQuotes

```haskell
```hs
defineByDocumentFile
"./schema.gql"
[gql|
query GetHero ($byRealm: Realm)
query GetHero ($character: Character)
{
deity (realm:$byRealm) {
deity (fatherOf:$character) {
name
power
fullName
worships {
deity2Name: name
}
}
}
|]
```

with schema:

```gql
input Character {
name: String!
}
type Deity {
name: String!
worships: Deity
}
```

will validate query and Generate:

- response type `GetHero`, `Deity` with `Lens` Instances
- input types: `GetHeroArgs` , `Realm`
- namespaced response and variable types
- instance for `Fetch` typeClass

so that
```hs
data GetHero = GetHero {
deity: DeityDeity
}
-- from: {user
data DeityDeity = DeityDeity {
name: Text,
worships: Maybe DeityWorshipsDeity
}
-- from: {deity{worships
data DeityWorshipsDeity = DeityWorshipsDeity {
name: Text,
}
data GetHeroArgs = GetHeroArgs {
getHeroArgsCharacter: Character
}
data Character = Character {
characterName: Person
}
```

as you see, response type field name collision can be handled with GraphQL `alias`.

with `fetch` you can fetch well typed response `GetHero`.

```haskell
fetchHero :: Args GetHero -> m (Either String GetHero)
fetchHero = fetch jsonRes args
where
args = GetHeroArgs {byRealm = Just Realm {owner = "Zeus", surface = Just 10}}
args = GetHeroArgs {getHeroArgsCharacter = Person {characterName = "Zeus"}}
jsonRes :: ByteString -> m ByteString
jsonRes = <GraphQL APi>
```

resolves well typed response `GetHero`.

except: `defineByDocumentFile` you can use:
types can be generatet from `introspection` too:

```haskell
defineByIntrospectionFile "./introspection.json"
```

or

`defineByIntrospection` where you can directly connect it to server

## Morpheus CLI for Code Generating

Generating dummy Morpheus Api from `schema.gql`
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: morpheus-graphql
version: 0.3.1
version: 0.4.0
github: "nalchevanidze/morpheus-graphql"
license: BSD3
author: "Daviti Nalchevanidze"
Expand Down

0 comments on commit 1279e13

Please sign in to comment.