{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE TemplateHaskellQuotes #-}

module Hasura.GraphQL.Schema.OrderBy
  ( tableOrderByExp,
    logicalModelOrderByExp,
  )
where

import Control.Lens ((^?))
import Data.Has
import Data.HashMap.Strict.Extended qualified as HashMap
import Data.Text.Casing qualified as C
import Data.Text.Extended
import Hasura.Base.Error
import Hasura.Function.Cache
import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Schema.Backend
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.Parser
  ( InputFieldsParser,
    Kind (..),
    Parser,
  )
import Hasura.GraphQL.Schema.Parser qualified as P
import Hasura.GraphQL.Schema.Table
import Hasura.GraphQL.Schema.Typename
import Hasura.LogicalModel.Cache (LogicalModelInfo (..))
import Hasura.LogicalModel.Common (columnsFromFields, getSelPermInfoForLogicalModel, toFieldInfo)
import Hasura.LogicalModel.Types (LogicalModelName (..))
import Hasura.Name qualified as Name
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp
import Hasura.RQL.IR.OrderBy qualified as IR
import Hasura.RQL.IR.Select qualified as IR
import Hasura.RQL.IR.Value qualified as IR
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Column
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.ComputedField
import Hasura.RQL.Types.NamingCase
import Hasura.RQL.Types.Relationships.Local
import Hasura.RQL.Types.SchemaCache hiding (askTableInfo)
import Hasura.RQL.Types.Source
import Hasura.RQL.Types.SourceCustomization
import Hasura.Table.Cache
import Language.GraphQL.Draft.Syntax qualified as G
import Type.Reflection

{-# INLINE orderByOperator #-}
orderByOperator ::
  forall b n.
  (BackendSchema b, MonadParse n) =>
  NamingCase ->
  SourceInfo b ->
  Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator :: forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator NamingCase
tCase SourceInfo b
sourceInfo = case NamingCase
tCase of
  NamingCase
HasuraCase -> forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperatorsHasuraCase @b SourceInfo b
sourceInfo
  NamingCase
GraphqlCase -> forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperatorsGraphqlCase @b SourceInfo b
sourceInfo

-- | Corresponds to an object type for an order by.
--
-- > input table_order_by {
-- >   col1: order_by
-- >   col2: order_by
-- >   .     .
-- >   .     .
-- >   coln: order_by
-- >   obj-rel: <remote-table>_order_by
-- > }
-- TODO: When there are no columns accessible to a role, the
-- `<table>_order_by` will be an empty input object. In such a case,
-- we can avoid exposing the `order_by` argument.
logicalModelOrderByExp ::
  forall b r m n.
  ( MonadBuildSchema b r m n
  ) =>
  LogicalModelInfo b ->
  SchemaT r m (Parser 'Input n [IR.AnnotatedOrderByItemG b (IR.UnpreparedValue b)])
logicalModelOrderByExp :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
LogicalModelInfo b
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
logicalModelOrderByExp LogicalModelInfo b
logicalModel = do
  RoleName
roleName <- (SchemaContext -> RoleName) -> SchemaT r m RoleName
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaContext -> RoleName
scRole
  let name :: Name
name = LogicalModelName -> Name
getLogicalModelName (LogicalModelInfo b -> LogicalModelName
forall (b :: BackendType). LogicalModelInfo b -> LogicalModelName
_lmiName LogicalModelInfo b
logicalModel)
      selectPermissions :: Maybe (SelPermInfo b)
selectPermissions = RoleName -> LogicalModelInfo b -> Maybe (SelPermInfo b)
forall (b :: BackendType).
Backend b =>
RoleName -> LogicalModelInfo b -> Maybe (SelPermInfo b)
getSelPermInfoForLogicalModel RoleName
roleName LogicalModelInfo b
logicalModel
  case InsOrdHashMap (Column b) (NullableScalarType b)
-> Maybe [FieldInfo b]
forall (b :: BackendType).
Backend b =>
InsOrdHashMap (Column b) (NullableScalarType b)
-> Maybe [FieldInfo b]
toFieldInfo (InsOrdHashMap (Column b) (LogicalModelField b)
-> InsOrdHashMap (Column b) (NullableScalarType b)
forall k (b :: BackendType).
InsOrdHashMap k (LogicalModelField b)
-> InsOrdHashMap k (NullableScalarType b)
columnsFromFields (InsOrdHashMap (Column b) (LogicalModelField b)
 -> InsOrdHashMap (Column b) (NullableScalarType b))
-> InsOrdHashMap (Column b) (LogicalModelField b)
-> InsOrdHashMap (Column b) (NullableScalarType b)
forall a b. (a -> b) -> a -> b
$ LogicalModelInfo b
-> InsOrdHashMap (Column b) (LogicalModelField b)
forall (b :: BackendType).
LogicalModelInfo b
-> InsOrdHashMap (Column b) (LogicalModelField b)
_lmiFields LogicalModelInfo b
logicalModel) of
    Maybe [FieldInfo b]
Nothing -> Text
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (m :: * -> *) a. QErrM m => Text -> m a
throw500 (Text
 -> SchemaT
      r
      m
      (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)]))
-> Text
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall a b. (a -> b) -> a -> b
$ Text
"Error creating fields for logical model " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name -> Text
forall a. Show a => a -> Text
tshow Name
name
    Just [FieldInfo b]
tableFields -> do
      let description :: Description
description =
            Text -> Description
G.Description
              (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"Ordering options when selecting data from "
              Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name
name
              Name -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
"."
          memoizeKey :: Name
memoizeKey = Name
name
      GQLNameIdentifier
-> Description
-> Maybe (SelPermInfo b)
-> [FieldInfo b]
-> Name
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *) name.
(Ord name, Typeable name, MonadBuildSchema b r m n) =>
GQLNameIdentifier
-> Description
-> Maybe (SelPermInfo b)
-> [FieldInfo b]
-> name
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
orderByExpInternal (Name -> GQLNameIdentifier
C.fromCustomName Name
name) Description
description Maybe (SelPermInfo b)
selectPermissions [FieldInfo b]
tableFields Name
memoizeKey

-- | Corresponds to an object type for an order by.
--
-- > input table_order_by {
-- >   col1: order_by
-- >   col2: order_by
-- >   .     .
-- >   .     .
-- >   coln: order_by
-- >   obj-rel: <remote-table>_order_by
-- > }
orderByExpInternal ::
  forall b r m n name.
  (Ord name, Typeable name, MonadBuildSchema b r m n) =>
  C.GQLNameIdentifier ->
  G.Description ->
  Maybe (SelPermInfo b) ->
  [FieldInfo b] ->
  name ->
  SchemaT r m (Parser 'Input n [IR.AnnotatedOrderByItemG b (IR.UnpreparedValue b)])
orderByExpInternal :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *) name.
(Ord name, Typeable name, MonadBuildSchema b r m n) =>
GQLNameIdentifier
-> Description
-> Maybe (SelPermInfo b)
-> [FieldInfo b]
-> name
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
orderByExpInternal GQLNameIdentifier
gqlName Description
description Maybe (SelPermInfo b)
selectPermissions [FieldInfo b]
tableFields name
memoizeKey = do
  SourceInfo b
sourceInfo <- (r -> SourceInfo b) -> SchemaT r m (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  Name
-> (SourceName, name)
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
 Typeable b) =>
Name -> a -> m (p n b) -> m (p n b)
P.memoizeOn 'orderByExpInternal (SourceInfo b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo, name
memoizeKey) do
    let customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
        tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
        mkTypename :: Name -> Name
mkTypename = MkTypename -> Name -> Name
runMkTypename (MkTypename -> Name -> Name) -> MkTypename -> Name -> Name
forall a b. (a -> b) -> a -> b
$ ResolvedSourceCustomization -> MkTypename
_rscTypeNames ResolvedSourceCustomization
customization
    let name :: Name
name = Name -> Name
mkTypename (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier
mkTableOrderByTypeName GQLNameIdentifier
gqlName
    InputFieldsParser
  MetadataObjId
  n
  [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
fieldParsers <- [InputFieldsParser
   MetadataObjId
   n
   (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])]
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA ([InputFieldsParser
    MetadataObjId
    n
    (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])]
 -> InputFieldsParser
      MetadataObjId
      n
      [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]])
-> ([Maybe
       (InputFieldsParser
          MetadataObjId
          n
          (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))]
    -> [InputFieldsParser
          MetadataObjId
          n
          (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])])
-> [Maybe
      (InputFieldsParser
         MetadataObjId
         n
         (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))]
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe
   (InputFieldsParser
      MetadataObjId
      n
      (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))]
-> [InputFieldsParser
      MetadataObjId
      n
      (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe
    (InputFieldsParser
       MetadataObjId
       n
       (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))]
 -> InputFieldsParser
      MetadataObjId
      n
      [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]])
-> SchemaT
     r
     m
     [Maybe
        (InputFieldsParser
           MetadataObjId
           n
           (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))]
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FieldInfo b
 -> SchemaT
      r
      m
      (Maybe
         (InputFieldsParser
            MetadataObjId
            n
            (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))))
