mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
66 lines
1.5 KiB
Haskell
66 lines
1.5 KiB
Haskell
module Hasura.RQL.IR.OrderBy
|
|
( OrderByCol (..),
|
|
OrderByItemG (..),
|
|
OrderByItem,
|
|
-- used by RQL.DML.Types
|
|
orderByColFromTxt,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson
|
|
import Data.Text qualified as T
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Backend
|
|
import Hasura.RQL.Types.Common
|
|
import Hasura.SQL.Backend
|
|
|
|
-- order by col
|
|
|
|
data OrderByCol
|
|
= OCPG !FieldName
|
|
| OCRel !FieldName !OrderByCol
|
|
deriving (Show, Eq)
|
|
|
|
instance FromJSON OrderByCol where
|
|
parseJSON = \case
|
|
(String t) -> orderByColFromToks $ T.split (== '.') t
|
|
v -> parseJSON v >>= orderByColFromToks
|
|
|
|
orderByColFromToks ::
|
|
(MonadFail m) =>
|
|
[Text] ->
|
|
m OrderByCol
|
|
orderByColFromToks toks = do
|
|
when (any T.null toks) $ fail "col/rel cannot be empty"
|
|
case toks of
|
|
[] -> fail "failed to parse an OrderByCol: found empty cols"
|
|
x : xs -> return $ go (FieldName x) xs
|
|
where
|
|
go fld = \case
|
|
[] -> OCPG fld
|
|
x : xs -> OCRel fld $ go (FieldName x) xs
|
|
|
|
orderByColFromTxt ::
|
|
(MonadFail m) =>
|
|
Text ->
|
|
m OrderByCol
|
|
orderByColFromTxt =
|
|
orderByColFromToks . T.split (== '.')
|
|
|
|
-- order by item
|
|
|
|
data OrderByItemG (b :: BackendType) a = OrderByItemG
|
|
{ obiType :: !(Maybe (BasicOrderType b)),
|
|
obiColumn :: !a,
|
|
obiNulls :: !(Maybe (NullsOrderType b))
|
|
}
|
|
deriving (Functor, Foldable, Traversable, Generic)
|
|
|
|
deriving instance (Backend b, Show a) => Show (OrderByItemG b a)
|
|
|
|
deriving instance (Backend b, Eq a) => Eq (OrderByItemG b a)
|
|
|
|
instance (Backend b, Hashable a) => Hashable (OrderByItemG b a)
|
|
|
|
type OrderByItem b = OrderByItemG b OrderByCol
|