mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
b4f89569c8
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4467 GitOrigin-RevId: 5e81d8581197c90ad2de9106e724c63d7592ae72
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 Text,
|
|
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
|