mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
45 lines
1.0 KiB
Haskell
45 lines
1.0 KiB
Haskell
|
--
|
||
|
module Hasura.Backends.DataWrapper.API
|
||
|
( module V0,
|
||
|
Api,
|
||
|
SchemaApi,
|
||
|
QueryApi,
|
||
|
openApiSchema,
|
||
|
)
|
||
|
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
|
||
|
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)
|