Upgrade templates to mu v0.3 🎸 (#181)

This commit is contained in:
Flavio Corpa 2020-04-17 13:01:25 +02:00 committed by GitHub
parent f0cd4fc5bd
commit e399ebff66
5 changed files with 82 additions and 83 deletions

View File

@ -24,12 +24,12 @@ Notice the use of `MonadServer` in this case. This gives us the ability to:
Being polymorphic here allows us to run the same server in multiple back-ends. Furthermore, by enlarging the set of abilities required for our monad `m`, we can [integrate with other libraries]({% link docs/transformer.md %}), including logging and resource pools.
Since you can declare more than one method in a service, you need to join them into a `ServerT`. You do so by using `singleService` (since gRPC servers may only expose one), and a *tuple* of methods indexed by their name *in the gRPC definition*. In addition to the name of the service, `ServerT` has an additional parameter which records the types of the handlers. Since that list may become quite long, we can ask GHC to write it for us by using the `PartialTypeSignatures` extension and writing an underscore `_` in that position.
Since you can declare more than one method in a service, you need to join them into a `SingleServerT`. You do so by using `singleService` (since gRPC servers may only expose one), and a *tuple* of methods indexed by their name *in the gRPC definition*. In addition to the name of the service, `SingleServerT` has an additional parameter which records the types of the handlers. Since that list may become quite long, we can ask GHC to write it for us by using the `PartialTypeSignatures` extension and writing an underscore `_` in that position.
```haskell
{-# language PartialTypeSignatures #-}
quickstartServer :: (MonadServer m) => ServerT QuickstartService m _
quickstartServer :: (MonadServer m) => SingleServerT QuickstartService m _
quickstartServer = singleService (method @"SayHello" sayHello)
```

View File

@ -103,7 +103,7 @@ Open the `src/Main.hs` file. The contents are quite small right now: a `main` fu
main :: IO ()
main = runGRpcApp msgProtoBuf 8080 server
server :: (MonadServer m) => ServerT Service m _
server :: (MonadServer m) => SingleServerT Service m _
server = singleService ()
```

View File

@ -40,7 +40,7 @@ library
, stm-conduit
, wai
, warp
, warp-grpc
, warp-grpc >=0.4
, warp-tls
hs-source-dirs: src

View File

@ -1,52 +1,53 @@
{-# START_FILE {{name}}.cabal #-}
name: {{name}}
version: 0.1.0.0
name: {{name}}
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}#readme
author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2020{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
category: {{category}}{{^category}}Web{{/category}}
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md
homepage: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}#readme
author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2020{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
category: {{category}}{{^category}}Web{{/category}}
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md
executable {{name}}
hs-source-dirs: src
main-is: Main.hs
other-modules: Schema
default-language: Haskell2010
build-depends: base >= 4.12 && < 5
, text
, mu-schema >= 0.2.0
, mu-rpc >= 0.2.0
, mu-avro >= 0.2.0
, mu-grpc-server >= 0.2.0
hs-source-dirs: src
main-is: Main.hs
other-modules: Schema
default-language: Haskell2010
build-depends:
base >=4.12 && <5
, mu-avro >=0.3.0
, mu-grpc-server >=0.3.0
, mu-rpc >=0.3.0
, mu-schema >=0.3.0
, text
{-# START_FILE stack.yaml #-}
resolver: lts-14.27
resolver: lts-15.8
allow-newer: true
extra-deps:
# mu
- mu-schema-0.2.0.0
- mu-rpc-0.2.0.0
- mu-optics-0.2.0.0
- mu-avro-0.2.0.0
- mu-protobuf-0.2.0.0
- mu-grpc-server-0.2.0.0
- mu-grpc-common-0.2.0.0
- compendium-client-0.2.0.0
- mu-schema-0.3.0.0
- mu-rpc-0.3.0.0
- mu-optics-0.3.0.0
- mu-avro-0.3.0.0
- mu-protobuf-0.3.0.0
- mu-grpc-server-0.3.0.0
- mu-grpc-common-0.3.0.0
- compendium-client-0.3.0.0
# dependencies of mu
- http2-client-0.9.0.0
- http2-grpc-types-0.5.0.0
- http2-grpc-proto3-wire-0.1.0.0
- warp-grpc-0.3.0.0
- warp-grpc-0.4.0.0
- proto3-wire-1.1.0
- language-protobuf-1.0.1
- language-avro-0.1.2.0
- avro-0.4.7.0
- HasBigDecimal-0.1.1
- language-avro-0.1.3.1
- avro-0.5.1.0
{-# START_FILE Setup.hs #-}
import Distribution.Simple
@ -81,7 +82,6 @@ protocol Service {
module Schema where
import Data.Functor.Identity
import Data.Text as T
import GHC.Generics
@ -94,11 +94,11 @@ avdl "TheSchema" "TheService" "." "{{name}}.avdl"
-- data Message
-- = Message { ... }
-- deriving ( Eq, Show, Generic
-- , ToSchema Identity TheSchema "Message"
-- , FromSchema Identity TheSchema "Message" )
-- , ToSchema TheSchema "Message"
-- , FromSchema TheSchema "Message" )
-- B. Use optics
type Message = Term Identity TheSchema (TheSchema :/: "Message")
type Message = Term TheSchema (TheSchema :/: "Message")
{-# START_FILE src/Main.hs #-}
{-# language FlexibleContexts #-}
@ -108,8 +108,6 @@ type Message = Term Identity TheSchema (TheSchema :/: "Message")
module Main where
import Data.Functor.Identity
import Mu.GRpc.Server
import Mu.Server
@ -118,5 +116,5 @@ import Schema
main :: IO ()
main = runGRpcApp msgAvro 8080 server
server :: (MonadServer m) => ServerT Identity TheService m _
server = Server H0
server :: MonadServer m => SingleServerT TheService m _
server = singleService ()

View File

@ -1,52 +1,53 @@
{-# START_FILE {{name}}.cabal #-}
name: {{name}}
version: 0.1.0.0
name: {{name}}
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}#readme
author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2020{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
category: {{category}}{{^category}}Web{{/category}}
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md
homepage: https://github.com/{{github-username}}{{^github-username}}githubuser{{/github-username}}/{{name}}#readme
author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2020{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
category: {{category}}{{^category}}Web{{/category}}
build-type: Simple
cabal-version: >=1.10
extra-source-files: README.md
executable {{name}}
hs-source-dirs: src
main-is: Main.hs
other-modules: Schema
default-language: Haskell2010
build-depends: base >= 4.12 && < 5
, text
, mu-schema >= 0.2.0
, mu-rpc >= 0.2.0
, mu-protobuf >= 0.2.0
, mu-grpc-server >= 0.2.0
hs-source-dirs: src
main-is: Main.hs
other-modules: Schema
default-language: Haskell2010
build-depends:
base >=4.12 && <5
, mu-grpc-server >=0.3.0
, mu-protobuf >=0.3.0
, mu-rpc >=0.3.0
, mu-schema >=0.3.0
, text
{-# START_FILE stack.yaml #-}
resolver: lts-14.27
resolver: lts-15.8
allow-newer: true
extra-deps:
# mu
- mu-schema-0.2.0.0
- mu-rpc-0.2.0.0
- mu-optics-0.2.0.0
- mu-avro-0.2.0.0
- mu-protobuf-0.2.0.0
- mu-grpc-server-0.2.0.0
- mu-grpc-common-0.2.0.0
- compendium-client-0.2.0.0
- mu-schema-0.3.0.0
- mu-rpc-0.3.0.0
- mu-optics-0.3.0.0
- mu-avro-0.3.0.0
- mu-protobuf-0.3.0.0
- mu-grpc-server-0.3.0.0
- mu-grpc-common-0.3.0.0
- compendium-client-0.3.0.0
# dependencies of mu
- http2-client-0.9.0.0
- http2-grpc-types-0.5.0.0
- http2-grpc-proto3-wire-0.1.0.0
- warp-grpc-0.3.0.0
- warp-grpc-0.4.0.0
- proto3-wire-1.1.0
- language-protobuf-1.0.1
- language-avro-0.1.2.0
- avro-0.4.7.0
- HasBigDecimal-0.1.1
- language-avro-0.1.3.1
- avro-0.5.1.0
{-# START_FILE Setup.hs #-}
import Distribution.Simple
@ -98,11 +99,11 @@ grpc "TheSchema" id "{{name}}.proto"
-- data Message
-- = Message { ... }
-- deriving ( Eq, Show, Generic
-- , ToSchema Maybe TheSchema "Message"
-- , FromSchema Maybe TheSchema "Message" )
-- , ToSchema TheSchema "Message"
-- , FromSchema TheSchema "Message" )
-- B. Use optics
type Message = Term Maybe TheSchema (TheSchema :/: "Message")
type Message = Term TheSchema (TheSchema :/: "Message")
{-# START_FILE src/Main.hs #-}
{-# language FlexibleContexts #-}
@ -120,5 +121,5 @@ import Schema
main :: IO ()
main = runGRpcApp msgProtoBuf 8080 server
server :: (MonadServer m) => ServerT Maybe Service m _
server = Server H0
server :: MonadServer m => SingleServerT Service m _
server = singleService ()