mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-22 06:51:32 +03:00
a6dca587d2
Updates to the latest version of autodocodec and uses the new features, in particular `discriminatedUnionCodec`. This allows us to remove the `ValueWrapper*` types and `sumTypeCodec`. Sum types are now encoded as discriminated unions. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5155 GitOrigin-RevId: 20bfdc12b28d35db354c4a149b9175fab0b2b7d2
54 lines
1.5 KiB
Haskell
54 lines
1.5 KiB
Haskell
{-# LANGUAGE DeriveAnyClass #-}
|
|
{-# LANGUAGE OverloadedLists #-}
|
|
|
|
--
|
|
module Hasura.Backends.DataConnector.API.V0.OrderBy
|
|
( OrderBy (..),
|
|
OrderType (..),
|
|
)
|
|
where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Autodocodec
|
|
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" $
|
|
stringConstCodec [(Ascending, "asc"), (Descending, "desc")]
|