mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
b4f89569c8
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4467 GitOrigin-RevId: 5e81d8581197c90ad2de9106e724c63d7592ae72
57 lines
1.6 KiB
Haskell
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)
|