2022-04-01 04:20:23 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.API.V0.Schema
|
2022-04-01 04:20:23 +03:00
|
|
|
( SchemaResponse (..),
|
2022-04-08 09:48:37 +03:00
|
|
|
QueryResponse (..),
|
2022-04-01 04:20:23 +03:00
|
|
|
Capabilities (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Autodocodec
|
|
|
|
import Control.DeepSeq (NFData)
|
2022-04-08 09:48:37 +03:00
|
|
|
import Data.Aeson (FromJSON, Object, ToJSON)
|
2022-04-01 04:20:23 +03:00
|
|
|
import Data.Data (Data)
|
|
|
|
import Data.Hashable (Hashable)
|
|
|
|
import Data.OpenApi (ToSchema)
|
|
|
|
import GHC.Generics (Generic)
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0.Table qualified as API.V0
|
2022-04-01 04:20:23 +03:00
|
|
|
import Prelude
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Schema Response
|
|
|
|
|
|
|
|
-- | The Schema Response provides the schemas for tracked tables and
|
|
|
|
-- 'Capabilities' supported by the service.
|
|
|
|
data SchemaResponse = SchemaResponse
|
|
|
|
{ srCapabilities :: Capabilities,
|
|
|
|
srTables :: [API.V0.TableInfo]
|
|
|
|
}
|
|
|
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
|
|
|
deriving anyclass (NFData, Hashable)
|
|
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec SchemaResponse
|
|
|
|
|
|
|
|
instance HasCodec SchemaResponse where
|
|
|
|
codec =
|
|
|
|
object "SchemaResponse" $
|
|
|
|
SchemaResponse
|
|
|
|
<$> requiredField "capabilities" "Capabilities of the agent" .= srCapabilities
|
|
|
|
<*> requiredField "tables" "Available tables" .= srTables
|
|
|
|
|
|
|
|
-- | The 'Capabilities' describes the _capabilities_ of the
|
|
|
|
-- service. Specifically, the service is capable of serving queries
|
|
|
|
-- which involve relationships.
|
|
|
|
data Capabilities = Capabilities
|
|
|
|
{ dcRelationships :: Bool
|
|
|
|
}
|
|
|
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
|
|
|
deriving anyclass (NFData, Hashable)
|
|
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec Capabilities
|
|
|
|
|
|
|
|
instance HasCodec Capabilities where
|
|
|
|
codec =
|
|
|
|
object "Capabilities" $
|
|
|
|
Capabilities <$> requiredField "relationships" "Does the agent support relationships?" .= dcRelationships
|
2022-04-08 09:48:37 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Query Response
|
|
|
|
|
|
|
|
-- | The resolved query response provided by the 'POST /query'
|
|
|
|
-- endpoint encoded as 'J.Value'.
|
|
|
|
newtype QueryResponse = QueryResponse {getQueryResponse :: [Object]}
|
|
|
|
deriving newtype (Eq, Ord, Show, NFData)
|
|
|
|
deriving (ToJSON, FromJSON, ToSchema) via Autodocodec [Object]
|