-> [FieldInfo b]
-> SchemaT
     r
     m
     [Maybe
        (InputFieldsParser
           MetadataObjId
           n
           (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (SourceInfo b
-> NamingCase
-> FieldInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           MetadataObjId
           n
           (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])))
mkField SourceInfo b
sourceInfo NamingCase
tCase) [FieldInfo b]
tableFields
    pure $ [[AnnotatedOrderByItemG b (UnpreparedValue b)]]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[AnnotatedOrderByItemG b (UnpreparedValue b)]]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> ([Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
    -> [[AnnotatedOrderByItemG b (UnpreparedValue b)]])
-> [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
-> [[AnnotatedOrderByItemG b (UnpreparedValue b)]]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> Parser
     MetadataObjId
     'Input
     n
     [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
-> Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
-> Parser
     MetadataObjId
     'Input
     n
     [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
name (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
description) InputFieldsParser
  MetadataObjId
  n
  [Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]]
fieldParsers
  where
    mkField ::
      SourceInfo b ->
      NamingCase ->
      FieldInfo b ->
      SchemaT r m (Maybe (InputFieldsParser n (Maybe [IR.AnnotatedOrderByItemG b (IR.UnpreparedValue b)])))
    mkField :: SourceInfo b
-> NamingCase
-> FieldInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           MetadataObjId
           n
           (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])))
