mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-22 06:51:32 +03:00
b9fb7d8720
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4926 GitOrigin-RevId: 2b6e5052f56a765e0b9a19345fcc4688d7e4700f
56 lines
1.8 KiB
Haskell
56 lines
1.8 KiB
Haskell
{-# LANGUAGE DeriveAnyClass #-}
|
|
|
|
--
|
|
module Hasura.Backends.DataConnector.API.V0.Table
|
|
( TableInfo (..),
|
|
TableName (..),
|
|
)
|
|
where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Autodocodec
|
|
import Autodocodec.OpenAPI ()
|
|
import Control.DeepSeq (NFData)
|
|
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
|
|
import Data.Data (Data)
|
|
import Data.Hashable (Hashable)
|
|
import Data.OpenApi (ToSchema)
|
|
import Data.Text (Text)
|
|
import GHC.Generics (Generic)
|
|
import Hasura.Backends.DataConnector.API.V0.Column qualified as API.V0
|
|
import Prelude
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
newtype TableName = TableName {unTableName :: Text}
|
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
|
deriving anyclass (NFData, Hashable)
|
|
deriving newtype (FromJSONKey, ToJSONKey)
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec TableName
|
|
|
|
instance HasCodec TableName where
|
|
codec = dimapCodec TableName unTableName textCodec
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Table schema data from the 'SchemaResponse'.
|
|
data TableInfo = TableInfo
|
|
{ dtiName :: TableName,
|
|
dtiColumns :: [API.V0.ColumnInfo],
|
|
dtiPrimaryKey :: Maybe [API.V0.ColumnName],
|
|
dtiDescription :: Maybe Text
|
|
}
|
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
|
deriving anyclass (NFData, Hashable)
|
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec TableInfo
|
|
|
|
instance HasCodec TableInfo where
|
|
codec =
|
|
object "TableInfo" $
|
|
TableInfo
|
|
<$> requiredField "name" "The name of the table" .= dtiName
|
|
<*> requiredField "columns" "The columns of the table" .= dtiColumns
|
|
<*> optionalFieldOrNull "primary_key" "The primary key of the table" .= dtiPrimaryKey
|
|
<*> optionalFieldOrNull "description" "Description of the table" .= dtiDescription
|