Skip to content

Commit

Permalink
Feature/update docs for Release 0.1.0 (#176)
Browse files Browse the repository at this point in the history
* update docs

* update subscriptions

* update subscriptions docs

* update type missmatch on root resolver

* update Deity

* fix infix
  • Loading branch information
nalchevanidze authored Jun 30, 2019
1 parent debcdfb commit a577319
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ As Morpheus is quite new, make sure stack can find morpheus-graphql by running `
### Building your first API

To define a GraphQL API with Morpheus we start by defining the API Schema as a native Haskell data type,
which derives the `Generic` typeclass. Lazily resolvable fields on this `Query` type are defined via the infix type `-> ResM`,
representing resolving a set of arguments `()` to a concrete value.
which derives the `Generic` typeclass. Lazily resolvable fields on this `Query` type are defined via `a -> ResM b`, representing resolving a set of arguments `a` to a concrete value `b`.

```haskell
data Query = Query
Expand Down Expand Up @@ -214,7 +213,7 @@ newtype Mutation = Mutation
createDeityMutation :: Form ::-> Deity
createDeityMutation = ...
rootResolver :: GQLRootResolver IO Query () ()
rootResolver :: GQLRootResolver IO Query Mutation ()
rootResolver =
GQLRootResolver
{ queryResolver = return Query {...}
Expand All @@ -229,8 +228,42 @@ gqlApi = interpreter rootResolver
```

### Subscriptions
because subscriptions are at an early stage of development, we only use `Text` for communication.
Mutation with same channel ID triggers subscription.

we use `GraphiQL` with old apollo `subscriptions-transport-ws@0.5.4` for subscription handling,
that why server will only recognize events with old apollo format.

```haskell
newtype Mutation = Mutation
{ createDeity :: DeityArgs -> EffectM Deity
} deriving (Generic)
newtype Subscription = Mutation
{ newDeity :: () -> EffectM Deity
} deriving (Generic)
createDeityResolver :: DeityArgs -> EffectM Address
createDeityResolver args = gqlEffectResolver ["UPDATE_DEITY"] createDeityOnDB args
newDeityResolver :: a -> EffectM Address
newDeityResolver _ = gqlEffectResolver ["UPDATE_DEITY"] $ fetchNewDeityFromDB
TODO.
rootResolver :: GQLRootResolver IO Query Mutation Subscription
rootResolver =
GQLRootResolver
{ queryResolver = return Query {...}
, mutationResolver = return Mutation {
createDeity = createDeityResolver
}
, subscriptionResolver = return Subscription {
newDeity = newDeityResolver
}
}
gqlApi :: ByteString -> IO ByteString
gqlApi = interpreter rootResolver
```

# About

Expand Down

0 comments on commit a577319

Please sign in to comment.