mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-22 06:51:32 +03:00
4f835623b1
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4400 GitOrigin-RevId: 2d90542f95ef4dad70c8dfe1ca3b4c1f3bdaa527
55 lines
1.7 KiB
Haskell
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
|