graphql-engine/server/src-dc-api/Hasura/Backends/DataConnector/API/V0/OrderBy.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

54 lines
1.5 KiB
Haskell

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedLists #-}
--
module Hasura.Backends.DataConnector.API.V0.OrderBy
( OrderBy (..),
OrderType (..),
)
where
--------------------------------------------------------------------------------
import Autodocodec.Extended
import Autodocodec.OpenAPI ()
import Control.DeepSeq (NFData)
import Data.Aeson (FromJSON, ToJSON)
import Data.Data (Data)
import Data.Hashable (Hashable)
import Data.OpenApi (ToSchema)
import GHC.Generics (Generic)
import Hasura.Backends.DataConnector.API.V0.Column qualified as API.V0
import Prelude
--------------------------------------------------------------------------------
data OrderBy = OrderBy
{ column :: API.V0.ColumnName,
ordering :: OrderType
}
deriving stock (Data, Eq, Generic, Ord, Show)
deriving anyclass (Hashable, NFData)
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec OrderBy
instance HasCodec OrderBy where
codec =
object "OrderBy" $
OrderBy
<$> requiredField "column" "Column to order by" .= column
<*> requiredField "ordering" "Ordering" .= ordering
--------------------------------------------------------------------------------
data OrderType
= Ascending
| Descending
deriving stock (Data, Eq, Generic, Ord, Show, Enum, Bounded)
deriving anyclass (Hashable, NFData)
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec OrderType
instance HasCodec OrderType where
codec =
named "OrderType" $
disjointStringConstCodec [(Ascending, "asc"), (Descending, "desc")]