graphql-engine/server/src-dc-api/Hasura/Backends/DataConnector/API/V0/Column.hs
Daniel Chambers 4f835623b1 Rename Data Wrapper to Data Connector [GDW-89]
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4400
GitOrigin-RevId: 2d90542f95ef4dad70c8dfe1ca3b4c1f3bdaa527
2022-05-02 05:04:07 +00:00

55 lines
1.7 KiB
Haskell

{-# LANGUAGE DeriveAnyClass #-}
--
module Hasura.Backends.DataConnector.API.V0.Column
( ColumnInfo (..),
ColumnName (..),
)
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.Scalar.Type qualified as API.V0.Scalar
import Prelude
--------------------------------------------------------------------------------
newtype ColumnName = ColumnName {unColumnName :: Text}
deriving stock (Eq, Ord, Show, Generic, Data)
deriving anyclass (NFData, Hashable)
deriving newtype (ToJSONKey, FromJSONKey)
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec ColumnName
instance HasCodec ColumnName where
codec = dimapCodec ColumnName unColumnName textCodec
--------------------------------------------------------------------------------
data ColumnInfo = ColumnInfo
{ dciName :: ColumnName,
dciType :: API.V0.Scalar.Type,
dciNullable :: Bool,
dciDescription :: Maybe Text
}
deriving stock (Eq, Ord, Show, Generic, Data)
deriving anyclass (NFData, Hashable)
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec ColumnInfo
instance HasCodec ColumnInfo where
codec =
object "ColumnInfo" $
ColumnInfo
<$> requiredField "name" "Column name" .= dciName
<*> requiredField "type" "Column type" .= dciType
<*> requiredField "nullable" "Is column nullable" .= dciNullable
<*> optionalFieldOrNull "description" "Column description" .= dciDescription