From efa30e6154b52a04b1012256e7eb7fe5c34da563 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 10:35:28 +0200 Subject: [PATCH 1/8] Move `.Logging` out of `demo-common` This only leaves the API definition, which we want to use in more than just the demo. --- demo-client/Demo/Client/API/Core/Greeter.hs | 2 +- demo-client/Demo/Client/API/Core/RouteGuide.hs | 2 +- demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs | 2 +- demo-client/Demo/Client/API/StreamType/IO/Greeter.hs | 2 +- demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs | 2 +- demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs | 2 +- .../Demo/Common => demo-client/Demo/Client/Util}/Logging.hs | 2 +- grapesy.cabal | 3 +-- 8 files changed, 8 insertions(+), 9 deletions(-) rename {demo-common/Demo/Common => demo-client/Demo/Client/Util}/Logging.hs (93%) diff --git a/demo-client/Demo/Client/API/Core/Greeter.hs b/demo-client/Demo/Client/API/Core/Greeter.hs index 6747ce41..d473d66b 100644 --- a/demo-client/Demo/Client/API/Core/Greeter.hs +++ b/demo-client/Demo/Client/API/Core/Greeter.hs @@ -11,8 +11,8 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr +import Demo.Client.Util.Logging import Demo.Common.API -import Demo.Common.Logging {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/Core/RouteGuide.hs b/demo-client/Demo/Client/API/Core/RouteGuide.hs index 9819dde1..c0c9bd64 100644 --- a/demo-client/Demo/Client/API/Core/RouteGuide.hs +++ b/demo-client/Demo/Client/API/Core/RouteGuide.hs @@ -7,7 +7,7 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Demo.Common.API -import Demo.Common.Logging +import Demo.Client.Util.Logging {------------------------------------------------------------------------------- RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs index 3f368469..38f2e88c 100644 --- a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs @@ -14,8 +14,8 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr +import Demo.Client.Util.Logging import Demo.Common.API -import Demo.Common.Logging {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs index 11d8e34d..ba24271e 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs @@ -8,8 +8,8 @@ import Network.GRPC.Client.StreamType.IO import Network.GRPC.Common.NextElem qualified as NextElem import Network.GRPC.Common.Protobuf +import Demo.Client.Util.Logging import Demo.Common.API -import Demo.Common.Logging {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs index 37e28f18..11189754 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs @@ -15,8 +15,8 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr +import Demo.Client.Util.Logging import Demo.Common.API -import Demo.Common.Logging {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs index ea979bec..c648bea7 100644 --- a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs @@ -14,7 +14,7 @@ import Network.GRPC.Common.NextElem qualified as NextElem import Network.GRPC.Common.Protobuf import Demo.Common.API -import Demo.Common.Logging qualified as Logging +import Demo.Client.Util.Logging qualified as Logging {------------------------------------------------------------------------------- Example custom monad diff --git a/demo-common/Demo/Common/Logging.hs b/demo-client/Demo/Client/Util/Logging.hs similarity index 93% rename from demo-common/Demo/Common/Logging.hs rename to demo-client/Demo/Client/Util/Logging.hs index 7e329aff..8b1939b8 100644 --- a/demo-common/Demo/Common/Logging.hs +++ b/demo-client/Demo/Client/Util/Logging.hs @@ -1,4 +1,4 @@ -module Demo.Common.Logging ( +module Demo.Client.Util.Logging ( threadSafeTracer , logMsg ) where diff --git a/grapesy.cabal b/grapesy.cabal index ed18f34e..e4d511da 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -374,9 +374,9 @@ executable demo-client Demo.Client.API.StreamType.MonadStack.Greeter Demo.Client.Cmdline Demo.Client.Util.DelayOr + Demo.Client.Util.Logging Demo.Common.API - Demo.Common.Logging Paths_grapesy @@ -424,7 +424,6 @@ executable demo-server Demo.Server.Service.RouteGuide Demo.Common.API - Demo.Common.Logging Proto.Helloworld Proto.Helloworld_Fields From f4c647357ad71cb5ce0482a03bbe6b34a6e82365 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 10:49:43 +0200 Subject: [PATCH 2/8] Move `.API` to `proto/` We'll probably want to clean it up a bit more still though. --- demo-client/Demo/Client/API/Core/Greeter.hs | 3 ++- demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs | 2 +- demo-client/Demo/Client/API/Core/RouteGuide.hs | 3 ++- .../Demo/Client/API/StreamType/Conduit/RouteGuide.hs | 3 ++- demo-client/Demo/Client/API/StreamType/IO/Greeter.hs | 3 ++- demo-client/Demo/Client/API/StreamType/IO/Ping.hs | 2 +- demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs | 3 ++- .../Demo/Client/API/StreamType/MonadStack/Greeter.hs | 3 ++- demo-client/Demo/Client/Cmdline.hs | 3 ++- demo-server/Demo/Server/Service/Greeter.hs | 2 +- demo-server/Demo/Server/Service/Ping.hs | 2 +- demo-server/Demo/Server/Service/RouteGuide.hs | 5 +++-- demo-server/Main.hs | 6 +++--- grapesy.cabal | 9 ++------- {demo-common/Demo/Common => proto/Proto}/API.hs | 4 ++-- 15 files changed, 28 insertions(+), 25 deletions(-) rename {demo-common/Demo/Common => proto/Proto}/API.hs (99%) diff --git a/demo-client/Demo/Client/API/Core/Greeter.hs b/demo-client/Demo/Client/API/Core/Greeter.hs index d473d66b..e9ef7449 100644 --- a/demo-client/Demo/Client/API/Core/Greeter.hs +++ b/demo-client/Demo/Client/API/Core/Greeter.hs @@ -12,7 +12,8 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr import Demo.Client.Util.Logging -import Demo.Common.API + +import Proto.API {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs b/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs index bb5a1708..5bab0ba4 100644 --- a/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs +++ b/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs @@ -6,7 +6,7 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Demo.Common.API +import Proto.API {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/Core/RouteGuide.hs b/demo-client/Demo/Client/API/Core/RouteGuide.hs index c0c9bd64..50fa8cde 100644 --- a/demo-client/Demo/Client/API/Core/RouteGuide.hs +++ b/demo-client/Demo/Client/API/Core/RouteGuide.hs @@ -6,9 +6,10 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Demo.Common.API import Demo.Client.Util.Logging +import Proto.API + {------------------------------------------------------------------------------- RouteGuide -------------------------------------------------------------------------------} diff --git a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs index 38f2e88c..9c371089 100644 --- a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs @@ -15,7 +15,8 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr import Demo.Client.Util.Logging -import Demo.Common.API + +import Proto.API {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs index ba24271e..d64b9d10 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs @@ -9,7 +9,8 @@ import Network.GRPC.Common.NextElem qualified as NextElem import Network.GRPC.Common.Protobuf import Demo.Client.Util.Logging -import Demo.Common.API + +import Proto.API {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs index 3f49b4f1..dd115afb 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs @@ -5,7 +5,7 @@ import Data.ByteString.Lazy.Char8 qualified as Lazy import Network.GRPC.Client import Network.GRPC.Client.StreamType.IO -import Demo.Common.API +import Proto.API ping :: Connection -> Lazy.ByteString -> IO () ping conn msg = do diff --git a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs index 11189754..c4a071f6 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs @@ -16,7 +16,8 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr import Demo.Client.Util.Logging -import Demo.Common.API + +import Proto.API {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs index c648bea7..62c0f69b 100644 --- a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs @@ -13,9 +13,10 @@ import Network.GRPC.Client.StreamType.CanCallRPC import Network.GRPC.Common.NextElem qualified as NextElem import Network.GRPC.Common.Protobuf -import Demo.Common.API import Demo.Client.Util.Logging qualified as Logging +import Proto.API + {------------------------------------------------------------------------------- Example custom monad -------------------------------------------------------------------------------} diff --git a/demo-client/Demo/Client/Cmdline.hs b/demo-client/Demo/Client/Cmdline.hs index ec0832a1..4a253af4 100644 --- a/demo-client/Demo/Client/Cmdline.hs +++ b/demo-client/Demo/Client/Cmdline.hs @@ -35,7 +35,8 @@ import Network.GRPC.Common.Protobuf import Paths_grapesy import Demo.Client.Util.DelayOr (DelayOr(..)) -import Demo.Common.API + +import Proto.API {------------------------------------------------------------------------------- Definition diff --git a/demo-server/Demo/Server/Service/Greeter.hs b/demo-server/Demo/Server/Service/Greeter.hs index 43fa4851..7dbc0931 100644 --- a/demo-server/Demo/Server/Service/Greeter.hs +++ b/demo-server/Demo/Server/Service/Greeter.hs @@ -13,7 +13,7 @@ import Network.GRPC.Server import Network.GRPC.Server.Protobuf import Network.GRPC.Server.StreamType -import Demo.Common.API +import Proto.API {------------------------------------------------------------------------------- Top-level diff --git a/demo-server/Demo/Server/Service/Ping.hs b/demo-server/Demo/Server/Service/Ping.hs index 71503aa4..b8b3fadf 100644 --- a/demo-server/Demo/Server/Service/Ping.hs +++ b/demo-server/Demo/Server/Service/Ping.hs @@ -4,7 +4,7 @@ import Data.ByteString.Lazy qualified as Lazy (ByteString) import Network.GRPC.Server.StreamType -import Demo.Common.API +import Proto.API handlers :: Methods IO '[Ping] handlers = diff --git a/demo-server/Demo/Server/Service/RouteGuide.hs b/demo-server/Demo/Server/Service/RouteGuide.hs index 29489325..1bb96473 100644 --- a/demo-server/Demo/Server/Service/RouteGuide.hs +++ b/demo-server/Demo/Server/Service/RouteGuide.hs @@ -8,6 +8,7 @@ module Demo.Server.Service.RouteGuide ( ) where import Control.Monad.IO.Class +import Control.Monad.Trans.Reader import Control.Monad.Trans.State (StateT, evalStateT) import Control.Monad.Trans.State qualified as State import Data.Map qualified as Map @@ -21,10 +22,10 @@ import Network.GRPC.Server import Network.GRPC.Server.Protobuf import Network.GRPC.Server.StreamType -import Demo.Common.API import Demo.Server.Aux.RouteGuide import Demo.Server.Cmdline -import Control.Monad.Trans.Reader + +import Proto.API {------------------------------------------------------------------------------- Custom handler monad diff --git a/demo-server/Main.hs b/demo-server/Main.hs index 95d246cf..094d2ea3 100644 --- a/demo-server/Main.hs +++ b/demo-server/Main.hs @@ -12,14 +12,14 @@ import Network.GRPC.Server.Protobuf import Network.GRPC.Server.Run import Network.GRPC.Server.StreamType +import Paths_grapesy + import Demo.Server.Cmdline import Demo.Server.Service.Greeter qualified as Greeter import Demo.Server.Service.Ping qualified as Ping import Demo.Server.Service.RouteGuide qualified as RouteGuide -import Demo.Common.API - -import Paths_grapesy +import Proto.API {------------------------------------------------------------------------------- All services diff --git a/grapesy.cabal b/grapesy.cabal index e4d511da..6c41cbc8 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -359,7 +359,6 @@ executable demo-client , common-executable-flags hs-source-dirs: demo-client - demo-common proto main-is: Main.hs @@ -376,10 +375,9 @@ executable demo-client Demo.Client.Util.DelayOr Demo.Client.Util.Logging - Demo.Common.API - Paths_grapesy + Proto.API Proto.Helloworld Proto.Helloworld_Fields Proto.RouteGuide @@ -412,7 +410,6 @@ executable demo-server , common-executable-flags hs-source-dirs: demo-server - demo-common proto main-is: Main.hs @@ -423,8 +420,7 @@ executable demo-server Demo.Server.Service.Ping Demo.Server.Service.RouteGuide - Demo.Common.API - + Proto.API Proto.Helloworld Proto.Helloworld_Fields Proto.RouteGuide @@ -441,7 +437,6 @@ executable demo-server , aeson >= 1.5 && < 2.3 , bytestring >= 0.10 && < 0.13 , containers >= 0.6 && < 0.8 - , contra-tracer >= 0.2 && < 0.3 , exceptions >= 0.10 && < 0.11 , network >= 3.1 && < 3.3 , optparse-applicative >= 0.16 && < 0.19 diff --git a/demo-common/Demo/Common/API.hs b/proto/Proto/API.hs similarity index 99% rename from demo-common/Demo/Common/API.hs rename to proto/Proto/API.hs index d7de4aab..85b60055 100644 --- a/demo-common/Demo/Common/API.hs +++ b/proto/Proto/API.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -Wno-orphans #-} -module Demo.Common.API ( +module Proto.API ( -- * Greeter SayHello , SayHelloStreamReply @@ -29,11 +29,11 @@ import Data.ByteString qualified as Strict import GHC.TypeLits import Network.GRPC.Common +import Network.GRPC.Common.Binary import Network.GRPC.Common.Protobuf import Proto.Helloworld import Proto.RouteGuide -import Network.GRPC.Common.Binary {------------------------------------------------------------------------------- Greeter From 459046f16030ac014a5884f504a15c12abae27fb Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 11:08:50 +0200 Subject: [PATCH 3/8] Split `Proto.API` into separate modules --- demo-client/Demo/Client/API/Core/Greeter.hs | 2 +- .../Demo/Client/API/Core/NoFinal/Greeter.hs | 2 +- .../Demo/Client/API/Core/RouteGuide.hs | 2 +- .../API/StreamType/Conduit/RouteGuide.hs | 2 +- .../Demo/Client/API/StreamType/IO/Greeter.hs | 2 +- .../Demo/Client/API/StreamType/IO/Ping.hs | 2 +- .../Client/API/StreamType/IO/RouteGuide.hs | 2 +- .../API/StreamType/MonadStack/Greeter.hs | 2 +- demo-client/Demo/Client/Cmdline.hs | 4 +- demo-server/Demo/Server/Service/Greeter.hs | 2 +- demo-server/Demo/Server/Service/Ping.hs | 2 +- demo-server/Demo/Server/Service/RouteGuide.hs | 2 +- demo-server/Main.hs | 4 +- grapesy.cabal | 8 +++- proto/Proto/{API.hs => API/Helloworld.hs} | 39 +------------------ proto/Proto/API/Ping.hs | 19 +++++++++ proto/Proto/API/RouteGuide.hs | 30 ++++++++++++++ 17 files changed, 74 insertions(+), 52 deletions(-) rename proto/Proto/{API.hs => API/Helloworld.hs} (60%) create mode 100644 proto/Proto/API/Ping.hs create mode 100644 proto/Proto/API/RouteGuide.hs diff --git a/demo-client/Demo/Client/API/Core/Greeter.hs b/demo-client/Demo/Client/API/Core/Greeter.hs index e9ef7449..8448324c 100644 --- a/demo-client/Demo/Client/API/Core/Greeter.hs +++ b/demo-client/Demo/Client/API/Core/Greeter.hs @@ -13,7 +13,7 @@ import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr import Demo.Client.Util.Logging -import Proto.API +import Proto.API.Helloworld {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs b/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs index 5bab0ba4..9351f02e 100644 --- a/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs +++ b/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs @@ -6,7 +6,7 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Proto.API +import Proto.API.Helloworld {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/Core/RouteGuide.hs b/demo-client/Demo/Client/API/Core/RouteGuide.hs index 50fa8cde..1ba01ec9 100644 --- a/demo-client/Demo/Client/API/Core/RouteGuide.hs +++ b/demo-client/Demo/Client/API/Core/RouteGuide.hs @@ -8,7 +8,7 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.Logging -import Proto.API +import Proto.API.RouteGuide {------------------------------------------------------------------------------- RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs index 9c371089..51479639 100644 --- a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs @@ -16,7 +16,7 @@ import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr import Demo.Client.Util.Logging -import Proto.API +import Proto.API.RouteGuide {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs index d64b9d10..ceb07513 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs @@ -10,7 +10,7 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.Logging -import Proto.API +import Proto.API.Helloworld {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs index dd115afb..15f8b2a5 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs @@ -5,7 +5,7 @@ import Data.ByteString.Lazy.Char8 qualified as Lazy import Network.GRPC.Client import Network.GRPC.Client.StreamType.IO -import Proto.API +import Proto.API.Ping ping :: Connection -> Lazy.ByteString -> IO () ping conn msg = do diff --git a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs index c4a071f6..1974db34 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs @@ -17,7 +17,7 @@ import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr import Demo.Client.Util.Logging -import Proto.API +import Proto.API.RouteGuide {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs index 62c0f69b..1955d0f1 100644 --- a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs @@ -15,7 +15,7 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.Logging qualified as Logging -import Proto.API +import Proto.API.Helloworld {------------------------------------------------------------------------------- Example custom monad diff --git a/demo-client/Demo/Client/Cmdline.hs b/demo-client/Demo/Client/Cmdline.hs index 4a253af4..427a024b 100644 --- a/demo-client/Demo/Client/Cmdline.hs +++ b/demo-client/Demo/Client/Cmdline.hs @@ -36,7 +36,9 @@ import Paths_grapesy import Demo.Client.Util.DelayOr (DelayOr(..)) -import Proto.API +import Proto.API.Helloworld +import Proto.API.Ping +import Proto.API.RouteGuide {------------------------------------------------------------------------------- Definition diff --git a/demo-server/Demo/Server/Service/Greeter.hs b/demo-server/Demo/Server/Service/Greeter.hs index 7dbc0931..48098b22 100644 --- a/demo-server/Demo/Server/Service/Greeter.hs +++ b/demo-server/Demo/Server/Service/Greeter.hs @@ -13,7 +13,7 @@ import Network.GRPC.Server import Network.GRPC.Server.Protobuf import Network.GRPC.Server.StreamType -import Proto.API +import Proto.API.Helloworld {------------------------------------------------------------------------------- Top-level diff --git a/demo-server/Demo/Server/Service/Ping.hs b/demo-server/Demo/Server/Service/Ping.hs index b8b3fadf..cda77a78 100644 --- a/demo-server/Demo/Server/Service/Ping.hs +++ b/demo-server/Demo/Server/Service/Ping.hs @@ -4,7 +4,7 @@ import Data.ByteString.Lazy qualified as Lazy (ByteString) import Network.GRPC.Server.StreamType -import Proto.API +import Proto.API.Ping handlers :: Methods IO '[Ping] handlers = diff --git a/demo-server/Demo/Server/Service/RouteGuide.hs b/demo-server/Demo/Server/Service/RouteGuide.hs index 1bb96473..03cc6866 100644 --- a/demo-server/Demo/Server/Service/RouteGuide.hs +++ b/demo-server/Demo/Server/Service/RouteGuide.hs @@ -25,7 +25,7 @@ import Network.GRPC.Server.StreamType import Demo.Server.Aux.RouteGuide import Demo.Server.Cmdline -import Proto.API +import Proto.API.RouteGuide {------------------------------------------------------------------------------- Custom handler monad diff --git a/demo-server/Main.hs b/demo-server/Main.hs index 094d2ea3..4eced14d 100644 --- a/demo-server/Main.hs +++ b/demo-server/Main.hs @@ -19,7 +19,9 @@ import Demo.Server.Service.Greeter qualified as Greeter import Demo.Server.Service.Ping qualified as Ping import Demo.Server.Service.RouteGuide qualified as RouteGuide -import Proto.API +import Proto.API.Helloworld +import Proto.API.Ping +import Proto.API.RouteGuide {------------------------------------------------------------------------------- All services diff --git a/grapesy.cabal b/grapesy.cabal index 6c41cbc8..245af160 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -377,7 +377,9 @@ executable demo-client Paths_grapesy - Proto.API + Proto.API.Helloworld + Proto.API.Ping + Proto.API.RouteGuide Proto.Helloworld Proto.Helloworld_Fields Proto.RouteGuide @@ -420,7 +422,9 @@ executable demo-server Demo.Server.Service.Ping Demo.Server.Service.RouteGuide - Proto.API + Proto.API.Helloworld + Proto.API.Ping + Proto.API.RouteGuide Proto.Helloworld Proto.Helloworld_Fields Proto.RouteGuide diff --git a/proto/Proto/API.hs b/proto/Proto/API/Helloworld.hs similarity index 60% rename from proto/Proto/API.hs rename to proto/Proto/API/Helloworld.hs index 85b60055..394b8ea8 100644 --- a/proto/Proto/API.hs +++ b/proto/Proto/API/Helloworld.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -Wno-orphans #-} -module Proto.API ( +module Proto.API.Helloworld ( -- * Greeter SayHello , SayHelloStreamReply @@ -10,18 +10,8 @@ module Proto.API ( -- ** Metadata , SayHelloMetadata(..) - -- * RouteGuide - , GetFeature - , ListFeatures - , RecordRoute - , RouteChat - - -- * Ping - , Ping - -- * Re-exports , module Proto.Helloworld - , module Proto.RouteGuide ) where import Control.Monad.Catch @@ -29,11 +19,9 @@ import Data.ByteString qualified as Strict import GHC.TypeLits import Network.GRPC.Common -import Network.GRPC.Common.Binary import Network.GRPC.Common.Protobuf import Proto.Helloworld -import Proto.RouteGuide {------------------------------------------------------------------------------- Greeter @@ -73,27 +61,4 @@ instance ParseMetadata SayHelloMetadata where [md] | customMetadataName md == "initial-md" -> return $ SayHelloMetadata $ Just (customMetadataValue md) _otherwise -> - throwM $ UnexpectedMetadata headers - -{------------------------------------------------------------------------------- - RouteGuide --------------------------------------------------------------------------------} - -type GetFeature = Protobuf RouteGuide "getFeature" -type ListFeatures = Protobuf RouteGuide "listFeatures" -type RecordRoute = Protobuf RouteGuide "recordRoute" -type RouteChat = Protobuf RouteGuide "routeChat" - -type instance RequestMetadata (Protobuf RouteGuide meth) = NoMetadata -type instance ResponseInitialMetadata (Protobuf RouteGuide meth) = NoMetadata -type instance ResponseTrailingMetadata (Protobuf RouteGuide meth) = NoMetadata - -{------------------------------------------------------------------------------- - Ping --------------------------------------------------------------------------------} - -type Ping = RawRpc "Ping" "ping" - -type instance RequestMetadata (RawRpc "Ping" meth) = NoMetadata -type instance ResponseInitialMetadata (RawRpc "Ping" meth) = NoMetadata -type instance ResponseTrailingMetadata (RawRpc "Ping" meth) = NoMetadata + throwM $ UnexpectedMetadata headers \ No newline at end of file diff --git a/proto/Proto/API/Ping.hs b/proto/Proto/API/Ping.hs new file mode 100644 index 00000000..de33142e --- /dev/null +++ b/proto/Proto/API/Ping.hs @@ -0,0 +1,19 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -Wno-orphans #-} + +module Proto.API.Ping ( + Ping + ) where + +import Network.GRPC.Common +import Network.GRPC.Common.Binary + +{------------------------------------------------------------------------------- + Ping +-------------------------------------------------------------------------------} + +type Ping = RawRpc "Ping" "ping" + +type instance RequestMetadata (RawRpc "Ping" meth) = NoMetadata +type instance ResponseInitialMetadata (RawRpc "Ping" meth) = NoMetadata +type instance ResponseTrailingMetadata (RawRpc "Ping" meth) = NoMetadata diff --git a/proto/Proto/API/RouteGuide.hs b/proto/Proto/API/RouteGuide.hs new file mode 100644 index 00000000..bed16497 --- /dev/null +++ b/proto/Proto/API/RouteGuide.hs @@ -0,0 +1,30 @@ +{-# OPTIONS_GHC -Wno-orphans #-} + +module Proto.API.RouteGuide ( + -- * RouteGuide + GetFeature + , ListFeatures + , RecordRoute + , RouteChat + + -- * Re-exports + , module Proto.RouteGuide + ) where + +import Network.GRPC.Common +import Network.GRPC.Common.Protobuf + +import Proto.RouteGuide + +{------------------------------------------------------------------------------- + RouteGuide +-------------------------------------------------------------------------------} + +type GetFeature = Protobuf RouteGuide "getFeature" +type ListFeatures = Protobuf RouteGuide "listFeatures" +type RecordRoute = Protobuf RouteGuide "recordRoute" +type RouteChat = Protobuf RouteGuide "routeChat" + +type instance RequestMetadata (Protobuf RouteGuide meth) = NoMetadata +type instance ResponseInitialMetadata (Protobuf RouteGuide meth) = NoMetadata +type instance ResponseTrailingMetadata (Protobuf RouteGuide meth) = NoMetadata From e64dbf7ffc8866db27e2a3d6cf537dc3e20d78f6 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 11:28:38 +0200 Subject: [PATCH 4/8] Switch demo client/server over to Protobuf Ping We were using raw ping previously (we introduced the Protobuf ping only when writing the interop tests); by switching over, we make everything a bit more uniform. --- .../Demo/Client/API/StreamType/IO/Ping.hs | 7 +++---- demo-client/Demo/Client/Cmdline.hs | 15 ++++++++++++--- demo-server/Demo/Server/Service/Ping.hs | 9 +++++---- grapesy.cabal | 4 ++++ proto/Proto/API/Ping.hs | 17 +++++++++++------ 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs index 15f8b2a5..b1ffe930 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs @@ -1,13 +1,12 @@ module Demo.Client.API.StreamType.IO.Ping (ping) where -import Data.ByteString.Lazy.Char8 qualified as Lazy - import Network.GRPC.Client import Network.GRPC.Client.StreamType.IO +import Network.GRPC.Common.Protobuf import Proto.API.Ping -ping :: Connection -> Lazy.ByteString -> IO () +ping :: Connection -> Proto PingMessage -> IO () ping conn msg = do pong <- nonStreaming conn (rpc @Ping) msg - Lazy.putStrLn pong + print pong diff --git a/demo-client/Demo/Client/Cmdline.hs b/demo-client/Demo/Client/Cmdline.hs index 427a024b..74ab23fb 100644 --- a/demo-client/Demo/Client/Cmdline.hs +++ b/demo-client/Demo/Client/Cmdline.hs @@ -16,7 +16,6 @@ module Demo.Client.Cmdline ( import Prelude -import Data.ByteString.Lazy qualified as Lazy (ByteString) import Data.Foldable (asum) import Data.Int import Data.Kind @@ -39,6 +38,7 @@ import Demo.Client.Util.DelayOr (DelayOr(..)) import Proto.API.Helloworld import Proto.API.Ping import Proto.API.RouteGuide +import Text.Read (readMaybe) {------------------------------------------------------------------------------- Definition @@ -78,7 +78,7 @@ data SMethod :: Type -> Type where SRecordRoute :: [DelayOr (Proto Point)] -> SMethod RecordRoute SRouteChat :: [DelayOr (Proto RouteNote)] -> SMethod RouteChat - SPing :: Lazy.ByteString -> SMethod Ping + SPing :: Proto PingMessage -> SMethod Ping deriving stock instance Show (SMethod rpc) @@ -252,7 +252,7 @@ parseSomeMethod = Opt.subparser $ mconcat [ Opt.many (parseDelayOr $ parseRouteNote) , sub "ping" "Ping.ping" $ SomeMethod . SPing <$> - Opt.argument Opt.str (Opt.metavar "MSG") + Opt.argument parsePingMessage (Opt.metavar "NUM") ] {------------------------------------------------------------------------------- @@ -327,6 +327,15 @@ parseRouteNote = & #location .~ location & #message .~ message +parsePingMessage :: Opt.ReadM (Proto PingMessage) +parsePingMessage = Opt.str >>= aux + where + aux :: String -> Opt.ReadM (Proto PingMessage) + aux str = + case readMaybe str of + Nothing -> fail $ "Could not parse ping ID " ++ show str + Just pid -> return $ defMessage & #id .~ pid + {------------------------------------------------------------------------------- Internal auxiliary -------------------------------------------------------------------------------} diff --git a/demo-server/Demo/Server/Service/Ping.hs b/demo-server/Demo/Server/Service/Ping.hs index cda77a78..212c99e2 100644 --- a/demo-server/Demo/Server/Service/Ping.hs +++ b/demo-server/Demo/Server/Service/Ping.hs @@ -1,7 +1,8 @@ -module Demo.Server.Service.Ping (handlers) where +{-# LANGUAGE OverloadedLabels #-} -import Data.ByteString.Lazy qualified as Lazy (ByteString) +module Demo.Server.Service.Ping (handlers) where +import Network.GRPC.Common.Protobuf import Network.GRPC.Server.StreamType import Proto.API.Ping @@ -11,6 +12,6 @@ handlers = Method (mkNonStreaming handlePing) $ NoMoreMethods -handlePing :: Lazy.ByteString -> IO Lazy.ByteString -handlePing = return +handlePing :: Proto PingMessage -> IO (Proto PongMessage) +handlePing ping = return $ defMessage & #id .~ (ping ^. #id) diff --git a/grapesy.cabal b/grapesy.cabal index 245af160..62a60882 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -382,6 +382,8 @@ executable demo-client Proto.API.RouteGuide Proto.Helloworld Proto.Helloworld_Fields + Proto.Ping + Proto.Ping_Fields Proto.RouteGuide Proto.RouteGuide_Fields autogen-modules: @@ -427,6 +429,8 @@ executable demo-server Proto.API.RouteGuide Proto.Helloworld Proto.Helloworld_Fields + Proto.Ping + Proto.Ping_Fields Proto.RouteGuide Proto.RouteGuide_Fields diff --git a/proto/Proto/API/Ping.hs b/proto/Proto/API/Ping.hs index de33142e..ff06e955 100644 --- a/proto/Proto/API/Ping.hs +++ b/proto/Proto/API/Ping.hs @@ -3,17 +3,22 @@ module Proto.API.Ping ( Ping - ) where + + -- * Re-exports + , module Proto.Ping +) where import Network.GRPC.Common -import Network.GRPC.Common.Binary +import Network.GRPC.Common.Protobuf + +import Proto.Ping {------------------------------------------------------------------------------- Ping -------------------------------------------------------------------------------} -type Ping = RawRpc "Ping" "ping" +type Ping = Protobuf PingService "ping" -type instance RequestMetadata (RawRpc "Ping" meth) = NoMetadata -type instance ResponseInitialMetadata (RawRpc "Ping" meth) = NoMetadata -type instance ResponseTrailingMetadata (RawRpc "Ping" meth) = NoMetadata +type instance RequestMetadata (Protobuf PingService meth) = NoMetadata +type instance ResponseInitialMetadata (Protobuf PingService meth) = NoMetadata +type instance ResponseTrailingMetadata (Protobuf PingService meth) = NoMetadata From d087daf8da60d23c6e87d2a2f68d7aeaaf068856 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 11:40:13 +0200 Subject: [PATCH 5/8] Use `Proto.API.Ping` in interop tests --- grapesy.cabal | 3 ++- interop/Interop/API.hs | 16 ---------------- interop/Interop/Client/Common.hs | 1 + interop/Interop/Client/Ping.hs | 5 ++--- .../Client/TestCase/CancelAfterFirstResponse.hs | 1 + .../Client/TestCase/ClientCompressedStreaming.hs | 1 + .../Interop/Client/TestCase/ClientStreaming.hs | 1 + .../Interop/Client/TestCase/CustomMetadata.hs | 1 + interop/Interop/Client/TestCase/EmptyUnary.hs | 1 + interop/Interop/Client/TestCase/LargeUnary.hs | 1 + interop/Interop/Client/TestCase/PingPong.hs | 1 + .../Client/TestCase/ServerCompressedUnary.hs | 1 + .../Client/TestCase/SpecialStatusMessage.hs | 1 + .../Client/TestCase/StatusCodeAndMessage.hs | 1 + .../Client/TestCase/TimeoutOnSleepingServer.hs | 1 + .../Client/TestCase/UnimplementedMethod.hs | 1 + interop/Interop/Server.hs | 2 ++ interop/Interop/Server/Common.hs | 1 + interop/Interop/Server/TestService/EmptyCall.hs | 2 ++ .../Interop/Server/TestService/FullDuplexCall.hs | 1 + .../Server/TestService/StreamingInputCall.hs | 1 + .../Server/TestService/StreamingOutputCall.hs | 1 + interop/Interop/Server/TestService/UnaryCall.hs | 1 + interop/Interop/Util/Messages.hs | 2 ++ 24 files changed, 28 insertions(+), 20 deletions(-) diff --git a/grapesy.cabal b/grapesy.cabal index 62a60882..37c40525 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -534,9 +534,10 @@ test-suite grapesy-interop Paths_grapesy - Proto.Ping + Proto.API.Ping Proto.Empty Proto.Messages + Proto.Ping Proto.Test autogen-modules: Paths_grapesy diff --git a/interop/Interop/API.hs b/interop/Interop/API.hs index 61d89a87..6b4cadbf 100644 --- a/interop/Interop/API.hs +++ b/interop/Interop/API.hs @@ -20,14 +20,9 @@ module Interop.API ( -- * UnimplementedService , UnimplementedServiceCall - -- * PingService - , Ping - -- * Re-exports - , module Network.GRPC.Common.Protobuf , module Proto.Empty , module Proto.Messages - , module Proto.Ping , module Proto.Test ) where @@ -40,7 +35,6 @@ import Network.GRPC.Common.Protobuf import Proto.Empty import Proto.Messages -import Proto.Ping import Proto.Test {------------------------------------------------------------------------------- @@ -183,13 +177,3 @@ type UnimplementedServiceCall = Protobuf UnimplementedService "unimplementedCall type instance RequestMetadata (Protobuf UnimplementedService meth) = NoMetadata type instance ResponseInitialMetadata (Protobuf UnimplementedService meth) = NoMetadata type instance ResponseTrailingMetadata (Protobuf UnimplementedService meth) = NoMetadata - -{------------------------------------------------------------------------------- - Ping service --------------------------------------------------------------------------------} - -type Ping = Protobuf PingService "ping" - -type instance RequestMetadata (Protobuf PingService meth) = NoMetadata -type instance ResponseInitialMetadata (Protobuf PingService meth) = NoMetadata -type instance ResponseTrailingMetadata (Protobuf PingService meth) = NoMetadata diff --git a/interop/Interop/Client/Common.hs b/interop/Interop/Client/Common.hs index 3e8da05c..1831372b 100644 --- a/interop/Interop/Client/Common.hs +++ b/interop/Interop/Client/Common.hs @@ -19,6 +19,7 @@ import Data.ByteString qualified as BS.Strict import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Compression qualified as Compr +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec import Interop.API diff --git a/interop/Interop/Client/Ping.hs b/interop/Interop/Client/Ping.hs index 3739f607..110cbdac 100644 --- a/interop/Interop/Client/Ping.hs +++ b/interop/Interop/Client/Ping.hs @@ -10,12 +10,11 @@ import Network.GRPC.Client.StreamType.IO import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Proto.Ping - -import Interop.API import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Ping + ping :: Cmdline -> IO () ping cmdline = withConnection def (testServer cmdline) $ \conn -> diff --git a/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs b/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs index 9bde7695..25f5cdfe 100644 --- a/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs +++ b/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs @@ -2,6 +2,7 @@ module Interop.Client.TestCase.CancelAfterFirstResponse (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Interop.API import Interop.Client.Connect diff --git a/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs b/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs index 2bbd9ed6..cd313106 100644 --- a/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs +++ b/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs @@ -2,6 +2,7 @@ module Interop.Client.TestCase.ClientCompressedStreaming (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec import Interop.API diff --git a/interop/Interop/Client/TestCase/ClientStreaming.hs b/interop/Interop/Client/TestCase/ClientStreaming.hs index 6c50cb2f..65dfe378 100644 --- a/interop/Interop/Client/TestCase/ClientStreaming.hs +++ b/interop/Interop/Client/TestCase/ClientStreaming.hs @@ -2,6 +2,7 @@ module Interop.Client.TestCase.ClientStreaming (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Interop.API import Interop.Client.Connect diff --git a/interop/Interop/Client/TestCase/CustomMetadata.hs b/interop/Interop/Client/TestCase/CustomMetadata.hs index 745ec7d3..b22e3b45 100644 --- a/interop/Interop/Client/TestCase/CustomMetadata.hs +++ b/interop/Interop/Client/TestCase/CustomMetadata.hs @@ -7,6 +7,7 @@ import Data.ByteString qualified as Strict (ByteString) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Interop.API import Interop.Client.Common diff --git a/interop/Interop/Client/TestCase/EmptyUnary.hs b/interop/Interop/Client/TestCase/EmptyUnary.hs index f430378e..01f72b6d 100644 --- a/interop/Interop/Client/TestCase/EmptyUnary.hs +++ b/interop/Interop/Client/TestCase/EmptyUnary.hs @@ -4,6 +4,7 @@ import Data.Proxy import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Spec diff --git a/interop/Interop/Client/TestCase/LargeUnary.hs b/interop/Interop/Client/TestCase/LargeUnary.hs index ca39dceb..a3fb50d8 100644 --- a/interop/Interop/Client/TestCase/LargeUnary.hs +++ b/interop/Interop/Client/TestCase/LargeUnary.hs @@ -3,6 +3,7 @@ module Interop.Client.TestCase.LargeUnary (runTest) where import Network.GRPC.Client import Network.GRPC.Client.StreamType.IO import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Interop.API import Interop.Client.Common diff --git a/interop/Interop/Client/TestCase/PingPong.hs b/interop/Interop/Client/TestCase/PingPong.hs index 28a709f4..27d8340e 100644 --- a/interop/Interop/Client/TestCase/PingPong.hs +++ b/interop/Interop/Client/TestCase/PingPong.hs @@ -4,6 +4,7 @@ import Control.Monad import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Interop.API import Interop.Client.Common diff --git a/interop/Interop/Client/TestCase/ServerCompressedUnary.hs b/interop/Interop/Client/TestCase/ServerCompressedUnary.hs index 881f10de..e211f606 100644 --- a/interop/Interop/Client/TestCase/ServerCompressedUnary.hs +++ b/interop/Interop/Client/TestCase/ServerCompressedUnary.hs @@ -4,6 +4,7 @@ import Data.Maybe (isJust) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Spec diff --git a/interop/Interop/Client/TestCase/SpecialStatusMessage.hs b/interop/Interop/Client/TestCase/SpecialStatusMessage.hs index 964a4806..fffd1e74 100644 --- a/interop/Interop/Client/TestCase/SpecialStatusMessage.hs +++ b/interop/Interop/Client/TestCase/SpecialStatusMessage.hs @@ -6,6 +6,7 @@ import Data.Text (Text) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec import Interop.API diff --git a/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs b/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs index ee91afa8..0c7e635a 100644 --- a/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs +++ b/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs @@ -6,6 +6,7 @@ import Data.Text (Text) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec import Interop.API diff --git a/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs b/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs index 69944a83..84b29053 100644 --- a/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs +++ b/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs @@ -2,6 +2,7 @@ module Interop.Client.TestCase.TimeoutOnSleepingServer (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Interop.API import Interop.Client.Common diff --git a/interop/Interop/Client/TestCase/UnimplementedMethod.hs b/interop/Interop/Client/TestCase/UnimplementedMethod.hs index 6ae6b700..e400f7a3 100644 --- a/interop/Interop/Client/TestCase/UnimplementedMethod.hs +++ b/interop/Interop/Client/TestCase/UnimplementedMethod.hs @@ -2,6 +2,7 @@ module Interop.Client.TestCase.UnimplementedMethod (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Client.StreamType.IO import Interop.API diff --git a/interop/Interop/Server.hs b/interop/Interop/Server.hs index 652655e7..36975f44 100644 --- a/interop/Interop/Server.hs +++ b/interop/Interop/Server.hs @@ -23,6 +23,8 @@ import Interop.Server.TestService.StreamingInputCall qualified as StreamingInpu import Interop.Server.TestService.StreamingOutputCall qualified as StreamingOutputCall import Interop.Server.TestService.UnaryCall qualified as UnaryCall +import Proto.API.Ping + {------------------------------------------------------------------------------- Handlers diff --git a/interop/Interop/Server/Common.hs b/interop/Interop/Server/Common.hs index c1bfda02..ebafa731 100644 --- a/interop/Interop/Server/Common.hs +++ b/interop/Interop/Server/Common.hs @@ -10,6 +10,7 @@ module Interop.Server.Common ( import Control.Exception import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec diff --git a/interop/Interop/Server/TestService/EmptyCall.hs b/interop/Interop/Server/TestService/EmptyCall.hs index 0c275ef0..f001c5a4 100644 --- a/interop/Interop/Server/TestService/EmptyCall.hs +++ b/interop/Interop/Server/TestService/EmptyCall.hs @@ -1,5 +1,7 @@ module Interop.Server.TestService.EmptyCall (handle) where +import Network.GRPC.Common.Protobuf + import Interop.API -- | Handle @TestService.EmptyCall@ diff --git a/interop/Interop/Server/TestService/FullDuplexCall.hs b/interop/Interop/Server/TestService/FullDuplexCall.hs index 8cc0ee09..e5dc6b2d 100644 --- a/interop/Interop/Server/TestService/FullDuplexCall.hs +++ b/interop/Interop/Server/TestService/FullDuplexCall.hs @@ -1,6 +1,7 @@ module Interop.Server.TestService.FullDuplexCall (handle) where import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Interop.API diff --git a/interop/Interop/Server/TestService/StreamingInputCall.hs b/interop/Interop/Server/TestService/StreamingInputCall.hs index ffcae8ea..6157d6d7 100644 --- a/interop/Interop/Server/TestService/StreamingInputCall.hs +++ b/interop/Interop/Server/TestService/StreamingInputCall.hs @@ -5,6 +5,7 @@ module Interop.Server.TestService.StreamingInputCall (handle) where import Data.ByteString qualified as BS.Strict import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec diff --git a/interop/Interop/Server/TestService/StreamingOutputCall.hs b/interop/Interop/Server/TestService/StreamingOutputCall.hs index 3d4e22ec..d19f0a63 100644 --- a/interop/Interop/Server/TestService/StreamingOutputCall.hs +++ b/interop/Interop/Server/TestService/StreamingOutputCall.hs @@ -7,6 +7,7 @@ import Control.Concurrent import Control.Monad import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec diff --git a/interop/Interop/Server/TestService/UnaryCall.hs b/interop/Interop/Server/TestService/UnaryCall.hs index 39602d2c..0825f201 100644 --- a/interop/Interop/Server/TestService/UnaryCall.hs +++ b/interop/Interop/Server/TestService/UnaryCall.hs @@ -3,6 +3,7 @@ module Interop.Server.TestService.UnaryCall (handle) where import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Server import Network.GRPC.Spec diff --git a/interop/Interop/Util/Messages.hs b/interop/Interop/Util/Messages.hs index f38152cc..5655f6dd 100644 --- a/interop/Interop/Util/Messages.hs +++ b/interop/Interop/Util/Messages.hs @@ -12,6 +12,8 @@ import Data.ByteString qualified as BS.Strict import Data.ByteString qualified as Strict (ByteString) import Data.ByteString.Char8 qualified as BS.Strict.Char8 +import Network.GRPC.Common.Protobuf + import Interop.API import Interop.Util.Exceptions From 69203ca41e3916757313c44b9459a974c7d49623 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 11:47:47 +0200 Subject: [PATCH 6/8] Move `Interop.API` to `Proto.API.Interop` This makes it available for use in the test suite. --- grapesy.cabal | 2 +- interop/Interop/Client/Common.hs | 3 ++- interop/Interop/Client/TestCase/CancelAfterBegin.hs | 3 ++- interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs | 3 ++- interop/Interop/Client/TestCase/ClientCompressedStreaming.hs | 3 ++- interop/Interop/Client/TestCase/ClientCompressedUnary.hs | 3 ++- interop/Interop/Client/TestCase/ClientStreaming.hs | 3 ++- interop/Interop/Client/TestCase/CustomMetadata.hs | 3 ++- interop/Interop/Client/TestCase/EmptyStream.hs | 3 ++- interop/Interop/Client/TestCase/EmptyUnary.hs | 3 ++- interop/Interop/Client/TestCase/LargeUnary.hs | 3 ++- interop/Interop/Client/TestCase/PingPong.hs | 3 ++- interop/Interop/Client/TestCase/ServerCompressedStreaming.hs | 5 +++-- interop/Interop/Client/TestCase/ServerCompressedUnary.hs | 3 ++- interop/Interop/Client/TestCase/ServerStreaming.hs | 3 ++- interop/Interop/Client/TestCase/SpecialStatusMessage.hs | 3 ++- interop/Interop/Client/TestCase/StatusCodeAndMessage.hs | 3 ++- interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs | 3 ++- interop/Interop/Client/TestCase/UnimplementedMethod.hs | 3 ++- interop/Interop/Client/TestCase/UnimplementedService.hs | 3 ++- interop/Interop/Server.hs | 2 +- interop/Interop/Server/Common.hs | 3 ++- interop/Interop/Server/TestService/EmptyCall.hs | 2 +- interop/Interop/Server/TestService/FullDuplexCall.hs | 3 ++- interop/Interop/Server/TestService/StreamingInputCall.hs | 3 ++- interop/Interop/Server/TestService/StreamingOutputCall.hs | 3 ++- interop/Interop/Server/TestService/UnaryCall.hs | 3 ++- interop/Interop/Util/Messages.hs | 3 ++- interop/Interop/API.hs => proto/Proto/API/Interop.hs | 2 +- 29 files changed, 55 insertions(+), 30 deletions(-) rename interop/Interop/API.hs => proto/Proto/API/Interop.hs (99%) diff --git a/grapesy.cabal b/grapesy.cabal index 37c40525..6619c746 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -495,7 +495,6 @@ test-suite grapesy-interop main-is: Main.hs other-modules: - Interop.API Interop.Client Interop.Client.Common Interop.Client.Connect @@ -534,6 +533,7 @@ test-suite grapesy-interop Paths_grapesy + Proto.API.Interop Proto.API.Ping Proto.Empty Proto.Messages diff --git a/interop/Interop/Client/Common.hs b/interop/Interop/Client/Common.hs index 1831372b..a6b4d856 100644 --- a/interop/Interop/Client/Common.hs +++ b/interop/Interop/Client/Common.hs @@ -22,10 +22,11 @@ import Network.GRPC.Common.Compression qualified as Compr import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Util.Exceptions import Interop.Util.Messages +import Proto.API.Interop + {------------------------------------------------------------------------------- Config -------------------------------------------------------------------------------} diff --git a/interop/Interop/Client/TestCase/CancelAfterBegin.hs b/interop/Interop/Client/TestCase/CancelAfterBegin.hs index ba14513c..f65fb76a 100644 --- a/interop/Interop/Client/TestCase/CancelAfterBegin.hs +++ b/interop/Interop/Client/TestCase/CancelAfterBegin.hs @@ -3,11 +3,12 @@ module Interop.Client.TestCase.CancelAfterBegin (runTest) where import Network.GRPC.Client import Network.GRPC.Common -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | -- -- This is not really testing anything about the server, but rather about how diff --git a/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs b/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs index 25f5cdfe..3c138391 100644 --- a/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs +++ b/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs @@ -4,12 +4,13 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions import Interop.Client.Common (mkStreamingOutputCallRequest) +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs b/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs index cd313106..fec43731 100644 --- a/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs +++ b/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs @@ -5,12 +5,13 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ClientCompressedUnary.hs b/interop/Interop/Client/TestCase/ClientCompressedUnary.hs index 92e10178..26b394bb 100644 --- a/interop/Interop/Client/TestCase/ClientCompressedUnary.hs +++ b/interop/Interop/Client/TestCase/ClientCompressedUnary.hs @@ -6,11 +6,12 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ClientStreaming.hs b/interop/Interop/Client/TestCase/ClientStreaming.hs index 65dfe378..64d536fe 100644 --- a/interop/Interop/Client/TestCase/ClientStreaming.hs +++ b/interop/Interop/Client/TestCase/ClientStreaming.hs @@ -4,12 +4,13 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions import Interop.Util.Messages +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/CustomMetadata.hs b/interop/Interop/Client/TestCase/CustomMetadata.hs index b22e3b45..a567298f 100644 --- a/interop/Interop/Client/TestCase/CustomMetadata.hs +++ b/interop/Interop/Client/TestCase/CustomMetadata.hs @@ -9,12 +9,13 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | -- -- For both UnaryCall and FullDuplexCall, the reference server (at least some) diff --git a/interop/Interop/Client/TestCase/EmptyStream.hs b/interop/Interop/Client/TestCase/EmptyStream.hs index a0135810..00a054b0 100644 --- a/interop/Interop/Client/TestCase/EmptyStream.hs +++ b/interop/Interop/Client/TestCase/EmptyStream.hs @@ -5,10 +5,11 @@ import Control.Monad import Network.GRPC.Client import Network.GRPC.Common -import Interop.API import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/EmptyUnary.hs b/interop/Interop/Client/TestCase/EmptyUnary.hs index 01f72b6d..724f48b1 100644 --- a/interop/Interop/Client/TestCase/EmptyUnary.hs +++ b/interop/Interop/Client/TestCase/EmptyUnary.hs @@ -8,11 +8,12 @@ import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Spec -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/LargeUnary.hs b/interop/Interop/Client/TestCase/LargeUnary.hs index a3fb50d8..19f149cb 100644 --- a/interop/Interop/Client/TestCase/LargeUnary.hs +++ b/interop/Interop/Client/TestCase/LargeUnary.hs @@ -5,11 +5,12 @@ import Network.GRPC.Client.StreamType.IO import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/PingPong.hs b/interop/Interop/Client/TestCase/PingPong.hs index 27d8340e..4a4ce766 100644 --- a/interop/Interop/Client/TestCase/PingPong.hs +++ b/interop/Interop/Client/TestCase/PingPong.hs @@ -6,11 +6,12 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs b/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs index 076f96d9..6e0f5512 100644 --- a/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs +++ b/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs @@ -4,13 +4,14 @@ import Data.Maybe (isJust) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions -import Network.GRPC.Spec + +import Proto.API.Interop -- | runTest :: Cmdline -> IO () diff --git a/interop/Interop/Client/TestCase/ServerCompressedUnary.hs b/interop/Interop/Client/TestCase/ServerCompressedUnary.hs index e211f606..0fee743e 100644 --- a/interop/Interop/Client/TestCase/ServerCompressedUnary.hs +++ b/interop/Interop/Client/TestCase/ServerCompressedUnary.hs @@ -8,13 +8,14 @@ import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions import Interop.Util.Messages +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ServerStreaming.hs b/interop/Interop/Client/TestCase/ServerStreaming.hs index 9b9d2b06..b37c6c3d 100644 --- a/interop/Interop/Client/TestCase/ServerStreaming.hs +++ b/interop/Interop/Client/TestCase/ServerStreaming.hs @@ -3,11 +3,12 @@ module Interop.Client.TestCase.ServerStreaming (runTest) where import Network.GRPC.Client import Network.GRPC.Common -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/SpecialStatusMessage.hs b/interop/Interop/Client/TestCase/SpecialStatusMessage.hs index fffd1e74..c9e03824 100644 --- a/interop/Interop/Client/TestCase/SpecialStatusMessage.hs +++ b/interop/Interop/Client/TestCase/SpecialStatusMessage.hs @@ -9,11 +9,12 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = do diff --git a/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs b/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs index 0c7e635a..ae9e05e3 100644 --- a/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs +++ b/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs @@ -9,11 +9,12 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = do diff --git a/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs b/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs index 84b29053..772a8cc6 100644 --- a/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs +++ b/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs @@ -4,12 +4,13 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/UnimplementedMethod.hs b/interop/Interop/Client/TestCase/UnimplementedMethod.hs index e400f7a3..bb413ef8 100644 --- a/interop/Interop/Client/TestCase/UnimplementedMethod.hs +++ b/interop/Interop/Client/TestCase/UnimplementedMethod.hs @@ -5,11 +5,12 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Client.StreamType.IO -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/UnimplementedService.hs b/interop/Interop/Client/TestCase/UnimplementedService.hs index 20354bda..437f9920 100644 --- a/interop/Interop/Client/TestCase/UnimplementedService.hs +++ b/interop/Interop/Client/TestCase/UnimplementedService.hs @@ -5,11 +5,12 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Client.StreamType.IO -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Server.hs b/interop/Interop/Server.hs index 36975f44..f1f5a805 100644 --- a/interop/Interop/Server.hs +++ b/interop/Interop/Server.hs @@ -13,7 +13,6 @@ import Network.GRPC.Server.Protobuf import Network.GRPC.Server.Run import Network.GRPC.Server.StreamType -import Interop.API import Interop.Cmdline import Interop.Server.PingService.Ping qualified as Ping @@ -23,6 +22,7 @@ import Interop.Server.TestService.StreamingInputCall qualified as StreamingInpu import Interop.Server.TestService.StreamingOutputCall qualified as StreamingOutputCall import Interop.Server.TestService.UnaryCall qualified as UnaryCall +import Proto.API.Interop import Proto.API.Ping {------------------------------------------------------------------------------- diff --git a/interop/Interop/Server/Common.hs b/interop/Interop/Server/Common.hs index ebafa731..aa89027e 100644 --- a/interop/Interop/Server/Common.hs +++ b/interop/Interop/Server/Common.hs @@ -14,9 +14,10 @@ import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Util.Exceptions +import Proto.API.Interop + {------------------------------------------------------------------------------- Dealing with the test-suite's message types -------------------------------------------------------------------------------} diff --git a/interop/Interop/Server/TestService/EmptyCall.hs b/interop/Interop/Server/TestService/EmptyCall.hs index f001c5a4..7b531a74 100644 --- a/interop/Interop/Server/TestService/EmptyCall.hs +++ b/interop/Interop/Server/TestService/EmptyCall.hs @@ -2,7 +2,7 @@ module Interop.Server.TestService.EmptyCall (handle) where import Network.GRPC.Common.Protobuf -import Interop.API +import Proto.API.Interop -- | Handle @TestService.EmptyCall@ -- diff --git a/interop/Interop/Server/TestService/FullDuplexCall.hs b/interop/Interop/Server/TestService/FullDuplexCall.hs index e5dc6b2d..0df59c78 100644 --- a/interop/Interop/Server/TestService/FullDuplexCall.hs +++ b/interop/Interop/Server/TestService/FullDuplexCall.hs @@ -4,10 +4,11 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Server -import Interop.API import Interop.Server.Common import Interop.Server.TestService.StreamingOutputCall qualified as StreamingOutputCall +import Proto.API.Interop + -- | Handle @TestService.FullDuplexCall@ -- -- diff --git a/interop/Interop/Server/TestService/StreamingInputCall.hs b/interop/Interop/Server/TestService/StreamingInputCall.hs index 6157d6d7..d501774a 100644 --- a/interop/Interop/Server/TestService/StreamingInputCall.hs +++ b/interop/Interop/Server/TestService/StreamingInputCall.hs @@ -9,9 +9,10 @@ import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Server.Common +import Proto.API.Interop + -- | Handle @TestService.StreamingInputCall@ -- -- diff --git a/interop/Interop/Server/TestService/StreamingOutputCall.hs b/interop/Interop/Server/TestService/StreamingOutputCall.hs index d19f0a63..b468d9f2 100644 --- a/interop/Interop/Server/TestService/StreamingOutputCall.hs +++ b/interop/Interop/Server/TestService/StreamingOutputCall.hs @@ -11,9 +11,10 @@ import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Util.Messages +import Proto.API.Interop + -- | Handle @TestService.StreamingOutputCall@ -- -- diff --git a/interop/Interop/Server/TestService/UnaryCall.hs b/interop/Interop/Server/TestService/UnaryCall.hs index 0825f201..4e7aff1e 100644 --- a/interop/Interop/Server/TestService/UnaryCall.hs +++ b/interop/Interop/Server/TestService/UnaryCall.hs @@ -8,10 +8,11 @@ import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Server.Common import Interop.Util.Messages +import Proto.API.Interop + -- | Handle @TestService.UnaryCall@ -- -- This is not implemented using the Protobuf communication patterns because diff --git a/interop/Interop/Util/Messages.hs b/interop/Interop/Util/Messages.hs index 5655f6dd..f410e1a3 100644 --- a/interop/Interop/Util/Messages.hs +++ b/interop/Interop/Util/Messages.hs @@ -14,9 +14,10 @@ import Data.ByteString.Char8 qualified as BS.Strict.Char8 import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Util.Exceptions +import Proto.API.Interop + {------------------------------------------------------------------------------- BoolValue -------------------------------------------------------------------------------} diff --git a/interop/Interop/API.hs b/proto/Proto/API/Interop.hs similarity index 99% rename from interop/Interop/API.hs rename to proto/Proto/API/Interop.hs index 6b4cadbf..f4e30d81 100644 --- a/interop/Interop/API.hs +++ b/proto/Proto/API/Interop.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -Wno-orphans #-} -module Interop.API ( +module Proto.API.Interop ( -- * TestService -- ** Endpoints From 8bffc45b47d23c3f9652b47f29cac4460e50dbcc Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 12:01:57 +0200 Subject: [PATCH 7/8] Use `Proto.API.Interop` in test suite --- grapesy.cabal | 3 +++ test-grapesy/Test/Sanity/Interop.hs | 39 +++++++++++++---------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/grapesy.cabal b/grapesy.cabal index 6619c746..40a58b64 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -316,8 +316,11 @@ test-suite test-grapesy Paths_grapesy + Proto.API.Interop + Proto.API.Ping Proto.Empty Proto.Messages + Proto.Ping Proto.Test autogen-modules: Paths_grapesy diff --git a/test-grapesy/Test/Sanity/Interop.hs b/test-grapesy/Test/Sanity/Interop.hs index 4b0772bc..c94fe9d2 100644 --- a/test-grapesy/Test/Sanity/Interop.hs +++ b/test-grapesy/Test/Sanity/Interop.hs @@ -15,7 +15,7 @@ import Test.Tasty.HUnit import Network.GRPC.Client qualified as Client import Network.GRPC.Client.Binary qualified as Client.Binary -import Network.GRPC.Client.StreamType.IO.Binary qualified as Client.Binary +import Network.GRPC.Client.StreamType.IO qualified as Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem @@ -24,8 +24,8 @@ import Network.GRPC.Server.Binary qualified as Server.Binary import Network.GRPC.Server.StreamType qualified as Server import Network.GRPC.Spec -import Proto.Messages -import Proto.Test +import Proto.API.Interop +import Proto.API.Ping import Test.Driver.ClientServer @@ -53,28 +53,28 @@ tests = testGroup "Test.Sanity.Interop" [ even if the first failed with a gRPC exception -------------------------------------------------------------------------------} -type Ping = RawRpc "test" "ping" - test_callAfterException :: IO () test_callAfterException = testClientServer $ ClientServerTest { config = def , client = simpleTestClient $ \conn -> do - resp1 <- ping conn 0 + resp1 <- ping conn $ defMessage & #id .~ 0 case resp1 of Left _ -> return () Right _ -> assertFailure "Expected gRPC exception" - resp2 <- ping conn 1 + resp2 <- ping conn $ defMessage & #id .~ 1 case resp2 of Left _ -> assertFailure "Expected pong" - Right i -> assertEqual "pong" i 1 + Right i -> assertEqual "pong" i (defMessage & #id .~ 1) , server = [ Server.someRpcHandler $ Server.mkRpcHandler @Ping $ \call -> do - i :: Word <- Server.Binary.recvFinalInput call - if i > 0 then - Server.Binary.sendFinalOutput call (i, NoMetadata) + pingMsg <- Server.recvFinalInput call + if pingMsg ^. #id > 0 then do + let pongMsg :: Proto PongMessage + pongMsg = defMessage & #id .~ (pingMsg ^. #id) + Server.sendFinalOutput call (pongMsg, NoMetadata) else Server.sendGrpcException call $ GrpcException { grpcError = GrpcInvalidArgument @@ -84,8 +84,11 @@ test_callAfterException = ] } where - ping :: Client.Connection -> Word -> IO (Either SomeException Word) - ping conn = try . Client.Binary.nonStreaming conn (Client.rpc @Ping) + ping :: + Client.Connection + -> Proto PingMessage + -> IO (Either SomeException (Proto PongMessage)) + ping conn = try . Client.nonStreaming conn (Client.rpc @Ping) {------------------------------------------------------------------------------- @empty_unary@ @@ -93,8 +96,6 @@ test_callAfterException = -------------------------------------------------------------------------------} -type EmptyCall = Protobuf TestService "emptyCall" - -- | Test that the empty message has an empty encoding -- -- This test fails if we unconditionally compress (the /compressed/ form of the @@ -133,8 +134,6 @@ test_emptyUnary = -------------------------------------------------------------------------------} -type StreamingOutputCall = Protobuf TestService "streamingOutputCall" - -- | Test that we can enable and disable compression per message test_serverCompressedStreaming :: IO () test_serverCompressedStreaming = @@ -188,7 +187,7 @@ test_serverCompressedStreaming = Server.sendOutputWithEnvelope call $ StreamElem (envelope, response) -- No further output - Server.sendTrailers call NoMetadata + Server.sendTrailers call def verifyOutputs :: ( Maybe (InboundEnvelope, Proto StreamingOutputCallResponse) @@ -278,10 +277,6 @@ test_cancellation_server = Internal: we don't care about metadata in these tests -------------------------------------------------------------------------------} -type instance RequestMetadata (Protobuf TestService meth) = NoMetadata -type instance ResponseInitialMetadata (Protobuf TestService meth) = NoMetadata -type instance ResponseTrailingMetadata (Protobuf TestService meth) = NoMetadata - type instance RequestMetadata (RawRpc "test" meth) = NoMetadata type instance ResponseInitialMetadata (RawRpc "test" meth) = NoMetadata type instance ResponseTrailingMetadata (RawRpc "test" meth) = NoMetadata From 7029f1220f30c2858a17210fcf3eadea09673cb0 Mon Sep 17 00:00:00 2001 From: Edsko de Vries Date: Thu, 18 Jul 2024 12:03:02 +0200 Subject: [PATCH 8/8] Remove unnecessary _Fields modules --- grapesy.cabal | 7 ------- 1 file changed, 7 deletions(-) diff --git a/grapesy.cabal b/grapesy.cabal index 40a58b64..6a11227b 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -177,7 +177,6 @@ library Paths_grapesy Proto.OrcaLoadReport - Proto.OrcaLoadReport_Fields Control.Monad.XIO autogen-modules: @@ -384,11 +383,8 @@ executable demo-client Proto.API.Ping Proto.API.RouteGuide Proto.Helloworld - Proto.Helloworld_Fields Proto.Ping - Proto.Ping_Fields Proto.RouteGuide - Proto.RouteGuide_Fields autogen-modules: Paths_grapesy build-depends: @@ -431,11 +427,8 @@ executable demo-server Proto.API.Ping Proto.API.RouteGuide Proto.Helloworld - Proto.Helloworld_Fields Proto.Ping - Proto.Ping_Fields Proto.RouteGuide - Proto.RouteGuide_Fields Paths_grapesy autogen-modules: