graphql-engine/server/src-dc-api/Hasura/Backends/DataConnector/Agent/Server.hs
Solomon b4f89569c8 GDC: Integration Tests and Servant Agent
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4467
GitOrigin-RevId: 5e81d8581197c90ad2de9106e724c63d7592ae72
2022-05-11 06:15:27 +00:00

57 lines
1.6 KiB
Haskell

module Hasura.Backends.DataConnector.Agent.Server
( dcReferenceServer,
dcMockableServer,
withDcServer,
runDcServer,
)
where
--------------------------------------------------------------------------------
import Control.Concurrent qualified as C
import Control.Exception (bracket)
import Control.Monad.Except (liftIO)
import Data.OpenApi qualified as OpenApi
import Data.Proxy
import Hasura.Backends.DataConnector.API qualified as API
import Hasura.Backends.DataConnector.Agent.Data
import Hasura.Backends.DataConnector.Agent.Query
import Hasura.Backends.DataConnector.Agent.Schema
import Network.Wai.Handler.Warp qualified as Warp
import Servant
import Prelude
--------------------------------------------------------------------------------
configHandler :: Handler API.ConfigSchemaResponse
configHandler =
pure $
API.ConfigSchemaResponse
{ _csrConfigSchema =
mempty
{ OpenApi._schemaType = Just OpenApi.OpenApiObject,
OpenApi._schemaNullable = Just False
},
_csrOtherSchemas = mempty
}
dcReferenceServer :: Server API.Api
dcReferenceServer = configHandler :<|> schemaHandler :<|> queryHandler staticData
-- TODO(SOLOMON):
dcMockableServer :: Server API.Api
dcMockableServer = undefined
runDcServer :: IO ()
runDcServer =
let app = serve (Proxy :: Proxy API.Api) dcReferenceServer
in Warp.run 8100 app
withDcServer :: Server API.QueryApi -> IO () -> IO ()
withDcServer server action =
let app = serve (Proxy :: Proxy API.QueryApi) server
in bracket
(liftIO $ C.forkIO $ Warp.run 8100 app)
C.killThread
(const action)