2022-04-01 04:20:23 +03:00
|
|
|
--
|
|
|
|
module Hasura.Backends.DataWrapper.API
|
|
|
|
( module V0,
|
|
|
|
Api,
|
|
|
|
SchemaApi,
|
|
|
|
QueryApi,
|
|
|
|
openApiSchema,
|
2022-04-10 07:47:15 +03:00
|
|
|
Routes (..),
|
|
|
|
apiClient,
|
2022-04-01 04:20:23 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Data (Proxy (..))
|
|
|
|
import Data.OpenApi (OpenApi)
|
|
|
|
import Hasura.Backends.DataWrapper.API.V0.API as V0
|
|
|
|
import Servant.API
|
|
|
|
import Servant.API.Generic
|
2022-04-10 07:47:15 +03:00
|
|
|
import Servant.Client (Client, ClientM, client)
|
2022-04-01 04:20:23 +03:00
|
|
|
import Servant.OpenApi
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Servant Routes
|
|
|
|
|
|
|
|
type SchemaApi =
|
|
|
|
"schema"
|
|
|
|
:> Get '[JSON] V0.SchemaResponse
|
|
|
|
|
|
|
|
type QueryApi =
|
|
|
|
"query"
|
|
|
|
:> ReqBody '[JSON] V0.Query
|
|
|
|
:> Post '[JSON] V0.QueryResponse
|
|
|
|
|
|
|
|
data Routes mode = Routes
|
|
|
|
{ -- | 'GET /schema'
|
|
|
|
_schema :: mode :- SchemaApi,
|
|
|
|
-- | 'POST /query'
|
|
|
|
_query :: mode :- QueryApi
|
|
|
|
}
|
|
|
|
deriving stock (Generic)
|
|
|
|
|
|
|
|
-- | servant-openapi3 does not (yet) support NamedRoutes so we need to compose the
|
|
|
|
-- API the old-fashioned way using :<|> for use by @toOpenApi@
|
|
|
|
type Api = SchemaApi :<|> QueryApi
|
|
|
|
|
|
|
|
-- | Provide an OpenApi 3.0 schema for the API
|
|
|
|
openApiSchema :: OpenApi
|
|
|
|
openApiSchema = toOpenApi (Proxy :: Proxy Api)
|
2022-04-10 07:47:15 +03:00
|
|
|
|
|
|
|
apiClient :: Client ClientM (NamedRoutes Routes)
|
|
|
|
apiClient =
|
|
|
|
client (Proxy @(NamedRoutes Routes))
|