mkField SourceInfo b
sourceInfo NamingCase
tCase FieldInfo b
fieldInfo = MaybeT
  (SchemaT r m)
  (InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           MetadataObjId
           n
           (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (InputFieldsParser
      MetadataObjId
      n
      (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
 -> SchemaT
      r
      m
      (Maybe
         (InputFieldsParser
            MetadataObjId
            n
            (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           MetadataObjId
           n
           (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])))
forall a b. (a -> b) -> a -> b
$ do
      SelPermInfo b
selectPermissions' <- Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe Maybe (SelPermInfo b)
selectPermissions
      RoleName
roleName <- (SchemaContext -> RoleName) -> MaybeT (SchemaT r m) RoleName
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaContext -> RoleName
scRole
      case FieldInfo b
fieldInfo of
        FIColumn (SCIScalarColumn ColumnInfo b
columnInfo) -> do
          let !fieldName :: Name
fieldName = ColumnInfo b -> Name
forall (b :: BackendType). ColumnInfo b -> Name
ciName ColumnInfo b
columnInfo
          let redactionExp :: AnnRedactionExp b (UnpreparedValue b)
redactionExp = AnnRedactionExp b (UnpreparedValue b)
-> Maybe (AnnRedactionExp b (UnpreparedValue b))
-> AnnRedactionExp b (UnpreparedValue b)
forall a. a -> Maybe a -> a
fromMaybe AnnRedactionExp b (UnpreparedValue b)
forall (b :: BackendType) v. AnnRedactionExp b v
NoRedaction (Maybe (AnnRedactionExp b (UnpreparedValue b))
 -> AnnRedactionExp b (UnpreparedValue b))
-> Maybe (AnnRedactionExp b (UnpreparedValue b))
-> AnnRedactionExp b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ SelPermInfo b
-> Column b -> Maybe (AnnRedactionExp b (UnpreparedValue b))
forall (b :: BackendType).
Backend b =>
SelPermInfo b
-> Column b -> Maybe (AnnRedactionExpUnpreparedValue b)
getRedactionExprForColumn SelPermInfo b
selectPermissions' (ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn ColumnInfo b
columnInfo)
          forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator @b NamingCase
tCase SourceInfo b
sourceInfo
            Parser
  MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
-> (Parser
      MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
    -> InputFieldsParser
         MetadataObjId
         n
         (Maybe (Maybe (BasicOrderType b, NullsOrderType b))))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
forall a b. a -> (a -> b) -> b
& Name
-> Maybe Description
-> Parser
     MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
fieldName Maybe Description
forall a. Maybe a
Nothing
            InputFieldsParser
  MetadataObjId
  n
  (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (((BasicOrderType b, NullsOrderType b)
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> Maybe (BasicOrderType b, NullsOrderType b)
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (AnnotatedOrderByItemG b (UnpreparedValue b)
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AnnotatedOrderByItemG b (UnpreparedValue b)
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> ((BasicOrderType b, NullsOrderType b)
    -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> (BasicOrderType b, NullsOrderType b)
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: BackendType) a.
a -> (BasicOrderType b, NullsOrderType b) -> OrderByItemG b a
mkOrderByItemG @b (ColumnInfo b
-> AnnRedactionExp b (UnpreparedValue b)
-> AnnotatedOrderByElement b (UnpreparedValue b)
forall (b :: BackendType) v.
ColumnInfo b -> AnnRedactionExp b v -> AnnotatedOrderByElement b v
IR.AOCColumn ColumnInfo b
columnInfo AnnRedactionExp b (UnpreparedValue b)
redactionExp)) (Maybe (BasicOrderType b, NullsOrderType b)
 -> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (BasicOrderType b, NullsOrderType b)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join)
            InputFieldsParser
  MetadataObjId
  n
  (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> (InputFieldsParser
      MetadataObjId
      n
      (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
    -> MaybeT
         (SchemaT r m)
         (InputFieldsParser
            MetadataObjId
            n
            (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a b. a -> (a -> b) -> b
& InputFieldsParser
  MetadataObjId
  n
  (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a. a -> MaybeT (SchemaT r m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
        FIColumn (SCIObjectColumn NestedObjectInfo b
_) -> MaybeT
  (SchemaT r m)
  (InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a. MaybeT (SchemaT r m) a
forall (f :: * -> *) a. Alternative f => f a
empty -- TODO(dmoverton)
        FIColumn (SCIArrayColumn NestedArrayInfo b
_) -> MaybeT
  (SchemaT r m)
  (InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a. MaybeT (SchemaT r m) a
forall (f :: * -> *) a. Alternative f => f a
empty -- TODO(dmoverton)
        FIRelationship RelInfo b
relationshipInfo -> do
          case RelInfo b -> RelTarget b
forall (b :: BackendType). RelInfo b -> RelTarget b
riTarget RelInfo b
relationshipInfo of
            RelTargetNativeQuery NativeQueryName
_ -> [Char]
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a. HasCallStack => [Char] -> a
error [Char]
"mkField RelTargetNativeQuery"
            RelTargetTable TableName b
remoteTableName -> do
              TableInfo b
remoteTableInfo <- TableName b -> MaybeT (SchemaT r m) (TableInfo b)
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName b
remoteTableName
              SelPermInfo b
perms <- Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b))
-> Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RoleName -> TableInfo b -> Maybe (SelPermInfo b)
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo b
remoteTableInfo
              Name
fieldName <- Maybe Name -> MaybeT (SchemaT r m) Name
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe Name -> MaybeT (SchemaT r m) Name)
-> Maybe Name -> MaybeT (SchemaT r m) Name
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Name
G.mkName (Text -> Maybe Name) -> Text -> Maybe Name
forall a b. (a -> b) -> a -> b
$ RelName -> Text
relNameToTxt (RelName -> Text) -> RelName -> Text
forall a b. (a -> b) -> a -> b
$ RelInfo b -> RelName
forall (b :: BackendType). RelInfo b -> RelName
riName RelInfo b
relationshipInfo
              let newPerms :: GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
newPerms = (PartialSQLExp b -> UnpreparedValue b)
-> AnnBoolExpFld b (PartialSQLExp b)
-> AnnBoolExpFld b (UnpreparedValue b)
forall a b. (a -> b) -> AnnBoolExpFld b a -> AnnBoolExpFld b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PartialSQLExp b -> UnpreparedValue b
forall (b :: BackendType). PartialSQLExp b -> UnpreparedValue b
partialSQLExpToUnpreparedValue (AnnBoolExpFld b (PartialSQLExp b)
 -> AnnBoolExpFld b (UnpreparedValue b))
-> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
-> GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SelPermInfo b -> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
forall (b :: BackendType). SelPermInfo b -> AnnBoolExpPartialSQL b
spiFilter SelPermInfo b
perms
              case RelInfo b -> RelType
forall (b :: BackendType). RelInfo b -> RelType
riType RelInfo b
relationshipInfo of
                RelType
ObjRel -> do
                  Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)]
otherTableParser <- SchemaT
  r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SchemaT
   r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
 -> MaybeT
      (SchemaT r m)
      (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)]))
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall a b. (a -> b) -> a -> b
$ TableInfo b
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
tableOrderByExp TableInfo b
remoteTableInfo
                  pure $ do
                    Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
otherTableOrderBy <- Maybe (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
 -> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
fieldName Maybe Description
forall a. Maybe a
Nothing (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)]
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)]
otherTableParser)
                    pure $ ([AnnotatedOrderByItemG b (UnpreparedValue b)]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((AnnotatedOrderByItemG b (UnpreparedValue b)
 -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> [a] -> [b]
map ((AnnotatedOrderByItemG b (UnpreparedValue b)
  -> AnnotatedOrderByItemG b (UnpreparedValue b))
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> (AnnotatedOrderByItemG b (UnpreparedValue b)
    -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> a -> b
$ (AnnotatedOrderByElement b (UnpreparedValue b)
 -> AnnotatedOrderByElement b (UnpreparedValue b))
-> AnnotatedOrderByItemG b (UnpreparedValue b)
-> AnnotatedOrderByItemG b (UnpreparedValue b)
forall a b. (a -> b) -> OrderByItemG b a -> OrderByItemG b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((AnnotatedOrderByElement b (UnpreparedValue b)
  -> AnnotatedOrderByElement b (UnpreparedValue b))
 -> AnnotatedOrderByItemG b (UnpreparedValue b)
 -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> (AnnotatedOrderByElement b (UnpreparedValue b)
    -> AnnotatedOrderByElement b (UnpreparedValue b))
-> AnnotatedOrderByItemG b (UnpreparedValue b)
-> AnnotatedOrderByItemG b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ RelInfo b
-> GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
-> AnnotatedOrderByElement b (UnpreparedValue b)
-> AnnotatedOrderByElement b (UnpreparedValue b)
forall (b :: BackendType) v.
RelInfo b
-> AnnBoolExp b v
-> AnnotatedOrderByElement b v
-> AnnotatedOrderByElement b v
IR.AOCObjectRelation RelInfo b
relationshipInfo GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
newPerms) Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
otherTableOrderBy
                RelType
ArrRel -> do
                  let aggregateFieldName :: Name
aggregateFieldName = NamingCase -> GQLNameIdentifier -> Name
applyFieldNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ (Name, [NameSuffix]) -> GQLNameIdentifier
C.fromAutogeneratedTuple (Name
fieldName, [Name -> NameSuffix
G.convertNameToSuffix Name
Name._aggregate])
                  Parser
  'Input
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationParser <- SchemaT
  r
  m
  (Parser
     'Input
     n
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> MaybeT
     (SchemaT r m)
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SchemaT
   r
   m
   (Parser
      'Input
      n
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
 -> MaybeT
      (SchemaT r m)
      (Parser
         'Input
         n
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
-> SchemaT
     r
     m
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> MaybeT
     (SchemaT r m)
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall a b. (a -> b) -> a -> b
$ SourceInfo b
-> TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
SourceInfo b
-> TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
orderByAggregation SourceInfo b
sourceInfo TableInfo b
remoteTableInfo
                  pure $ do
                    Maybe
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationOrderBy <- Maybe
  (Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe
   (Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
 -> Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
aggregateFieldName Maybe Description
forall a. Maybe a
Nothing (Parser
  'Input
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable Parser
  'Input
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationParser)
                    pure $ ([OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
 -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> [a] -> [b]
map ((OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
  -> AnnotatedOrderByItemG b (UnpreparedValue b))
 -> [OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> (OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
    -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> a -> b
$ (AnnotatedAggregateOrderBy b (UnpreparedValue b)
 -> AnnotatedOrderByElement b (UnpreparedValue b))
-> OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
-> AnnotatedOrderByItemG b (UnpreparedValue b)
forall a b. (a -> b) -> OrderByItemG b a -> OrderByItemG b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((AnnotatedAggregateOrderBy b (UnpreparedValue b)
  -> AnnotatedOrderByElement b (UnpreparedValue b))
 -> OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
 -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> (AnnotatedAggregateOrderBy b (UnpreparedValue b)
    -> AnnotatedOrderByElement b (UnpreparedValue b))
-> OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
-> AnnotatedOrderByItemG b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ RelInfo b
-> GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
-> AnnotatedAggregateOrderBy b (UnpreparedValue b)
-> AnnotatedOrderByElement b (UnpreparedValue b)
forall (b :: BackendType) v.
RelInfo b
-> AnnBoolExp b v
-> AnnotatedAggregateOrderBy b v
-> AnnotatedOrderByElement b v
IR.AOCArrayAggregation RelInfo b
relationshipInfo GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
newPerms) Maybe
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationOrderBy
        FIComputedField ComputedFieldInfo {Maybe Text
ComputedFieldName
ComputedFieldReturn b
XComputedField b
ComputedFieldFunction b
_cfiXComputedFieldInfo :: XComputedField b
_cfiName :: ComputedFieldName
_cfiFunction :: ComputedFieldFunction b
_cfiReturnType :: ComputedFieldReturn b
_cfiDescription :: Maybe Text
_cfiXComputedFieldInfo :: forall (b :: BackendType). ComputedFieldInfo b -> XComputedField b
_cfiName :: forall (b :: BackendType). ComputedFieldInfo b -> ComputedFieldName
_cfiFunction :: forall (b :: BackendType).
ComputedFieldInfo b -> ComputedFieldFunction b
_cfiReturnType :: forall (b :: BackendType).
ComputedFieldInfo b -> ComputedFieldReturn b
_cfiDescription :: forall (b :: BackendType). ComputedFieldInfo b -> Maybe Text
..} -> do
          let ComputedFieldFunction {Maybe PGDescription
Seq (FunctionArgument b)
FunctionName b
ComputedFieldImplicitArguments b
_cffName :: FunctionName b
_cffInputArgs :: Seq (FunctionArgument b)
_cffComputedFieldImplicitArgs :: ComputedFieldImplicitArguments b
_cffDescription :: Maybe PGDescription
_cffName :: forall (b :: BackendType).
ComputedFieldFunction b -> FunctionName b
_cffInputArgs :: forall (b :: BackendType).
ComputedFieldFunction b -> Seq (FunctionArgument b)
_cffComputedFieldImplicitArgs :: forall (b :: BackendType).
ComputedFieldFunction b -> ComputedFieldImplicitArguments b
_cffDescription :: forall (b :: BackendType).
ComputedFieldFunction b -> Maybe PGDescription
..} = ComputedFieldFunction b
_cfiFunction
              mkComputedFieldOrderBy :: ComputedFieldOrderByElement b (UnpreparedValue b)
-> ComputedFieldOrderBy b (UnpreparedValue b)
mkComputedFieldOrderBy =
                let functionArgs :: FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b))
functionArgs =
                      ([FunctionArgumentExp b (UnpreparedValue b)]
 -> HashMap Text (FunctionArgumentExp b (UnpreparedValue b))
 -> FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b)))
-> HashMap Text (FunctionArgumentExp b (UnpreparedValue b))
-> [FunctionArgumentExp b (UnpreparedValue b)]
-> FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b))
forall a b c. (a -> b -> c) -> b -> a -> c
flip [FunctionArgumentExp b (UnpreparedValue b)]
-> HashMap Text (FunctionArgumentExp b (UnpreparedValue b))
-> FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b))
forall a. [a] -> HashMap Text a -> FunctionArgsExpG a
FunctionArgsExp HashMap Text (FunctionArgumentExp b (UnpreparedValue b))
forall a. Monoid a => a
mempty
                        ([FunctionArgumentExp b (UnpreparedValue b)]
 -> FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b)))
-> [FunctionArgumentExp b (UnpreparedValue b)]
-> FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType) v.
Backend b =>
v -> ComputedFieldImplicitArguments b -> [FunctionArgumentExp b v]
fromComputedFieldImplicitArguments @b UnpreparedValue b
forall (b :: BackendType). UnpreparedValue b
IR.UVSession ComputedFieldImplicitArguments b
_cffComputedFieldImplicitArgs
                 in XComputedField b
-> ComputedFieldName
-> FunctionName b
-> FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b))
-> ComputedFieldOrderByElement b (UnpreparedValue b)
-> ComputedFieldOrderBy b (UnpreparedValue b)
forall (b :: BackendType) v.
XComputedField b
-> ComputedFieldName
-> FunctionName b
-> FunctionArgsExp b v
-> ComputedFieldOrderByElement b v
-> ComputedFieldOrderBy b v
IR.ComputedFieldOrderBy XComputedField b
_cfiXComputedFieldInfo ComputedFieldName
_cfiName FunctionName b
_cffName FunctionArgsExpG (FunctionArgumentExp b (UnpreparedValue b))
functionArgs
          Name
fieldName <- Maybe Name -> MaybeT (SchemaT r m) Name
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe Name -> MaybeT (SchemaT r m) Name)
-> Maybe Name -> MaybeT (SchemaT r m) Name
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Name
G.mkName (Text -> Maybe Name) -> Text -> Maybe Name
forall a b. (a -> b) -> a -> b
$ ComputedFieldName -> Text
forall a. ToTxt a => a -> Text
toTxt ComputedFieldName
_cfiName
          Bool -> MaybeT (SchemaT r m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> MaybeT (SchemaT r m) ())
-> Bool -> MaybeT (SchemaT r m) ()
forall a b. (a -> b) -> a -> b
$ Seq (FunctionArgument b)
_cffInputArgs Seq (FunctionArgument b) -> Seq (FunctionArgument b) -> Bool
forall a. Eq a => a -> a -> Bool
== Seq (FunctionArgument b)
forall a. Monoid a => a
mempty -- No input arguments other than table row and session argument
          case forall (b :: BackendType).
Backend b =>
ComputedFieldReturn b -> ComputedFieldReturnType b
computedFieldReturnType @b ComputedFieldReturn b
_cfiReturnType of
            ReturnsScalar ScalarType b
scalarType -> do
              let redactionExp :: AnnRedactionExp b (UnpreparedValue b)
redactionExp = AnnRedactionExp b (UnpreparedValue b)
-> Maybe (AnnRedactionExp b (UnpreparedValue b))
-> AnnRedactionExp b (UnpreparedValue b)
forall a. a -> Maybe a -> a
fromMaybe AnnRedactionExp b (UnpreparedValue b)
forall (b :: BackendType) v. AnnRedactionExp b v
NoRedaction (Maybe (AnnRedactionExp b (UnpreparedValue b))
 -> AnnRedactionExp b (UnpreparedValue b))
-> Maybe (AnnRedactionExp b (UnpreparedValue b))
-> AnnRedactionExp b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ SelPermInfo b
-> ComputedFieldName
-> Maybe (AnnRedactionExp b (UnpreparedValue b))
forall (b :: BackendType).
Backend b =>
SelPermInfo b
-> ComputedFieldName -> Maybe (AnnRedactionExpUnpreparedValue b)
getRedactionExprForComputedField SelPermInfo b
selectPermissions' ComputedFieldName
_cfiName
              let computedFieldOrderBy :: ComputedFieldOrderBy b (UnpreparedValue b)
computedFieldOrderBy = ComputedFieldOrderByElement b (UnpreparedValue b)
-> ComputedFieldOrderBy b (UnpreparedValue b)
mkComputedFieldOrderBy (ComputedFieldOrderByElement b (UnpreparedValue b)
 -> ComputedFieldOrderBy b (UnpreparedValue b))
-> ComputedFieldOrderByElement b (UnpreparedValue b)
-> ComputedFieldOrderBy b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ ScalarType b
-> AnnRedactionExp b (UnpreparedValue b)
-> ComputedFieldOrderByElement b (UnpreparedValue b)
forall (b :: BackendType) v.
ScalarType b
-> AnnRedactionExp b v -> ComputedFieldOrderByElement b v
IR.CFOBEScalar ScalarType b
scalarType AnnRedactionExp b (UnpreparedValue b)
redactionExp
              InputFieldsParser
  MetadataObjId
  n
  (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a. a -> MaybeT (SchemaT r m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
                (InputFieldsParser
   MetadataObjId
   n
   (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
 -> MaybeT
      (SchemaT r m)
      (InputFieldsParser
         MetadataObjId
         n
         (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> Parser
     MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional
                  Name
fieldName
                  Maybe Description
forall a. Maybe a
Nothing
                  (forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator @b NamingCase
tCase SourceInfo b
sourceInfo)
                InputFieldsParser
  MetadataObjId
  n
  (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> ((BasicOrderType b, NullsOrderType b)
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> Maybe (BasicOrderType b, NullsOrderType b)
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (AnnotatedOrderByItemG b (UnpreparedValue b)
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AnnotatedOrderByItemG b (UnpreparedValue b)
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> ((BasicOrderType b, NullsOrderType b)
    -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> (BasicOrderType b, NullsOrderType b)
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: BackendType) a.
a -> (BasicOrderType b, NullsOrderType b) -> OrderByItemG b a
mkOrderByItemG @b (ComputedFieldOrderBy b (UnpreparedValue b)
-> AnnotatedOrderByElement b (UnpreparedValue b)
forall (b :: BackendType) v.
ComputedFieldOrderBy b v -> AnnotatedOrderByElement b v
IR.AOCComputedField ComputedFieldOrderBy b (UnpreparedValue b)
computedFieldOrderBy))
                (Maybe (BasicOrderType b, NullsOrderType b)
 -> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (BasicOrderType b, NullsOrderType b)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join
            ReturnsTable TableName b
table -> do
              let aggregateFieldName :: Name
aggregateFieldName = NamingCase -> GQLNameIdentifier -> Name
applyFieldNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ (Name, [NameSuffix]) -> GQLNameIdentifier
C.fromAutogeneratedTuple (Name
fieldName, [Name -> NameSuffix
G.convertNameToSuffix Name
Name._aggregate])
              TableInfo b
tableInfo' <- TableName b -> MaybeT (SchemaT r m) (TableInfo b)
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName b
table
              SelPermInfo b
perms <- Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b))
-> Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RoleName -> TableInfo b -> Maybe (SelPermInfo b)
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo b
tableInfo'
              let newPerms :: GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
newPerms = (PartialSQLExp b -> UnpreparedValue b)
-> AnnBoolExpFld b (PartialSQLExp b)
-> AnnBoolExpFld b (UnpreparedValue b)
forall a b. (a -> b) -> AnnBoolExpFld b a -> AnnBoolExpFld b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PartialSQLExp b -> UnpreparedValue b
forall (b :: BackendType). PartialSQLExp b -> UnpreparedValue b
partialSQLExpToUnpreparedValue (AnnBoolExpFld b (PartialSQLExp b)
 -> AnnBoolExpFld b (UnpreparedValue b))
-> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
-> GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SelPermInfo b -> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
forall (b :: BackendType). SelPermInfo b -> AnnBoolExpPartialSQL b
spiFilter SelPermInfo b
perms
              Parser
  'Input
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationParser <- SchemaT
  r
  m
  (Parser
     'Input
     n
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> MaybeT
     (SchemaT r m)
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SchemaT
   r
   m
   (Parser
      'Input
      n
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
 -> MaybeT
      (SchemaT r m)
      (Parser
         'Input
         n
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
-> SchemaT
     r
     m
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> MaybeT
     (SchemaT r m)
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall a b. (a -> b) -> a -> b
$ SourceInfo b
-> TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
SourceInfo b
-> TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
orderByAggregation SourceInfo b
sourceInfo TableInfo b
tableInfo'
              pure $ do
                Maybe
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationOrderBy <- Maybe
  (Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe
   (Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
 -> Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
aggregateFieldName Maybe Description
forall a. Maybe a
Nothing (Parser
  'Input
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable Parser
  'Input
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationParser)
                pure
                  $ ([OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
                    ( (OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
 -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> [a] -> [b]
map
                        ((OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
  -> AnnotatedOrderByItemG b (UnpreparedValue b))
 -> [OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
 -> [AnnotatedOrderByItemG b (UnpreparedValue b)])
-> (OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
    -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> [AnnotatedOrderByItemG b (UnpreparedValue b)]
forall a b. (a -> b) -> a -> b
$ (AnnotatedAggregateOrderBy b (UnpreparedValue b)
 -> AnnotatedOrderByElement b (UnpreparedValue b))
-> OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
-> AnnotatedOrderByItemG b (UnpreparedValue b)
forall a b. (a -> b) -> OrderByItemG b a -> OrderByItemG b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
                        ((AnnotatedAggregateOrderBy b (UnpreparedValue b)
  -> AnnotatedOrderByElement b (UnpreparedValue b))
 -> OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
 -> AnnotatedOrderByItemG b (UnpreparedValue b))
-> (AnnotatedAggregateOrderBy b (UnpreparedValue b)
    -> AnnotatedOrderByElement b (UnpreparedValue b))
-> OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
-> AnnotatedOrderByItemG b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ ComputedFieldOrderBy b (UnpreparedValue b)
-> AnnotatedOrderByElement b (UnpreparedValue b)
forall (b :: BackendType) v.
ComputedFieldOrderBy b v -> AnnotatedOrderByElement b v
IR.AOCComputedField
                        (ComputedFieldOrderBy b (UnpreparedValue b)
 -> AnnotatedOrderByElement b (UnpreparedValue b))
-> (AnnotatedAggregateOrderBy b (UnpreparedValue b)
    -> ComputedFieldOrderBy b (UnpreparedValue b))
-> AnnotatedAggregateOrderBy b (UnpreparedValue b)
-> AnnotatedOrderByElement b (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComputedFieldOrderByElement b (UnpreparedValue b)
-> ComputedFieldOrderBy b (UnpreparedValue b)
mkComputedFieldOrderBy
                        (ComputedFieldOrderByElement b (UnpreparedValue b)
 -> ComputedFieldOrderBy b (UnpreparedValue b))
-> (AnnotatedAggregateOrderBy b (UnpreparedValue b)
    -> ComputedFieldOrderByElement b (UnpreparedValue b))
-> AnnotatedAggregateOrderBy b (UnpreparedValue b)
-> ComputedFieldOrderBy b (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableName b
-> GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
-> AnnotatedAggregateOrderBy b (UnpreparedValue b)
-> ComputedFieldOrderByElement b (UnpreparedValue b)
forall (b :: BackendType) v.
TableName b
-> AnnBoolExp b v
-> AnnotatedAggregateOrderBy b v
-> ComputedFieldOrderByElement b v
IR.CFOBETableAggregation TableName b
table GBoolExp b (AnnBoolExpFld b (UnpreparedValue b))
newPerms
                    )
                    Maybe
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggregationOrderBy
            ComputedFieldReturnType b
ReturnsOthers -> MaybeT
  (SchemaT r m)
  (InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a. MaybeT (SchemaT r m) a
forall (f :: * -> *) a. Alternative f => f a
empty
        FIRemoteRelationship RemoteFieldInfo (DBJoinField b)
_ -> MaybeT
  (SchemaT r m)
  (InputFieldsParser
     MetadataObjId
     n
     (Maybe [AnnotatedOrderByItemG b (UnpreparedValue b)]))
forall a. MaybeT (SchemaT r m) a
forall (f :: * -> *) a. Alternative f => f a
empty

-- | Corresponds to an object type for an order by.
--
-- > input table_order_by {
-- >   col1: order_by
-- >   col2: order_by
-- >   .     .
-- >   .     .
-- >   coln: order_by
-- >   obj-rel: <remote-table>_order_by
-- > }
tableOrderByExp ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  TableInfo b ->
  SchemaT r m (Parser 'Input n [IR.AnnotatedOrderByItemG b (IR.UnpreparedValue b)])
tableOrderByExp :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
tableOrderByExp TableInfo b
tableInfo = do
  RoleName
roleName <- (SchemaContext -> RoleName) -> SchemaT r m RoleName
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaContext -> RoleName
scRole
  GQLNameIdentifier
tableGQLName <- TableInfo b -> SchemaT r m GQLNameIdentifier
forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName TableInfo b
tableInfo
  [FieldInfo b]
tableFields <- TableInfo b -> SchemaT r m [FieldInfo b]
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has SchemaContext r, Has (SourceInfo b) r) =>
TableInfo b -> m [FieldInfo b]
tableSelectFields TableInfo b
tableInfo
  let selectPermissions :: Maybe (SelPermInfo b)
selectPermissions = RoleName -> TableInfo b -> Maybe (SelPermInfo b)
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo b
tableInfo
  let description :: Description
description =
        Text -> Description
G.Description
          (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"Ordering options when selecting data from "
          Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
          TableName b -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
"."
      memoizeKey :: TableName b
memoizeKey = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
  GQLNameIdentifier
-> Description
-> Maybe (SelPermInfo b)
-> [FieldInfo b]
-> TableName b
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *) name.
(Ord name, Typeable name, MonadBuildSchema b r m n) =>
GQLNameIdentifier
-> Description
-> Maybe (SelPermInfo b)
-> [FieldInfo b]
-> name
-> SchemaT
     r m (Parser 'Input n [AnnotatedOrderByItemG b (UnpreparedValue b)])
orderByExpInternal GQLNameIdentifier
tableGQLName Description
description Maybe (SelPermInfo b)
selectPermissions [FieldInfo b]
tableFields TableName b
memoizeKey

-- FIXME!
-- those parsers are directly using Postgres' SQL representation of
-- order, rather than using a general intermediary representation

orderByAggregation ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  SourceInfo b ->
  TableInfo b ->
  SchemaT r m (Parser 'Input n [IR.OrderByItemG b (IR.AnnotatedAggregateOrderBy b (IR.UnpreparedValue b))])
orderByAggregation :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
SourceInfo b
-> TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
orderByAggregation SourceInfo b
sourceInfo TableInfo b
tableInfo = Name
-> (SourceName, TableName b)
-> SchemaT
     r
     m
     (Parser
        MetadataObjId
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> SchemaT
     r
     m
     (Parser
        MetadataObjId
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
 Typeable b) =>
Name -> a -> m (p n b) -> m (p n b)
P.memoizeOn 'orderByAggregation (SourceInfo b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo, TableName b
tableName) do
  -- WIP NOTE
  -- there is heavy duplication between this and Select.tableAggregationFields
  -- it might be worth putting some of it in common, just to avoid issues when
  -- we change one but not the other?
  GQLNameIdentifier
tableGQLName <- forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName @b TableInfo b
tableInfo
  let customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
      mkTypename :: MkTypename
mkTypename = ResolvedSourceCustomization -> MkTypename
_rscTypeNames ResolvedSourceCustomization
customization
  GQLNameIdentifier
tableIdentifierName <- forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName @b TableInfo b
tableInfo
  [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
allScalarColumns <- ((StructuredColumnInfo b, AnnRedactionExpUnpreparedValue b)
 -> Maybe (ColumnInfo b, AnnRedactionExpUnpreparedValue b))
-> [(StructuredColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
forall a b. (a -> Maybe b) -> [a] -> [b]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (\(StructuredColumnInfo b
column, AnnRedactionExpUnpreparedValue b
redactionExp) -> StructuredColumnInfo b
column StructuredColumnInfo b
-> Getting
     (First (ColumnInfo b)) (StructuredColumnInfo b) (ColumnInfo b)
-> Maybe (ColumnInfo b)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting
  (First (ColumnInfo b)) (StructuredColumnInfo b) (ColumnInfo b)
forall (b :: BackendType) (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (ColumnInfo b) (f (ColumnInfo b))
-> p (StructuredColumnInfo b) (f (StructuredColumnInfo b))
_SCIScalarColumn Maybe (ColumnInfo b)
-> (ColumnInfo b
    -> (ColumnInfo b, AnnRedactionExpUnpreparedValue b))
-> Maybe (ColumnInfo b, AnnRedactionExpUnpreparedValue b)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (,AnnRedactionExpUnpreparedValue b
redactionExp)) ([(StructuredColumnInfo b, AnnRedactionExpUnpreparedValue b)]
 -> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)])
-> SchemaT
     r m [(StructuredColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> SchemaT r m [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TableInfo b
-> SchemaT
     r m [(StructuredColumnInfo b, AnnRedactionExpUnpreparedValue b)]
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has SchemaContext r, Has (SourceInfo b) r) =>
TableInfo b
-> m [(StructuredColumnInfo b, AnnRedactionExpUnpreparedValue b)]
tableSelectColumns TableInfo b
tableInfo
  let numColumns :: Maybe
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
numColumns = NamingCase
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
stdAggOpColumns NamingCase
tCase ([(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
 -> Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall a b. (a -> b) -> a -> b
$ ((ColumnInfo b, AnnRedactionExpUnpreparedValue b) -> Bool)
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
forall a. (a -> Bool) -> [a] -> [a]
filter (ColumnInfo b -> Bool
forall (b :: BackendType). Backend b => ColumnInfo b -> Bool
isNumCol (ColumnInfo b -> Bool)
-> ((ColumnInfo b, AnnRedactionExpUnpreparedValue b)
    -> ColumnInfo b)
-> (ColumnInfo b, AnnRedactionExpUnpreparedValue b)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ColumnInfo b, AnnRedactionExpUnpreparedValue b) -> ColumnInfo b
forall a b. (a, b) -> a
fst) [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
allScalarColumns
      compColumns :: Maybe
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
compColumns = NamingCase
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
stdAggOpColumns NamingCase
tCase ([(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
 -> Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall a b. (a -> b) -> a -> b
$ ((ColumnInfo b, AnnRedactionExpUnpreparedValue b) -> Bool)
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
forall a. (a -> Bool) -> [a] -> [a]
filter (ColumnInfo b -> Bool
forall (b :: BackendType). Backend b => ColumnInfo b -> Bool
isComparableCol (ColumnInfo b -> Bool)
-> ((ColumnInfo b, AnnRedactionExpUnpreparedValue b)
    -> ColumnInfo b)
-> (ColumnInfo b, AnnRedactionExpUnpreparedValue b)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ColumnInfo b, AnnRedactionExpUnpreparedValue b) -> ColumnInfo b
forall a b. (a, b) -> a
fst) [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
allScalarColumns
      numOperatorsAndColumns :: HashMap
  GQLNameIdentifier
  (Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))
numOperatorsAndColumns = [(GQLNameIdentifier,
  Maybe
    (InputFieldsParser
       n
       [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b))]))]
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(GQLNameIdentifier,
   Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))]
 -> HashMap
      GQLNameIdentifier
      (Maybe
         (InputFieldsParser
            n
            [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
              (BasicOrderType b, NullsOrderType b))])))
-> [(GQLNameIdentifier,
     Maybe
       (InputFieldsParser
          n
          [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))]))]
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall a b. (a -> b) -> a -> b
$ (,Maybe
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
numColumns) (GQLNameIdentifier
 -> (GQLNameIdentifier,
     Maybe
       (InputFieldsParser
          n
          [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))])))
-> [GQLNameIdentifier]
-> [(GQLNameIdentifier,
     Maybe
       (InputFieldsParser
          n
          [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))]))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [GQLNameIdentifier]
numericAggOperators
      compOperatorsAndColumns :: HashMap
  GQLNameIdentifier
  (Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))
compOperatorsAndColumns = [(GQLNameIdentifier,
  Maybe
    (InputFieldsParser
       n
       [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b))]))]
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(GQLNameIdentifier,
   Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))]
 -> HashMap
      GQLNameIdentifier
      (Maybe
         (InputFieldsParser
            n
            [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
              (BasicOrderType b, NullsOrderType b))])))
-> [(GQLNameIdentifier,
     Maybe
       (InputFieldsParser
          n
          [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))]))]
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall a b. (a -> b) -> a -> b
$ (,Maybe
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
compColumns) (GQLNameIdentifier
 -> (GQLNameIdentifier,
     Maybe
       (InputFieldsParser
          n
          [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))])))
-> [GQLNameIdentifier]
-> [(GQLNameIdentifier,
     Maybe
       (InputFieldsParser
          n
          [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))]))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [GQLNameIdentifier]
comparisonAggOperators
      customOperatorsAndColumns :: HashMap
  GQLNameIdentifier
  (Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))
customOperatorsAndColumns =
        (Name -> GQLNameIdentifier)
-> HashMap
     Name
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall k2 k1 v.
(Eq k2, Hashable k2) =>
(k1 -> k2) -> HashMap k1 v -> HashMap k2 v
HashMap.mapKeys (Name -> GQLNameIdentifier
C.fromCustomName)
          (HashMap
   Name
   (Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
 -> HashMap
      GQLNameIdentifier
      (Maybe
         (InputFieldsParser
            n
            [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
              (BasicOrderType b, NullsOrderType b))])))
-> HashMap
     Name
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall a b. (a -> b) -> a -> b
$ NamingCase
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> HashMap (ScalarType b) (ScalarType b)
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
getCustomAggOpsColumns NamingCase
tCase [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
allScalarColumns
          (HashMap (ScalarType b) (ScalarType b)
 -> Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
-> HashMap Name (HashMap (ScalarType b) (ScalarType b))
-> HashMap
     Name
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (b :: BackendType).
Backend b =>
SourceConfig b
-> HashMap Name (HashMap (ScalarType b) (ScalarType b))
getCustomAggregateOperators @b (SourceInfo b -> SourceConfig b
forall (b :: BackendType). SourceInfo b -> SourceConfig b
_siConfiguration SourceInfo b
sourceInfo)
      allOperatorsAndColumns :: HashMap
  GQLNameIdentifier
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
allOperatorsAndColumns =
        HashMap
  GQLNameIdentifier
  (Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))
-> HashMap
     GQLNameIdentifier
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall k v. HashMap k (Maybe v) -> HashMap k v
HashMap.catMaybes
          (HashMap
   GQLNameIdentifier
   (Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
 -> HashMap
      GQLNameIdentifier
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
-> HashMap
     GQLNameIdentifier
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall a b. (a -> b) -> a -> b
$ (Maybe
   (InputFieldsParser
      n
      [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
        (BasicOrderType b, NullsOrderType b))])
 -> Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))])
 -> Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
-> [HashMap
      GQLNameIdentifier
      (Maybe
         (InputFieldsParser
            n
            [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
              (BasicOrderType b, NullsOrderType b))]))]
-> HashMap
     GQLNameIdentifier
     (Maybe
        (InputFieldsParser
           n
           [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
             (BasicOrderType b, NullsOrderType b))]))
forall k (t :: * -> *) v.
(Hashable k, Foldable t) =>
(v -> v -> v) -> t (HashMap k v) -> HashMap k v
HashMap.unionsWith Maybe
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall a. Semigroup a => a -> a -> a
(<>) [HashMap
  GQLNameIdentifier
  (Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))
numOperatorsAndColumns, HashMap
  GQLNameIdentifier
  (Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))
compOperatorsAndColumns, HashMap
  GQLNameIdentifier
  (Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))]))
customOperatorsAndColumns]
      aggFields :: InputFieldsParser
  MetadataObjId
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggFields =
        ([[Maybe
     [OrderByItemG
        b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
 -> [OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> InputFieldsParser
     MetadataObjId
     n
     [[Maybe
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
-> InputFieldsParser
     MetadataObjId
     n
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall a b.
(a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([[OrderByItemG
    b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[OrderByItemG
     b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
 -> [OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> ([[Maybe
        [OrderByItemG
           b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
    -> [[OrderByItemG
           b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
-> [[Maybe
       [OrderByItemG
          b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe
   [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
-> [[OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe
    [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
 -> [[OrderByItemG
        b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
-> ([[Maybe
        [OrderByItemG
           b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
    -> [Maybe
          [OrderByItemG
             b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
-> [[Maybe
       [OrderByItemG
          b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
-> [[OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Maybe
    [OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
-> [Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat)
          (InputFieldsParser
   MetadataObjId
   n
   [[Maybe
       [OrderByItemG
          b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
 -> InputFieldsParser
      MetadataObjId
      n
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> InputFieldsParser
     MetadataObjId
     n
     [[Maybe
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
-> InputFieldsParser
     MetadataObjId
     n
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall a b. (a -> b) -> a -> b
$ [InputFieldsParser
   MetadataObjId
   n
   [Maybe
      [OrderByItemG
         b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
-> InputFieldsParser
     MetadataObjId
     n
     [[Maybe
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA
          ([InputFieldsParser
    MetadataObjId
    n
    [Maybe
       [OrderByItemG
          b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
 -> InputFieldsParser
      MetadataObjId
      n
      [[Maybe
          [OrderByItemG
             b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]])
-> [InputFieldsParser
      MetadataObjId
      n
      [Maybe
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
-> InputFieldsParser
     MetadataObjId
     n
     [[Maybe
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
forall a b. (a -> b) -> a -> b
$ [Maybe
   (InputFieldsParser
      MetadataObjId
      n
      [Maybe
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])]
-> [InputFieldsParser
      MetadataObjId
      n
      [Maybe
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
            [ -- count
              InputFieldsParser
  MetadataObjId
  n
  [Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
-> Maybe
     (InputFieldsParser
        MetadataObjId
        n
        [Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
forall a. a -> Maybe a
Just
                (InputFieldsParser
   MetadataObjId
   n
   [Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
 -> Maybe
      (InputFieldsParser
         MetadataObjId
         n
         [Maybe
            [OrderByItemG
               b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]))
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
-> Maybe
     (InputFieldsParser
        MetadataObjId
        n
        [Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> Parser
     MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional
                  Name
Name._count
                  Maybe Description
forall a. Maybe a
Nothing
                  (forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator @b NamingCase
tCase SourceInfo b
sourceInfo)
                InputFieldsParser
  MetadataObjId
  n
  (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> [Maybe
          [OrderByItemG
             b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> Maybe
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> [Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
                (Maybe
   [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
 -> [Maybe
       [OrderByItemG
          b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe
         [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> [Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((BasicOrderType b, NullsOrderType b)
 -> [OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> Maybe (BasicOrderType b, NullsOrderType b)
-> Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
 -> [OrderByItemG
       b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> ((BasicOrderType b, NullsOrderType b)
    -> OrderByItemG
         b (AnnotatedAggregateOrderBy b (UnpreparedValue b)))
-> (BasicOrderType b, NullsOrderType b)
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: BackendType) a.
a -> (BasicOrderType b, NullsOrderType b) -> OrderByItemG b a
mkOrderByItemG @b AnnotatedAggregateOrderBy b (UnpreparedValue b)
forall (b :: BackendType) v. AnnotatedAggregateOrderBy b v
IR.AAOCount)
                (Maybe (BasicOrderType b, NullsOrderType b)
 -> Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (BasicOrderType b, NullsOrderType b)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join,
              -- other operators
              if HashMap
  GQLNameIdentifier
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
-> Bool
forall a. HashMap GQLNameIdentifier a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null HashMap
  GQLNameIdentifier
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
allOperatorsAndColumns
                then Maybe
  (InputFieldsParser
     MetadataObjId
     n
     [Maybe
        [OrderByItemG
           b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
forall a. Maybe a
Nothing
                else InputFieldsParser
  MetadataObjId
  n
  [Maybe
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
-> Maybe
     (InputFieldsParser
        MetadataObjId
        n
        [Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
forall a. a -> Maybe a
Just
                  (InputFieldsParser
   MetadataObjId
   n
   [Maybe
      [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
 -> Maybe
      (InputFieldsParser
         MetadataObjId
         n
         [Maybe
            [OrderByItemG
               b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]))
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
-> Maybe
     (InputFieldsParser
        MetadataObjId
        n
        [Maybe
           [OrderByItemG
              b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]])
forall a b. (a -> b) -> a -> b
$ [(GQLNameIdentifier,
  InputFieldsParser
    n
    [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
      (BasicOrderType b, NullsOrderType b))])]
-> ((GQLNameIdentifier,
     InputFieldsParser
       n
       [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b))])
    -> InputFieldsParser
         MetadataObjId
         n
         (Maybe
            [OrderByItemG
               b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for (HashMap
  GQLNameIdentifier
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
-> [(GQLNameIdentifier,
     InputFieldsParser
       n
       [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b))])]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList HashMap
  GQLNameIdentifier
  (InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
allOperatorsAndColumns) \(GQLNameIdentifier
operator, InputFieldsParser
  n
  [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
    (BasicOrderType b, NullsOrderType b))]
fields) -> do
                    MkTypename
-> GQLNameIdentifier
-> GQLNameIdentifier
-> NamingCase
-> InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
parseOperator MkTypename
mkTypename GQLNameIdentifier
operator GQLNameIdentifier
tableGQLName NamingCase
tCase InputFieldsParser
  n
  [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
    (BasicOrderType b, NullsOrderType b))]
fields
            ]
  let objectName :: Name
objectName = MkTypename -> Name -> Name
runMkTypename MkTypename
mkTypename (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier
mkTableAggregateOrderByTypeName GQLNameIdentifier
tableIdentifierName
      description :: Description
description = Text -> Description
G.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"order by aggregate values of table " Text -> TableName b -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName b
tableName
  Parser
  MetadataObjId
  'Input
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> SchemaT
     r
     m
     (Parser
        MetadataObjId
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser
   MetadataObjId
   'Input
   n
   [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
 -> SchemaT
      r
      m
      (Parser
         MetadataObjId
         'Input
         n
         [OrderByItemG
            b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]))
-> Parser
     MetadataObjId
     'Input
     n
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> SchemaT
     r
     m
     (Parser
        MetadataObjId
        'Input
        n
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
-> Parser
     MetadataObjId
     'Input
     n
     [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
objectName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
description) InputFieldsParser
  MetadataObjId
  n
  [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
aggFields
  where
    tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo

    stdAggOpColumns ::
      NamingCase ->
      [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)] ->
      Maybe (InputFieldsParser n [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b, (BasicOrderType b, NullsOrderType b))])
    stdAggOpColumns :: NamingCase
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
stdAggOpColumns NamingCase
tCase [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
columns =
      [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
columns
        -- ALl std aggregate functions return the same type as the column used with it
        [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> ([(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
    -> [(ColumnInfo b, ColumnType b,
         AnnRedactionExpUnpreparedValue b)])
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
forall a b. a -> (a -> b) -> b
& ((ColumnInfo b, AnnRedactionExpUnpreparedValue b)
 -> (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b))
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(ColumnInfo b
colInfo, AnnRedactionExpUnpreparedValue b
redactionExp) -> (ColumnInfo b
colInfo, ColumnInfo b -> ColumnType b
forall (b :: BackendType). ColumnInfo b -> ColumnType b
ciType ColumnInfo b
colInfo, AnnRedactionExpUnpreparedValue b
redactionExp))
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
-> ([(ColumnInfo b, ColumnType b,
      AnnRedactionExpUnpreparedValue b)]
    -> Maybe
         (InputFieldsParser
            n
            [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
              (BasicOrderType b, NullsOrderType b))]))
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall a b. a -> (a -> b) -> b
& NamingCase
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
mkAgOpsFields NamingCase
tCase

    -- Build an InputFieldsParser only if the column list is non-empty
    mkAgOpsFields ::
      NamingCase ->
      -- Assoc list of column types with the type returned by the aggregate function when it is applied to that column
      [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)] ->
      Maybe (InputFieldsParser n [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b, (BasicOrderType b, NullsOrderType b))])
    mkAgOpsFields :: NamingCase
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
mkAgOpsFields NamingCase
tCase =
      (NonEmpty
   (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
 -> InputFieldsParser
      n
      [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
        (BasicOrderType b, NullsOrderType b))])
-> Maybe
     (NonEmpty
        (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b))
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((NonEmpty
   (Maybe
      (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b)))
 -> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
      (BasicOrderType b, NullsOrderType b))])
-> InputFieldsParser
     MetadataObjId
     n
     (NonEmpty
        (Maybe
           (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))))
-> InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
forall a b.
(a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Maybe
   (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
    (BasicOrderType b, NullsOrderType b))]
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
     (BasicOrderType b, NullsOrderType b))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe
    (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
     (BasicOrderType b, NullsOrderType b))]
 -> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
      (BasicOrderType b, NullsOrderType b))])
-> (NonEmpty
      (Maybe
         (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b)))
    -> [Maybe
          (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))])
-> NonEmpty
     (Maybe
        (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b)))
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
     (BasicOrderType b, NullsOrderType b))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty
  (Maybe
     (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
      (BasicOrderType b, NullsOrderType b)))
-> [Maybe
      (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList) (InputFieldsParser
   MetadataObjId
   n
   (NonEmpty
      (Maybe
         (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))))
 -> InputFieldsParser
      n
      [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
        (BasicOrderType b, NullsOrderType b))])
-> (NonEmpty
      (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
    -> InputFieldsParser
         MetadataObjId
         n
         (NonEmpty
            (Maybe
               (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
                (BasicOrderType b, NullsOrderType b)))))
-> NonEmpty
     (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
-> InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
 -> InputFieldsParser
      MetadataObjId
      n
      (Maybe
         (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))))
-> NonEmpty
     (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
-> InputFieldsParser
     MetadataObjId
     n
     (NonEmpty
        (Maybe
           (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
            (BasicOrderType b, NullsOrderType b))))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonEmpty a -> f (NonEmpty b)
traverse (NamingCase
-> (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b)))
mkField NamingCase
tCase)) (Maybe
   (NonEmpty
      (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b))
 -> Maybe
      (InputFieldsParser
         n
         [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
           (BasicOrderType b, NullsOrderType b))]))
-> ([(ColumnInfo b, ColumnType b,
      AnnRedactionExpUnpreparedValue b)]
    -> Maybe
         (NonEmpty
            (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)))
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (NonEmpty
        (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b))
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty

    getCustomAggOpsColumns ::
      NamingCase ->
      -- All columns
      [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)] ->
      -- Map of type the aggregate function accepts to the type it returns
      HashMap (ScalarType b) (ScalarType b) ->
      Maybe (InputFieldsParser n [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b, (BasicOrderType b, NullsOrderType b))])
    getCustomAggOpsColumns :: NamingCase
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> HashMap (ScalarType b) (ScalarType b)
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
getCustomAggOpsColumns NamingCase
tCase [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
allColumns HashMap (ScalarType b) (ScalarType b)
typeMap =
      [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
allColumns
        -- Filter by columns with a scalar type supported by this aggregate function
        -- and retrieve the result type of the aggregate function
        [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> ([(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
    -> [(ColumnInfo b, ColumnType b,
         AnnRedactionExpUnpreparedValue b)])
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
forall a b. a -> (a -> b) -> b
& ((ColumnInfo b, AnnRedactionExpUnpreparedValue b)
 -> Maybe
      (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b))
-> [(ColumnInfo b, AnnRedactionExpUnpreparedValue b)]
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
forall a b. (a -> Maybe b) -> [a] -> [b]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe
          ( \(ColumnInfo b
columnInfo, AnnRedactionExpUnpreparedValue b
redactionExp) ->
              case ColumnInfo b -> ColumnType b
forall (b :: BackendType). ColumnInfo b -> ColumnType b
ciType ColumnInfo b
columnInfo of
                ColumnEnumReference EnumReference b
_ -> Maybe
  (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
forall a. Maybe a
Nothing
                ColumnScalar ScalarType b
scalarType ->
                  (\ScalarType b
resultType -> (ColumnInfo b
columnInfo, ScalarType b -> ColumnType b
forall (b :: BackendType). ScalarType b -> ColumnType b
ColumnScalar ScalarType b
resultType, AnnRedactionExpUnpreparedValue b
redactionExp)) (ScalarType b
 -> (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b))
-> Maybe (ScalarType b)
-> Maybe
     (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ScalarType b
-> HashMap (ScalarType b) (ScalarType b) -> Maybe (ScalarType b)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup ScalarType b
scalarType HashMap (ScalarType b) (ScalarType b)
typeMap
          )
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
-> ([(ColumnInfo b, ColumnType b,
      AnnRedactionExpUnpreparedValue b)]
    -> Maybe
         (InputFieldsParser
            n
            [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
              (BasicOrderType b, NullsOrderType b))]))
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall a b. a -> (a -> b) -> b
& NamingCase
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)]
-> Maybe
     (InputFieldsParser
        n
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
mkAgOpsFields NamingCase
tCase

    mkField ::
      NamingCase ->
      (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b) ->
      InputFieldsParser n (Maybe (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b, (BasicOrderType b, NullsOrderType b)))
    mkField :: NamingCase
-> (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b)
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b)))
mkField NamingCase
tCase (ColumnInfo b
columnInfo, ColumnType b
resultType, AnnRedactionExpUnpreparedValue b
redactionExp) =
      Name
-> Maybe Description
-> Parser
     MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional
        (ColumnInfo b -> Name
forall (b :: BackendType). ColumnInfo b -> Name
ciName ColumnInfo b
columnInfo)
        (ColumnInfo b -> Maybe Description
forall (b :: BackendType). ColumnInfo b -> Maybe Description
ciDescription ColumnInfo b
columnInfo)
        (forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator @b NamingCase
tCase SourceInfo b
sourceInfo)
        InputFieldsParser
  MetadataObjId
  n
  (Maybe (Maybe (BasicOrderType b, NullsOrderType b)))
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe
         (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b)))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
         (BasicOrderType b, NullsOrderType b)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> ((BasicOrderType b, NullsOrderType b)
 -> (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
     (BasicOrderType b, NullsOrderType b)))
-> Maybe (BasicOrderType b, NullsOrderType b)
-> Maybe
     (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
      (BasicOrderType b, NullsOrderType b))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ColumnInfo b
columnInfo,ColumnType b
resultType,AnnRedactionExpUnpreparedValue b
redactionExp,)
        (Maybe (BasicOrderType b, NullsOrderType b)
 -> Maybe
      (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b)))
-> (Maybe (Maybe (BasicOrderType b, NullsOrderType b))
    -> Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe
     (ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
      (BasicOrderType b, NullsOrderType b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Maybe (BasicOrderType b, NullsOrderType b))
-> Maybe (BasicOrderType b, NullsOrderType b)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join

    parseOperator ::
      MkTypename ->
      C.GQLNameIdentifier ->
      C.GQLNameIdentifier ->
      NamingCase ->
      InputFieldsParser n [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b, (BasicOrderType b, NullsOrderType b))] ->
      InputFieldsParser n (Maybe [IR.OrderByItemG b (IR.AnnotatedAggregateOrderBy b (IR.UnpreparedValue b))])
    parseOperator :: MkTypename
-> GQLNameIdentifier
-> GQLNameIdentifier
-> NamingCase
-> InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
parseOperator MkTypename
makeTypename GQLNameIdentifier
operator GQLNameIdentifier
tableGQLName NamingCase
tCase InputFieldsParser
  n
  [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
    (BasicOrderType b, NullsOrderType b))]
columns =
      let opText :: Text
opText = Name -> Text
G.unName (Name -> Text) -> Name -> Text
forall a b. (a -> b) -> a -> b
$ NamingCase -> GQLNameIdentifier -> Name
applyFieldNameCaseIdentifier NamingCase
tCase GQLNameIdentifier
operator
          opTypeName :: Name
opTypeName = NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier -> GQLNameIdentifier
mkTableAggregateOrderByOpTypeName GQLNameIdentifier
tableGQLName GQLNameIdentifier
operator
          opFieldName :: Name
opFieldName = NamingCase -> GQLNameIdentifier -> Name
applyFieldNameCaseIdentifier NamingCase
tCase GQLNameIdentifier
operator
          objectName :: Name
objectName = MkTypename -> Name -> Name
runMkTypename MkTypename
makeTypename Name
opTypeName
          objectDesc :: Maybe Description
objectDesc = Description -> Maybe Description
forall a. a -> Maybe a
Just (Description -> Maybe Description)
-> Description -> Maybe Description
forall a b. (a -> b) -> a -> b
$ Text -> Description
G.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"order by " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
opText Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"() on columns of table " Text -> TableName b -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName b
tableName
       in Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
          (BasicOrderType b, NullsOrderType b))])
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
opFieldName Maybe Description
forall a. Maybe a
Nothing (Name
-> Maybe Description
-> InputFieldsParser
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
-> Parser
     MetadataObjId
     'Input
     n
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))]
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
objectName Maybe Description
objectDesc InputFieldsParser
  n
  [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
    (BasicOrderType b, NullsOrderType b))]
columns)
            InputFieldsParser
  MetadataObjId
  n
  (Maybe
     [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
       (BasicOrderType b, NullsOrderType b))])
-> ([(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
      (BasicOrderType b, NullsOrderType b))]
    -> [OrderByItemG
          b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        [OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))])
forall (m :: * -> *) a b.
Functor m =>
InputFieldsParser m (Maybe a)
-> (a -> b) -> InputFieldsParser m (Maybe b)
`mapField` ((ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
  (BasicOrderType b, NullsOrderType b))
 -> OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b)))
-> [(ColumnInfo b, ColumnType b, AnnRedactionExpUnpreparedValue b,
     (BasicOrderType b, NullsOrderType b))]
-> [OrderByItemG
      b (AnnotatedAggregateOrderBy b (UnpreparedValue b))]
forall a b. (a -> b) -> [a] -> [b]
map (\(ColumnInfo b
col, ColumnType b
resultType, AnnRedactionExpUnpreparedValue b
redactionExp, (BasicOrderType b, NullsOrderType b)
info) -> AnnotatedAggregateOrderBy b (UnpreparedValue b)
-> (BasicOrderType b, NullsOrderType b)
-> OrderByItemG b (AnnotatedAggregateOrderBy b (UnpreparedValue b))
forall (b :: BackendType) a.
a -> (BasicOrderType b, NullsOrderType b) -> OrderByItemG b a
mkOrderByItemG (AggregateOrderByColumn b (UnpreparedValue b)
-> AnnotatedAggregateOrderBy b (UnpreparedValue b)
forall (b :: BackendType) v.
AggregateOrderByColumn b v -> AnnotatedAggregateOrderBy b v
IR.AAOOp (AggregateOrderByColumn b (UnpreparedValue b)
 -> AnnotatedAggregateOrderBy b (UnpreparedValue b))
-> AggregateOrderByColumn b (UnpreparedValue b)
-> AnnotatedAggregateOrderBy b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ Text
-> ColumnType b
-> ColumnInfo b
-> AnnRedactionExpUnpreparedValue b
-> AggregateOrderByColumn b (UnpreparedValue b)
forall (b :: BackendType) v.
Text
-> ColumnType b
-> ColumnInfo b
-> AnnRedactionExp b v
-> AggregateOrderByColumn b v
IR.AggregateOrderByColumn Text
opText ColumnType b
resultType ColumnInfo b
col AnnRedactionExpUnpreparedValue b
redactionExp) (BasicOrderType b, NullsOrderType b)
info)

orderByOperatorsHasuraCase ::
  forall b n.
  (BackendSchema b, MonadParse n) =>
  SourceInfo b ->
  Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperatorsHasuraCase :: forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperatorsHasuraCase = forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator' @b NamingCase
HasuraCase

orderByOperatorsGraphqlCase ::
  forall b n.
  (BackendSchema b, MonadParse n) =>
  SourceInfo b ->
  Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperatorsGraphqlCase :: forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperatorsGraphqlCase = forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator' @b NamingCase
GraphqlCase

orderByOperator' ::
  forall b n.
  (BackendSchema b, MonadParse n) =>
  NamingCase ->
  SourceInfo b ->
  Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator' :: forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
NamingCase
-> SourceInfo b
-> Parser 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
orderByOperator' NamingCase
tCase SourceInfo b
sourceInfo =
  let (Name
sourcePrefix, NonEmpty
  (Definition EnumValueInfo, (BasicOrderType b, NullsOrderType b))
orderOperators) = forall (b :: BackendType).
BackendSchema b =>
SourceInfo b
-> NamingCase
-> (Name,
    NonEmpty
      (Definition EnumValueInfo, (BasicOrderType b, NullsOrderType b)))
orderByOperators @b SourceInfo b
sourceInfo NamingCase
tCase
   in Parser MetadataObjId 'Both n (BasicOrderType b, NullsOrderType b)
-> Parser
     MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable (Parser MetadataObjId 'Both n (BasicOrderType b, NullsOrderType b)
 -> Parser
      MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b)))
-> Parser
     MetadataObjId 'Both n (BasicOrderType b, NullsOrderType b)
-> Parser
     MetadataObjId 'Both n (Maybe (BasicOrderType b, NullsOrderType b))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> NonEmpty
     (Definition EnumValueInfo, (BasicOrderType b, NullsOrderType b))
-> Parser
     MetadataObjId 'Both n (BasicOrderType b, NullsOrderType b)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> NonEmpty (Definition origin EnumValueInfo, a)
-> Parser origin 'Both m a
P.enum (NamingCase -> Name -> Name
applyTypeNameCaseCust NamingCase
tCase Name
sourcePrefix) (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
"column ordering options") (NonEmpty
   (Definition EnumValueInfo, (BasicOrderType b, NullsOrderType b))
 -> Parser
      MetadataObjId 'Both n (BasicOrderType b, NullsOrderType b))
-> NonEmpty
     (Definition EnumValueInfo, (BasicOrderType b, NullsOrderType b))
-> Parser
     MetadataObjId 'Both n (BasicOrderType b, NullsOrderType b)
forall a b. (a -> b) -> a -> b
$ NonEmpty
  (Definition EnumValueInfo, (BasicOrderType b, NullsOrderType b))
orderOperators

mkOrderByItemG :: forall b a. a -> (BasicOrderType b, NullsOrderType b) -> IR.OrderByItemG b a
mkOrderByItemG :: forall (b :: BackendType) a.
a -> (BasicOrderType b, NullsOrderType b) -> OrderByItemG b a
mkOrderByItemG a
column (BasicOrderType b
orderType, NullsOrderType b
nullsOrder) =
  IR.OrderByItemG
    { obiType :: Maybe (BasicOrderType b)
obiType = BasicOrderType b -> Maybe (BasicOrderType b)
forall a. a -> Maybe a
Just BasicOrderType b
orderType,
      obiColumn :: a
obiColumn = a
column,
      obiNulls :: Maybe (NullsOrderType b)
obiNulls = NullsOrderType b -> Maybe (NullsOrderType b)
forall a. a -> Maybe a
Just NullsOrderType b
nullsOrder
    }