graphql-engine/server/src-dc-api/Hasura/Backends/DataConnector/Agent/Server.hs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.6 KiB
Haskell
Raw Normal View History

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)