{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE ViewPatterns #-}

module Hasura.Backends.Postgres.Schema.Select
  ( selectFunction,
    selectFunctionAggregate,
    selectFunctionConnection,
    computedFieldPG,
    buildFunctionQueryFieldsPG,
    buildFunctionMutationFieldsPG,
  )
where

import Control.Lens hiding (index)
import Data.Has (getter)
import Data.HashMap.Strict.Extended qualified as HashMap
import Data.Sequence qualified as Seq
import Data.Text.Casing qualified as C
import Data.Text.Extended
import Data.Traversable (mapAccumL)
import Hasura.Backends.Postgres.SQL.Types qualified as Postgres
import Hasura.Backends.Postgres.Types.ComputedField qualified as Postgres
import Hasura.Backends.Postgres.Types.Function qualified as Postgres
import Hasura.Base.Error
import Hasura.Function.Cache
import Hasura.GraphQL.Schema.Backend
import Hasura.GraphQL.Schema.BoolExp
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.Parser
  ( FieldParser,
    InputFieldsParser,
  )
import Hasura.GraphQL.Schema.Parser qualified as P
import Hasura.GraphQL.Schema.Select
import Hasura.GraphQL.Schema.Table
import Hasura.GraphQL.Schema.Typename
import Hasura.Name qualified as Name
import Hasura.Prelude
import Hasura.RQL.IR
import Hasura.RQL.IR qualified as IR
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Column
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.ComputedField
import Hasura.RQL.Types.Schema.Options qualified as Options
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

-- | User-defined function (AKA custom function)
selectFunction ::
  forall r m n pgKind.
  ( MonadBuildSchema ('Postgres pgKind) r m n,
    BackendTableSelectSchema ('Postgres pgKind)
  ) =>
  MkRootFieldName ->
  -- | SQL function info
  FunctionInfo ('Postgres pgKind) ->
  -- | field description, if any
  Maybe G.Description ->
  SchemaT r m (Maybe (FieldParser n (SelectExp ('Postgres pgKind))))
selectFunction :: forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r m (Maybe (FieldParser n (SelectExp ('Postgres pgKind))))
selectFunction MkRootFieldName
mkRootFieldName fi :: FunctionInfo ('Postgres pgKind)
fi@FunctionInfo {Maybe Text
FunctionPermissionsMap
Seq (FunctionInputArgument ('Postgres pgKind))
Name
SystemDefined
JsonAggSelect
TableName ('Postgres pgKind)
FunctionName ('Postgres pgKind)
FunctionExposedAs
FunctionVolatility
_fiSQLName :: FunctionName ('Postgres pgKind)
_fiGQLName :: Name
_fiGQLArgsName :: Name
_fiGQLAggregateName :: Name
_fiSystemDefined :: SystemDefined
_fiVolatility :: FunctionVolatility
_fiExposedAs :: FunctionExposedAs
_fiInputArgs :: Seq (FunctionInputArgument ('Postgres pgKind))
_fiReturnType :: TableName ('Postgres pgKind)
_fiDescription :: Maybe Text
_fiPermissions :: FunctionPermissionsMap
_fiJsonAggSelect :: JsonAggSelect
_fiComment :: Maybe Text
_fiSQLName :: forall (b :: BackendType). FunctionInfo b -> FunctionName b
_fiGQLName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLArgsName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLAggregateName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiSystemDefined :: forall (b :: BackendType). FunctionInfo b -> SystemDefined
_fiVolatility :: forall (b :: BackendType). FunctionInfo b -> FunctionVolatility
_fiExposedAs :: forall (b :: BackendType). FunctionInfo b -> FunctionExposedAs
_fiInputArgs :: forall (b :: BackendType).
FunctionInfo b -> Seq (FunctionInputArgument b)
_fiReturnType :: forall (b :: BackendType). FunctionInfo b -> TableName b
_fiDescription :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiPermissions :: forall (b :: BackendType). FunctionInfo b -> FunctionPermissionsMap
_fiJsonAggSelect :: forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiComment :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
..} Maybe Description
description = MaybeT (SchemaT r m) (FieldParser n (SelectExp ('Postgres pgKind)))
-> SchemaT
     r m (Maybe (FieldParser n (SelectExp ('Postgres pgKind))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
  SourceInfo ('Postgres pgKind)
sourceInfo :: SourceInfo ('Postgres pgKind) <- (r -> SourceInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SourceInfo ('Postgres pgKind))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo ('Postgres pgKind)
forall a t. Has a t => t -> a
getter
  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
  let customization :: ResolvedSourceCustomization
customization = SourceInfo ('Postgres pgKind) -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo ('Postgres pgKind)
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
  TableInfo ('Postgres pgKind)
tableInfo <- SchemaT r m (TableInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind))
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 (TableInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind)))
-> SchemaT r m (TableInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ TableName ('Postgres pgKind)
-> SchemaT r m (TableInfo ('Postgres pgKind))
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName ('Postgres pgKind)
_fiReturnType
  SelPermInfo ('Postgres pgKind)
selectPermissions <- Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind)))
-> Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ RoleName
-> TableInfo ('Postgres pgKind)
-> Maybe (SelPermInfo ('Postgres pgKind))
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo ('Postgres pgKind)
tableInfo
  Parser 'Output n (AnnotatedFields ('Postgres pgKind))
selectionSetParser <- SchemaT
  r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Output n (AnnotatedFields ('Postgres pgKind)))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT
   r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
 -> MaybeT
      (SchemaT r m)
      (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Output n (AnnotatedFields ('Postgres pgKind)))
forall a b. (a -> b) -> a -> b
$ TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
returnFunctionParser TableInfo ('Postgres pgKind)
tableInfo
  SchemaT r m (FieldParser n (SelectExp ('Postgres pgKind)))
-> MaybeT
     (SchemaT r m) (FieldParser n (SelectExp ('Postgres pgKind)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift do
    StringifyNumbers
stringifyNumbers <- (SchemaOptions -> StringifyNumbers) -> SchemaT r m StringifyNumbers
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaOptions -> StringifyNumbers
Options.soStringifyNumbers
    InputFieldsParser
  n
  (SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
tableArgsParser <- TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema ('Postgres pgKind) r m n =>
TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendTableSelectSchema b, MonadBuildSourceSchema b r m n) =>
TableInfo b
-> SchemaT
     r m (InputFieldsParser n (SelectArgsG b (UnpreparedValue b)))
tableArguments TableInfo ('Postgres pgKind)
tableInfo
    InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser <- FunctionInfo ('Postgres pgKind)
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall (pgKind :: PostgresKind) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema ('Postgres pgKind) r m n =>
FunctionInfo ('Postgres pgKind)
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
customSQLFunctionArgs FunctionInfo ('Postgres pgKind)
fi Name
_fiGQLName Name
_fiGQLArgsName
    let argsParser :: InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
argsParser = (FunctionArgsExpG
   (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> SelectArgsG
      ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
 -> (FunctionArgsExpG
       (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
     SelectArgsG
       ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     n
     (SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
forall a b c.
(a -> b -> c)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
-> InputFieldsParser MetadataObjId n c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser InputFieldsParser
  n
  (SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
tableArgsParser
        functionFieldName :: Name
functionFieldName = MkRootFieldName -> Name -> Name
runMkRootFieldName MkRootFieldName
mkRootFieldName Name
_fiGQLName
    pure
      $ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> Parser 'Output n (AnnotatedFields ('Postgres pgKind))
-> FieldParser
     MetadataObjId
     n
     ((FunctionArgsExpG
         (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
       SelectArgsG
         ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
      AnnotatedFields ('Postgres pgKind))
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
functionFieldName Maybe Description
description InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
argsParser Parser 'Output n (AnnotatedFields ('Postgres pgKind))
selectionSetParser
      FieldParser
  MetadataObjId
  n
  ((FunctionArgsExpG
      (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
    SelectArgsG
      ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
   AnnotatedFields ('Postgres pgKind))
-> (((FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
     AnnotatedFields ('Postgres pgKind))
    -> SelectExp ('Postgres pgKind))
-> FieldParser n (SelectExp ('Postgres pgKind))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \((FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
funcArgs, SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
tableArgs'), AnnotatedFields ('Postgres pgKind)
fields) ->
        IR.AnnSelectG
          { $sel:_asnFields:AnnSelectG :: AnnotatedFields ('Postgres pgKind)
IR._asnFields = AnnotatedFields ('Postgres pgKind)
fields,
            $sel:_asnFrom:AnnSelectG :: SelectFromG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnFrom = FunctionName ('Postgres pgKind)
-> FunctionArgsExp
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
-> Maybe
     [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
-> SelectFromG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) v.
FunctionName b
-> FunctionArgsExp b v
-> Maybe [(Column b, ScalarType b)]
-> SelectFromG b v
IR.FromFunction FunctionName ('Postgres pgKind)
_fiSQLName FunctionArgsExp
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
funcArgs Maybe [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
Maybe [(PGCol, PGScalarType)]
forall a. Maybe a
Nothing,
            $sel:_asnPerm:AnnSelectG :: TablePermG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnPerm = SelPermInfo ('Postgres pgKind)
-> TablePermG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType).
Backend b =>
SelPermInfo b -> TablePerms b
tablePermissionsInfo SelPermInfo ('Postgres pgKind)
selectPermissions,
            $sel:_asnArgs:AnnSelectG :: SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnArgs = SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
tableArgs',
            $sel:_asnStrfyNum:AnnSelectG :: StringifyNumbers
IR._asnStrfyNum = StringifyNumbers
stringifyNumbers,
            $sel:_asnNamingConvention:AnnSelectG :: Maybe NamingCase
IR._asnNamingConvention = NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase
          }
  where
    returnFunctionParser :: TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
returnFunctionParser =
      case JsonAggSelect
_fiJsonAggSelect of
        JsonAggSelect
JASSingleObject -> TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema ('Postgres pgKind) r m n =>
TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendTableSelectSchema b, MonadBuildSourceSchema b r m n) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
tableSelectionSet
        JsonAggSelect
JASMultipleRows -> TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
tableSelectionList

selectFunctionAggregate ::
  forall r m n pgKind.
  ( MonadBuildSchema ('Postgres pgKind) r m n,
    BackendTableSelectSchema ('Postgres pgKind)
  ) =>
  MkRootFieldName ->
  -- | SQL function info
  FunctionInfo ('Postgres pgKind) ->
  -- | field description, if any
  Maybe G.Description ->
  SchemaT r m (Maybe (FieldParser n (AggSelectExp ('Postgres pgKind))))
selectFunctionAggregate :: forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r m (Maybe (FieldParser n (AggSelectExp ('Postgres pgKind))))
selectFunctionAggregate MkRootFieldName
mkRootFieldName fi :: FunctionInfo ('Postgres pgKind)
fi@FunctionInfo {Maybe Text
FunctionPermissionsMap
Seq (FunctionInputArgument ('Postgres pgKind))
Name
SystemDefined
JsonAggSelect
TableName ('Postgres pgKind)
FunctionName ('Postgres pgKind)
FunctionExposedAs
FunctionVolatility
_fiSQLName :: forall (b :: BackendType). FunctionInfo b -> FunctionName b
_fiGQLName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLArgsName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLAggregateName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiSystemDefined :: forall (b :: BackendType). FunctionInfo b -> SystemDefined
_fiVolatility :: forall (b :: BackendType). FunctionInfo b -> FunctionVolatility
_fiExposedAs :: forall (b :: BackendType). FunctionInfo b -> FunctionExposedAs
_fiInputArgs :: forall (b :: BackendType).
FunctionInfo b -> Seq (FunctionInputArgument b)
_fiReturnType :: forall (b :: BackendType). FunctionInfo b -> TableName b
_fiDescription :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiPermissions :: forall (b :: BackendType). FunctionInfo b -> FunctionPermissionsMap
_fiJsonAggSelect :: forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiComment :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiSQLName :: FunctionName ('Postgres pgKind)
_fiGQLName :: Name
_fiGQLArgsName :: Name
_fiGQLAggregateName :: Name
_fiSystemDefined :: SystemDefined
_fiVolatility :: FunctionVolatility
_fiExposedAs :: FunctionExposedAs
_fiInputArgs :: Seq (FunctionInputArgument ('Postgres pgKind))
_fiReturnType :: TableName ('Postgres pgKind)
_fiDescription :: Maybe Text
_fiPermissions :: FunctionPermissionsMap
_fiJsonAggSelect :: JsonAggSelect
_fiComment :: Maybe Text
..} Maybe Description
description = MaybeT
  (SchemaT r m) (FieldParser n (AggSelectExp ('Postgres pgKind)))
-> SchemaT
     r m (Maybe (FieldParser n (AggSelectExp ('Postgres pgKind))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
  SourceInfo ('Postgres pgKind)
sourceInfo :: SourceInfo ('Postgres pgKind) <- (r -> SourceInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SourceInfo ('Postgres pgKind))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo ('Postgres pgKind)
forall a t. Has a t => t -> a
getter
  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
  let customization :: ResolvedSourceCustomization
customization = SourceInfo ('Postgres pgKind) -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo ('Postgres pgKind)
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

  TableInfo ('Postgres pgKind)
targetTableInfo <- TableName ('Postgres pgKind)
-> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind))
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName ('Postgres pgKind)
_fiReturnType

  SelPermInfo ('Postgres pgKind)
selectPermissions <- Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind)))
-> Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ RoleName
-> TableInfo ('Postgres pgKind)
-> Maybe (SelPermInfo ('Postgres pgKind))
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo ('Postgres pgKind)
targetTableInfo
  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
$ SelPermInfo ('Postgres pgKind) -> Bool
forall (b :: BackendType). SelPermInfo b -> Bool
spiAllowAgg SelPermInfo ('Postgres pgKind)
selectPermissions
  ()
xNodesAgg <- Maybe (XNodesAgg ('Postgres pgKind))
-> MaybeT (SchemaT r m) (XNodesAgg ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (XNodesAgg ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (XNodesAgg ('Postgres pgKind)))
-> Maybe (XNodesAgg ('Postgres pgKind))
-> MaybeT (SchemaT r m) (XNodesAgg ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType). BackendSchema b => Maybe (XNodesAgg b)
nodesAggExtension @('Postgres pgKind)
  Parser 'Output n (AnnotatedFields ('Postgres pgKind))
nodesParser <- SchemaT
  r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Output n (AnnotatedFields ('Postgres pgKind)))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT
   r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
 -> MaybeT
      (SchemaT r m)
      (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Output n (AnnotatedFields ('Postgres pgKind)))
forall a b. (a -> b) -> a -> b
$ TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
tableSelectionList TableInfo ('Postgres pgKind)
targetTableInfo
  SchemaT r m (FieldParser n (AggSelectExp ('Postgres pgKind)))
-> MaybeT
     (SchemaT r m) (FieldParser n (AggSelectExp ('Postgres pgKind)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift do
    StringifyNumbers
stringifyNumbers <- (SchemaOptions -> StringifyNumbers) -> SchemaT r m StringifyNumbers
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaOptions -> StringifyNumbers
Options.soStringifyNumbers
    GQLNameIdentifier
tableGQLName <- TableInfo ('Postgres pgKind) -> SchemaT r m GQLNameIdentifier
forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName TableInfo ('Postgres pgKind)
targetTableInfo
    InputFieldsParser
  n
  (SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
tableArgsParser <- TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema ('Postgres pgKind) r m n =>
TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendTableSelectSchema b, MonadBuildSourceSchema b r m n) =>
TableInfo b
-> SchemaT
     r m (InputFieldsParser n (SelectArgsG b (UnpreparedValue b)))
tableArguments TableInfo ('Postgres pgKind)
targetTableInfo
    InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser <- FunctionInfo ('Postgres pgKind)
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall (pgKind :: PostgresKind) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema ('Postgres pgKind) r m n =>
FunctionInfo ('Postgres pgKind)
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
customSQLFunctionArgs FunctionInfo ('Postgres pgKind)
fi Name
_fiGQLAggregateName Name
_fiGQLArgsName
    Parser
  'Output
  n
  (AggregateFields
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
aggregateParser <- TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (AggregateFields
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Output n (AggregateFields b (UnpreparedValue b)))
tableAggregationFields TableInfo ('Postgres pgKind)
targetTableInfo
    let aggregateFieldName :: Name
aggregateFieldName = MkRootFieldName -> Name -> Name
runMkRootFieldName MkRootFieldName
mkRootFieldName Name
_fiGQLAggregateName
        argsParser :: InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
argsParser = (FunctionArgsExpG
   (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> SelectArgsG
      ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
 -> (FunctionArgsExpG
       (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
     SelectArgsG
       ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     n
     (SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
forall a b c.
(a -> b -> c)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
-> InputFieldsParser MetadataObjId n c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser InputFieldsParser
  n
  (SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
tableArgsParser
        selectionName :: Name
selectionName = Name -> Name
mkTypename (NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier
mkTableAggregateTypeName GQLNameIdentifier
tableGQLName)
        aggregationParser :: Parser
  MetadataObjId
  'Output
  n
  (Fields
     (TableAggregateFieldG
        ('Postgres pgKind)
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue ('Postgres pgKind))))
aggregationParser =
          (InsOrdHashMap
   Name
   (ParsedSelection
      (TableAggregateFieldG
         ('Postgres pgKind)
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue ('Postgres pgKind))))
 -> Fields
      (TableAggregateFieldG
         ('Postgres pgKind)
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue ('Postgres pgKind))))
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (TableAggregateFieldG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> Parser
     MetadataObjId
     'Output
     n
     (Fields
        (TableAggregateFieldG
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind))))
forall a b.
(a -> b)
-> Parser MetadataObjId 'Output n a
-> Parser MetadataObjId 'Output n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
 -> TableAggregateFieldG
      ('Postgres pgKind)
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue ('Postgres pgKind)))
-> InsOrdHashMap
     Name
     (ParsedSelection
        (TableAggregateFieldG
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind))))
-> Fields
     (TableAggregateFieldG
        ('Postgres pgKind)
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue ('Postgres pgKind)))
forall a.
(Text -> a) -> InsOrdHashMap Name (ParsedSelection a) -> Fields a
parsedSelectionsToFields Text
-> TableAggregateFieldG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v. Text -> TableAggregateFieldG b r v
IR.TAFExp)
            (Parser
   MetadataObjId
   'Output
   n
   (InsOrdHashMap
      Name
      (ParsedSelection
         (TableAggregateFieldG
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))
 -> Parser
      MetadataObjId
      'Output
      n
      (Fields
         (TableAggregateFieldG
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (TableAggregateFieldG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> Parser
     MetadataObjId
     'Output
     n
     (Fields
        (TableAggregateFieldG
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ Parser
  MetadataObjId
  'Output
  n
  (InsOrdHashMap
     Name
     (ParsedSelection
        (TableAggregateFieldG
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind)))))
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (TableAggregateFieldG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall (m :: * -> *) origin (k :: Kind) a.
Parser origin k m a -> Parser origin k m a
P.nonNullableParser
            (Parser
   MetadataObjId
   'Output
   n
   (InsOrdHashMap
      Name
      (ParsedSelection
         (TableAggregateFieldG
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))
 -> Parser
      MetadataObjId
      'Output
      n
      (InsOrdHashMap
         Name
         (ParsedSelection
            (TableAggregateFieldG
               ('Postgres pgKind)
               (RemoteRelationshipField UnpreparedValue)
               (UnpreparedValue ('Postgres pgKind))))))
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (TableAggregateFieldG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (TableAggregateFieldG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> [FieldParser
      MetadataObjId
      n
      (TableAggregateFieldG
         ('Postgres pgKind)
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue ('Postgres pgKind)))]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (TableAggregateFieldG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> [FieldParser origin m a]
-> Parser origin 'Output m (InsOrdHashMap Name (ParsedSelection a))
P.selectionSet
              Name
selectionName
              Maybe Description
forall a. Maybe a
Nothing
              [ XNodesAgg ('Postgres pgKind)
-> AnnotatedFields ('Postgres pgKind)
-> TableAggregateFieldG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
XNodesAgg b -> AnnFieldsG b r v -> TableAggregateFieldG b r v
IR.TAFNodes ()
XNodesAgg ('Postgres pgKind)
xNodesAgg (AnnotatedFields ('Postgres pgKind)
 -> TableAggregateFieldG
      ('Postgres pgKind)
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue ('Postgres pgKind)))
-> FieldParser MetadataObjId n (AnnotatedFields ('Postgres pgKind))
-> FieldParser
     MetadataObjId
     n
     (TableAggregateFieldG
        ('Postgres pgKind)
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue ('Postgres pgKind)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser 'Output n (AnnotatedFields ('Postgres pgKind))
-> FieldParser MetadataObjId n (AnnotatedFields ('Postgres pgKind))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
Name._nodes Maybe Description
forall a. Maybe a
Nothing Parser 'Output n (AnnotatedFields ('Postgres pgKind))
nodesParser,
                AggregateFields
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
-> TableAggregateFieldG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
AggregateFields b v -> TableAggregateFieldG b r v
IR.TAFAgg (AggregateFields
   ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
 -> TableAggregateFieldG
      ('Postgres pgKind)
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue ('Postgres pgKind)))
-> FieldParser
     MetadataObjId
     n
     (AggregateFields
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> FieldParser
     MetadataObjId
     n
     (TableAggregateFieldG
        ('Postgres pgKind)
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue ('Postgres pgKind)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser
     'Output
     n
     (AggregateFields
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> FieldParser
     MetadataObjId
     n
     (AggregateFields
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
Name._aggregate Maybe Description
forall a. Maybe a
Nothing Parser
  'Output
  n
  (AggregateFields
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
aggregateParser
              ]
    pure
      $ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> Parser
     MetadataObjId
     'Output
     n
     (Fields
        (TableAggregateFieldG
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind))))
-> FieldParser
     MetadataObjId
     n
     ((FunctionArgsExpG
         (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
       SelectArgsG
         ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
      Fields
        (TableAggregateFieldG
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind))))
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
aggregateFieldName Maybe Description
description InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
argsParser Parser
  MetadataObjId
  'Output
  n
  (Fields
     (TableAggregateFieldG
        ('Postgres pgKind)
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue ('Postgres pgKind))))
aggregationParser
      FieldParser
  MetadataObjId
  n
  ((FunctionArgsExpG
      (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
    SelectArgsG
      ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
   Fields
     (TableAggregateFieldG
        ('Postgres pgKind)
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue ('Postgres pgKind))))
-> (((FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
     Fields
       (TableAggregateFieldG
          ('Postgres pgKind)
          (RemoteRelationshipField UnpreparedValue)
          (UnpreparedValue ('Postgres pgKind))))
    -> AggSelectExp ('Postgres pgKind))
-> FieldParser n (AggSelectExp ('Postgres pgKind))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \((FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
funcArgs, SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
tableArgs'), Fields
  (TableAggregateFieldG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind)))
fields) ->
        IR.AnnSelectG
          { $sel:_asnFields:AnnSelectG :: Fields
  (TableAggregateFieldG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind)))
IR._asnFields = Fields
  (TableAggregateFieldG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind)))
fields,
            $sel:_asnFrom:AnnSelectG :: SelectFromG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnFrom = FunctionName ('Postgres pgKind)
-> FunctionArgsExp
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
-> Maybe
     [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
-> SelectFromG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) v.
FunctionName b
-> FunctionArgsExp b v
-> Maybe [(Column b, ScalarType b)]
-> SelectFromG b v
IR.FromFunction FunctionName ('Postgres pgKind)
_fiSQLName FunctionArgsExp
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
funcArgs Maybe [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
Maybe [(PGCol, PGScalarType)]
forall a. Maybe a
Nothing,
            $sel:_asnPerm:AnnSelectG :: TablePermG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnPerm = SelPermInfo ('Postgres pgKind)
-> TablePermG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType).
Backend b =>
SelPermInfo b -> TablePerms b
tablePermissionsInfo SelPermInfo ('Postgres pgKind)
selectPermissions,
            $sel:_asnArgs:AnnSelectG :: SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnArgs = SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
tableArgs',
            $sel:_asnStrfyNum:AnnSelectG :: StringifyNumbers
IR._asnStrfyNum = StringifyNumbers
stringifyNumbers,
            $sel:_asnNamingConvention:AnnSelectG :: Maybe NamingCase
IR._asnNamingConvention = NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase
          }

selectFunctionConnection ::
  forall pgKind r m n.
  ( MonadBuildSchema ('Postgres pgKind) r m n,
    AggregationPredicatesSchema ('Postgres pgKind),
    BackendTableSelectSchema ('Postgres pgKind)
  ) =>
  MkRootFieldName ->
  -- | SQL function info
  FunctionInfo ('Postgres pgKind) ->
  -- | field description, if any
  Maybe G.Description ->
  -- | primary key columns of the target table
  PrimaryKeyColumns ('Postgres pgKind) ->
  SchemaT r m (Maybe (FieldParser n (ConnectionSelectExp ('Postgres pgKind))))
selectFunctionConnection :: forall (pgKind :: PostgresKind) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema ('Postgres pgKind) r m n,
 AggregationPredicatesSchema ('Postgres pgKind),
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> PrimaryKeyColumns ('Postgres pgKind)
-> SchemaT
     r
     m
     (Maybe (FieldParser n (ConnectionSelectExp ('Postgres pgKind))))
selectFunctionConnection MkRootFieldName
mkRootFieldName fi :: FunctionInfo ('Postgres pgKind)
fi@FunctionInfo {Maybe Text
FunctionPermissionsMap
Seq (FunctionInputArgument ('Postgres pgKind))
Name
SystemDefined
JsonAggSelect
TableName ('Postgres pgKind)
FunctionName ('Postgres pgKind)
FunctionExposedAs
FunctionVolatility
_fiSQLName :: forall (b :: BackendType). FunctionInfo b -> FunctionName b
_fiGQLName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLArgsName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLAggregateName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiSystemDefined :: forall (b :: BackendType). FunctionInfo b -> SystemDefined
_fiVolatility :: forall (b :: BackendType). FunctionInfo b -> FunctionVolatility
_fiExposedAs :: forall (b :: BackendType). FunctionInfo b -> FunctionExposedAs
_fiInputArgs :: forall (b :: BackendType).
FunctionInfo b -> Seq (FunctionInputArgument b)
_fiReturnType :: forall (b :: BackendType). FunctionInfo b -> TableName b
_fiDescription :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiPermissions :: forall (b :: BackendType). FunctionInfo b -> FunctionPermissionsMap
_fiJsonAggSelect :: forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiComment :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiSQLName :: FunctionName ('Postgres pgKind)
_fiGQLName :: Name
_fiGQLArgsName :: Name
_fiGQLAggregateName :: Name
_fiSystemDefined :: SystemDefined
_fiVolatility :: FunctionVolatility
_fiExposedAs :: FunctionExposedAs
_fiInputArgs :: Seq (FunctionInputArgument ('Postgres pgKind))
_fiReturnType :: TableName ('Postgres pgKind)
_fiDescription :: Maybe Text
_fiPermissions :: FunctionPermissionsMap
_fiJsonAggSelect :: JsonAggSelect
_fiComment :: Maybe Text
..} Maybe Description
description PrimaryKeyColumns ('Postgres pgKind)
pkeyColumns = MaybeT
  (SchemaT r m)
  (FieldParser n (ConnectionSelectExp ('Postgres pgKind)))
-> SchemaT
     r
     m
     (Maybe (FieldParser n (ConnectionSelectExp ('Postgres pgKind))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
  SourceInfo ('Postgres pgKind)
sourceInfo :: SourceInfo ('Postgres pgKind) <- (r -> SourceInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SourceInfo ('Postgres pgKind))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo ('Postgres pgKind)
forall a t. Has a t => t -> a
getter
  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
  let customization :: ResolvedSourceCustomization
customization = SourceInfo ('Postgres pgKind) -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo ('Postgres pgKind)
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization

  TableInfo ('Postgres pgKind)
returnTableInfo <- SchemaT r m (TableInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind))
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 (TableInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind)))
-> SchemaT r m (TableInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ TableName ('Postgres pgKind)
-> SchemaT r m (TableInfo ('Postgres pgKind))
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName ('Postgres pgKind)
_fiReturnType
  SelPermInfo ('Postgres pgKind)
selectPermissions <- Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind)))
-> Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ RoleName
-> TableInfo ('Postgres pgKind)
-> Maybe (SelPermInfo ('Postgres pgKind))
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo ('Postgres pgKind)
returnTableInfo
  ()
xRelayInfo <- Maybe (XRelay ('Postgres pgKind))
-> MaybeT (SchemaT r m) (XRelay ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (XRelay ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (XRelay ('Postgres pgKind)))
-> Maybe (XRelay ('Postgres pgKind))
-> MaybeT (SchemaT r m) (XRelay ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType). BackendSchema b => Maybe (XRelay b)
relayExtension @('Postgres pgKind)
  Parser 'Output n (ConnectionFields ('Postgres pgKind))
selectionSetParser <- SchemaT
  r
  m
  (Maybe (Parser 'Output n (ConnectionFields ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Output n (ConnectionFields ('Postgres pgKind)))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT
   r
   m
   (Maybe (Parser 'Output n (ConnectionFields ('Postgres pgKind))))
 -> MaybeT
      (SchemaT r m)
      (Parser 'Output n (ConnectionFields ('Postgres pgKind))))
-> SchemaT
     r
     m
     (Maybe (Parser 'Output n (ConnectionFields ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Output n (ConnectionFields ('Postgres pgKind)))
forall a b. (a -> b) -> a -> b
$ TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (Maybe (Parser 'Output n (ConnectionFields ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (ConnectionFields b)))
tableConnectionSelectionSet TableInfo ('Postgres pgKind)
returnTableInfo
  SchemaT
  r m (FieldParser n (ConnectionSelectExp ('Postgres pgKind)))
-> MaybeT
     (SchemaT r m)
     (FieldParser n (ConnectionSelectExp ('Postgres pgKind)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift do
    let fieldName :: Name
fieldName = MkRootFieldName -> Name -> Name
runMkRootFieldName MkRootFieldName
mkRootFieldName (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ Name
_fiGQLName Name -> Name -> Name
forall a. Semigroup a => a -> a -> a
<> Name
Name.__connection
    StringifyNumbers
stringifyNumbers <- (SchemaOptions -> StringifyNumbers) -> SchemaT r m StringifyNumbers
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaOptions -> StringifyNumbers
Options.soStringifyNumbers
    InputFieldsParser
  n
  (SelectArgs ('Postgres pgKind),
   Maybe
     (NonEmpty
        (ConnectionSplit
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
   Maybe ConnectionSlice)
tableConnectionArgsParser <- PrimaryKeyColumns ('Postgres pgKind)
-> TableInfo ('Postgres pgKind)
-> SelPermInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgs ('Postgres pgKind),
         Maybe
           (NonEmpty
              (ConnectionSplit
                 ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
         Maybe ConnectionSlice))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, AggregationPredicatesSchema b) =>
PrimaryKeyColumns b
-> TableInfo b
-> SelPermInfo b
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgs b,
         Maybe (NonEmpty (ConnectionSplit b (UnpreparedValue b))),
         Maybe ConnectionSlice))
tableConnectionArgs PrimaryKeyColumns ('Postgres pgKind)
pkeyColumns TableInfo ('Postgres pgKind)
returnTableInfo SelPermInfo ('Postgres pgKind)
selectPermissions
    InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser <- FunctionInfo ('Postgres pgKind)
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall (pgKind :: PostgresKind) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema ('Postgres pgKind) r m n =>
FunctionInfo ('Postgres pgKind)
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
customSQLFunctionArgs FunctionInfo ('Postgres pgKind)
fi Name
_fiGQLName Name
_fiGQLArgsName
    let argsParser :: InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   (SelectArgs ('Postgres pgKind),
    Maybe
      (NonEmpty
         (ConnectionSplit
            ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
    Maybe ConnectionSlice))
argsParser = (FunctionArgsExpG
   (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> (SelectArgs ('Postgres pgKind),
     Maybe
       (NonEmpty
          (ConnectionSplit
             ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
     Maybe ConnectionSlice)
 -> (FunctionArgsExpG
       (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
     (SelectArgs ('Postgres pgKind),
      Maybe
        (NonEmpty
           (ConnectionSplit
              ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
      Maybe ConnectionSlice)))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     n
     (SelectArgs ('Postgres pgKind),
      Maybe
        (NonEmpty
           (ConnectionSplit
              ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
      Maybe ConnectionSlice)
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      (SelectArgs ('Postgres pgKind),
       Maybe
         (NonEmpty
            (ConnectionSplit
               ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
       Maybe ConnectionSlice))
forall a b c.
(a -> b -> c)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
-> InputFieldsParser MetadataObjId n c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser InputFieldsParser
  n
  (SelectArgs ('Postgres pgKind),
   Maybe
     (NonEmpty
        (ConnectionSplit
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
   Maybe ConnectionSlice)
tableConnectionArgsParser
    pure
      $ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      (SelectArgs ('Postgres pgKind),
       Maybe
         (NonEmpty
            (ConnectionSplit
               ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
       Maybe ConnectionSlice))
-> Parser 'Output n (ConnectionFields ('Postgres pgKind))
-> FieldParser
     MetadataObjId
     n
     ((FunctionArgsExpG
         (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
       (SelectArgs ('Postgres pgKind),
        Maybe
          (NonEmpty
             (ConnectionSplit
                ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
        Maybe ConnectionSlice)),
      ConnectionFields ('Postgres pgKind))
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
fieldName Maybe Description
description InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   (SelectArgs ('Postgres pgKind),
    Maybe
      (NonEmpty
         (ConnectionSplit
            ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
    Maybe ConnectionSlice))
argsParser Parser 'Output n (ConnectionFields ('Postgres pgKind))
selectionSetParser
      FieldParser
  MetadataObjId
  n
  ((FunctionArgsExpG
      (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
    (SelectArgs ('Postgres pgKind),
     Maybe
       (NonEmpty
          (ConnectionSplit
             ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
     Maybe ConnectionSlice)),
   ConnectionFields ('Postgres pgKind))
-> (((FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      (SelectArgs ('Postgres pgKind),
       Maybe
         (NonEmpty
            (ConnectionSplit
               ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))),
       Maybe ConnectionSlice)),
     ConnectionFields ('Postgres pgKind))
    -> ConnectionSelectExp ('Postgres pgKind))
-> FieldParser n (ConnectionSelectExp ('Postgres pgKind))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \((FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
funcArgs, (SelectArgs ('Postgres pgKind)
args, Maybe
  (NonEmpty
     (ConnectionSplit
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
split, Maybe ConnectionSlice
slice)), ConnectionFields ('Postgres pgKind)
fields) ->
        IR.ConnectionSelect
          { $sel:_csXRelay:ConnectionSelect :: XRelay ('Postgres pgKind)
IR._csXRelay = ()
XRelay ('Postgres pgKind)
xRelayInfo,
            $sel:_csPrimaryKeyColumns:ConnectionSelect :: PrimaryKeyColumns ('Postgres pgKind)
IR._csPrimaryKeyColumns = PrimaryKeyColumns ('Postgres pgKind)
pkeyColumns,
            $sel:_csSplit:ConnectionSelect :: Maybe
  (NonEmpty
     (ConnectionSplit
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
IR._csSplit = Maybe
  (NonEmpty
     (ConnectionSplit
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
split,
            $sel:_csSlice:ConnectionSelect :: Maybe ConnectionSlice
IR._csSlice = Maybe ConnectionSlice
slice,
            $sel:_csSelect:ConnectionSelect :: AnnSelectG
  ('Postgres pgKind)
  (ConnectionField
     ('Postgres pgKind) (RemoteRelationshipField UnpreparedValue))
  (UnpreparedValue ('Postgres pgKind))
IR._csSelect =
              IR.AnnSelectG
                { $sel:_asnFields:AnnSelectG :: ConnectionFields ('Postgres pgKind)
IR._asnFields = ConnectionFields ('Postgres pgKind)
fields,
                  $sel:_asnFrom:AnnSelectG :: SelectFromG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnFrom = FunctionName ('Postgres pgKind)
-> FunctionArgsExp
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
-> Maybe
     [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
-> SelectFromG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) v.
FunctionName b
-> FunctionArgsExp b v
-> Maybe [(Column b, ScalarType b)]
-> SelectFromG b v
IR.FromFunction FunctionName ('Postgres pgKind)
_fiSQLName FunctionArgsExp
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
funcArgs Maybe [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
Maybe [(PGCol, PGScalarType)]
forall a. Maybe a
Nothing,
                  $sel:_asnPerm:AnnSelectG :: TablePermG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnPerm = SelPermInfo ('Postgres pgKind)
-> TablePermG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType).
Backend b =>
SelPermInfo b -> TablePerms b
tablePermissionsInfo SelPermInfo ('Postgres pgKind)
selectPermissions,
                  $sel:_asnArgs:AnnSelectG :: SelectArgs ('Postgres pgKind)
IR._asnArgs = SelectArgs ('Postgres pgKind)
args,
                  $sel:_asnStrfyNum:AnnSelectG :: StringifyNumbers
IR._asnStrfyNum = StringifyNumbers
stringifyNumbers,
                  $sel:_asnNamingConvention:AnnSelectG :: Maybe NamingCase
IR._asnNamingConvention = NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase
                }
          }

-- | Computed field parser
computedFieldPG ::
  forall pgKind r m n.
  ( MonadBuildSchema ('Postgres pgKind) r m n,
    BackendTableSelectSchema ('Postgres pgKind)
  ) =>
  ComputedFieldInfo ('Postgres pgKind) ->
  TableName ('Postgres pgKind) ->
  TableInfo ('Postgres pgKind) ->
  SchemaT r m (Maybe (FieldParser n (AnnotatedField ('Postgres pgKind))))
computedFieldPG :: forall (pgKind :: PostgresKind) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
ComputedFieldInfo ('Postgres pgKind)
-> TableName ('Postgres pgKind)
-> TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (FieldParser n (AnnotatedField ('Postgres pgKind))))
computedFieldPG ComputedFieldInfo {Maybe Text
ComputedFieldName
ComputedFieldReturn ('Postgres pgKind)
XComputedField ('Postgres pgKind)
ComputedFieldFunction ('Postgres pgKind)
_cfiXComputedFieldInfo :: XComputedField ('Postgres pgKind)
_cfiName :: ComputedFieldName
_cfiFunction :: ComputedFieldFunction ('Postgres pgKind)
_cfiReturnType :: ComputedFieldReturn ('Postgres pgKind)
_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
..} TableName ('Postgres pgKind)
parentTable TableInfo ('Postgres pgKind)
tableInfo = MaybeT
  (SchemaT r m) (FieldParser n (AnnotatedField ('Postgres pgKind)))
-> SchemaT
     r m (Maybe (FieldParser n (AnnotatedField ('Postgres pgKind))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
  SourceInfo ('Postgres pgKind)
sourceInfo :: SourceInfo ('Postgres pgKind) <- (r -> SourceInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SourceInfo ('Postgres pgKind))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo ('Postgres pgKind)
forall a t. Has a t => t -> a
getter
  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
  let sourceName :: SourceName
sourceName = SourceInfo ('Postgres pgKind) -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo ('Postgres pgKind)
sourceInfo
      customization :: ResolvedSourceCustomization
customization = SourceInfo ('Postgres pgKind) -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo ('Postgres pgKind)
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
  StringifyNumbers
stringifyNumbers <- (SchemaOptions -> StringifyNumbers)
-> MaybeT (SchemaT r m) StringifyNumbers
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaOptions -> StringifyNumbers
Options.soStringifyNumbers
  SelPermInfo ('Postgres pgKind)
selectPermissions <- Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind)))
-> Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ RoleName
-> TableInfo ('Postgres pgKind)
-> Maybe (SelPermInfo ('Postgres pgKind))
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo ('Postgres pgKind)
tableInfo
  Name
fieldName <- SchemaT r m Name -> MaybeT (SchemaT r m) Name
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 Name -> MaybeT (SchemaT r m) Name)
-> SchemaT r m Name -> MaybeT (SchemaT r m) Name
forall a b. (a -> b) -> a -> b
$ Text -> SchemaT r m Name
forall (m :: * -> *). MonadError QErr m => Text -> m Name
textToName (Text -> SchemaT r m Name) -> Text -> SchemaT r m Name
forall a b. (a -> b) -> a -> b
$ ComputedFieldName -> Text
computedFieldNameToText ComputedFieldName
_cfiName
  InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser <- SchemaT
  r
  m
  (InputFieldsParser
     n
     (FunctionArgsExp
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
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
   (InputFieldsParser
      n
      (FunctionArgsExp
         ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
 -> MaybeT
      (SchemaT r m)
      (InputFieldsParser
         n
         (FunctionArgsExp
            ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ SourceName
-> ComputedFieldFunction ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
computedFieldFunctionArgs SourceName
sourceName ComputedFieldFunction ('Postgres pgKind)
_cfiFunction
  case ComputedFieldReturn ('Postgres pgKind)
_cfiReturnType of
    Postgres.CFRScalar PGScalarType
scalarReturnType -> do
      AnnRedactionExpUnpreparedValue ('Postgres pgKind)
redactionExp <- Maybe (AnnRedactionExpUnpreparedValue ('Postgres pgKind))
-> MaybeT
     (SchemaT r m) (AnnRedactionExpUnpreparedValue ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (AnnRedactionExpUnpreparedValue ('Postgres pgKind))
 -> MaybeT
      (SchemaT r m) (AnnRedactionExpUnpreparedValue ('Postgres pgKind)))
-> Maybe (AnnRedactionExpUnpreparedValue ('Postgres pgKind))
-> MaybeT
     (SchemaT r m) (AnnRedactionExpUnpreparedValue ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ SelPermInfo ('Postgres pgKind)
-> ComputedFieldName
-> Maybe (AnnRedactionExpUnpreparedValue ('Postgres pgKind))
forall (b :: BackendType).
Backend b =>
SelPermInfo b
-> ComputedFieldName -> Maybe (AnnRedactionExpUnpreparedValue b)
getRedactionExprForComputedField SelPermInfo ('Postgres pgKind)
selectPermissions ComputedFieldName
_cfiName
      let fieldArgsParser :: InputFieldsParser
  MetadataObjId n (AnnotatedField ('Postgres pgKind))
fieldArgsParser = do
            FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
args <- InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser
            Maybe ColumnOp
colOp <- forall (b :: BackendType) (n :: * -> *).
(BackendSchema b, MonadParse n) =>
ColumnType b
-> InputFieldsParser n (Maybe (ScalarSelectionArguments b))
scalarSelectionArgumentsParser @('Postgres pgKind) (ColumnType ('Postgres pgKind)
 -> InputFieldsParser
      n (Maybe (ScalarSelectionArguments ('Postgres pgKind))))
-> ColumnType ('Postgres pgKind)
-> InputFieldsParser
     n (Maybe (ScalarSelectionArguments ('Postgres pgKind)))
forall a b. (a -> b) -> a -> b
$ ScalarType ('Postgres pgKind) -> ColumnType ('Postgres pgKind)
forall (b :: BackendType). ScalarType b -> ColumnType b
ColumnScalar ScalarType ('Postgres pgKind)
PGScalarType
scalarReturnType
            pure
              $ XComputedField ('Postgres pgKind)
-> ComputedFieldName
-> ComputedFieldSelect
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
-> AnnotatedField ('Postgres pgKind)
forall (b :: BackendType) r v.
XComputedField b
-> ComputedFieldName
-> ComputedFieldSelect b r v
-> AnnFieldG b r v
IR.AFComputedField
                XComputedField ('Postgres pgKind)
_cfiXComputedFieldInfo
                ComputedFieldName
_cfiName
                ( ComputedFieldScalarSelect
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
-> ComputedFieldSelect
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
ComputedFieldScalarSelect b v -> ComputedFieldSelect b r v
IR.CFSScalar
                    ( IR.ComputedFieldScalarSelect
                        { $sel:_cfssFunction:ComputedFieldScalarSelect :: FunctionName ('Postgres pgKind)
IR._cfssFunction = ComputedFieldFunction ('Postgres pgKind)
-> FunctionName ('Postgres pgKind)
forall (b :: BackendType).
ComputedFieldFunction b -> FunctionName b
_cffName ComputedFieldFunction ('Postgres pgKind)
_cfiFunction,
                          $sel:_cfssType:ComputedFieldScalarSelect :: ScalarType ('Postgres pgKind)
IR._cfssType = ScalarType ('Postgres pgKind)
PGScalarType
scalarReturnType,
                          $sel:_cfssScalarArguments:ComputedFieldScalarSelect :: Maybe (ScalarSelectionArguments ('Postgres pgKind))
IR._cfssScalarArguments = Maybe (ScalarSelectionArguments ('Postgres pgKind))
Maybe ColumnOp
colOp,
                          $sel:_cfssArguments:ComputedFieldScalarSelect :: FunctionArgsExp
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._cfssArguments = FunctionArgsExp
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
args,
                          $sel:_cfssRedactionExpression:ComputedFieldScalarSelect :: AnnRedactionExpUnpreparedValue ('Postgres pgKind)
IR._cfssRedactionExpression = AnnRedactionExpUnpreparedValue ('Postgres pgKind)
redactionExp
                        }
                    )
                )
      Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind)))
dummyParser <- SchemaT
  r
  m
  (Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
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 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
 -> MaybeT
      (SchemaT r m)
      (Parser
         'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendSchema b, MonadBuildSchema b r m n) =>
ColumnType b
-> Nullability
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
columnParser @('Postgres pgKind) (ScalarType ('Postgres pgKind) -> ColumnType ('Postgres pgKind)
forall (b :: BackendType). ScalarType b -> ColumnType b
ColumnScalar ScalarType ('Postgres pgKind)
PGScalarType
scalarReturnType) (Bool -> Nullability
G.Nullability Bool
True)
      pure $ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId n (AnnotatedField ('Postgres pgKind))
-> Parser
     'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind)))
-> FieldParser n (AnnotatedField ('Postgres pgKind))
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Both m b
-> FieldParser origin m a
P.selection Name
fieldName Maybe Description
fieldDescription InputFieldsParser
  MetadataObjId n (AnnotatedField ('Postgres pgKind))
fieldArgsParser Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind)))
dummyParser
    Postgres.CFRSetofTable QualifiedTable
tableName -> do
      TableInfo ('Postgres pgKind)
otherTableInfo <- SchemaT r m (TableInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind))
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 (TableInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind)))
-> SchemaT r m (TableInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (TableInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ TableName ('Postgres pgKind)
-> SchemaT r m (TableInfo ('Postgres pgKind))
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName ('Postgres pgKind)
QualifiedTable
tableName
      SelPermInfo ('Postgres pgKind)
remotePerms <- Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo ('Postgres pgKind))
 -> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind)))
-> Maybe (SelPermInfo ('Postgres pgKind))
-> MaybeT (SchemaT r m) (SelPermInfo ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ RoleName
-> TableInfo ('Postgres pgKind)
-> Maybe (SelPermInfo ('Postgres pgKind))
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo ('Postgres pgKind)
otherTableInfo
      Parser MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
selectionSetParser <- SchemaT
  r
  m
  (Maybe
     (Parser
        MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (Parser
        MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind)))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT ((Parser
   MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
 -> Parser
      MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind)))
-> Maybe
     (Parser
        MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind)))
-> Maybe
     (Parser
        MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind)))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Parser MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
-> Parser
     MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
forall (m :: * -> *) origin a.
Parser origin 'Output m a -> Parser origin 'Output m a
P.multiple (Parser
   MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
 -> Parser
      MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind)))
-> (Parser
      MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
    -> Parser
         MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind)))
-> Parser
     MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
-> Parser
     MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
-> Parser
     MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
forall (m :: * -> *) origin (k :: Kind) a.
Parser origin k m a -> Parser origin k m a
P.nonNullableParser) (Maybe
   (Parser
      MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind)))
 -> Maybe
      (Parser
         MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))))
-> SchemaT
     r
     m
     (Maybe
        (Parser
           MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))))
-> SchemaT
     r
     m
     (Maybe
        (Parser
           MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (Maybe
        (Parser
           MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema ('Postgres pgKind) r m n =>
TableInfo ('Postgres pgKind)
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendTableSelectSchema b, MonadBuildSourceSchema b r m n) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
tableSelectionSet TableInfo ('Postgres pgKind)
otherTableInfo)
      InputFieldsParser
  n
  (SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
selectArgsParser <- SchemaT
  r
  m
  (InputFieldsParser
     n
     (SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
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
   (InputFieldsParser
      n
      (SelectArgsG
         ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
 -> MaybeT
      (SchemaT r m)
      (InputFieldsParser
         n
         (SelectArgsG
            ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema ('Postgres pgKind) r m n =>
TableInfo ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (SelectArgsG
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendTableSelectSchema b, MonadBuildSourceSchema b r m n) =>
TableInfo b
-> SchemaT
     r m (InputFieldsParser n (SelectArgsG b (UnpreparedValue b)))
tableArguments TableInfo ('Postgres pgKind)
otherTableInfo
      let fieldArgsParser :: InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
fieldArgsParser = (FunctionArgsExpG
   (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> SelectArgsG
      ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
 -> (FunctionArgsExpG
       (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
     SelectArgsG
       ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     n
     (SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
forall a b c.
(a -> b -> c)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
-> InputFieldsParser MetadataObjId n c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
functionArgsParser InputFieldsParser
  n
  (SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
selectArgsParser
      pure
        $ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
-> Parser
     MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
-> FieldParser
     MetadataObjId
     n
     ((FunctionArgsExpG
         (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
       SelectArgsG
         ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
      AnnotatedFields ('Postgres pgKind))
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
fieldName Maybe Description
fieldDescription InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
   SelectArgsG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))
fieldArgsParser Parser MetadataObjId 'Output n (AnnotatedFields ('Postgres pgKind))
selectionSetParser
        FieldParser
  MetadataObjId
  n
  ((FunctionArgsExpG
      (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
    SelectArgsG
      ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
   AnnotatedFields ('Postgres pgKind))
-> (((FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))),
      SelectArgsG
        ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))),
     AnnotatedFields ('Postgres pgKind))
    -> AnnotatedField ('Postgres pgKind))
-> FieldParser n (AnnotatedField ('Postgres pgKind))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \((FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
functionArgs', SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
args), AnnotatedFields ('Postgres pgKind)
fields) ->
          XComputedField ('Postgres pgKind)
-> ComputedFieldName
-> ComputedFieldSelect
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
-> AnnotatedField ('Postgres pgKind)
forall (b :: BackendType) r v.
XComputedField b
-> ComputedFieldName
-> ComputedFieldSelect b r v
-> AnnFieldG b r v
IR.AFComputedField XComputedField ('Postgres pgKind)
_cfiXComputedFieldInfo ComputedFieldName
_cfiName
            (ComputedFieldSelect
   ('Postgres pgKind)
   (RemoteRelationshipField UnpreparedValue)
   (UnpreparedValue ('Postgres pgKind))
 -> AnnotatedField ('Postgres pgKind))
-> ComputedFieldSelect
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
-> AnnotatedField ('Postgres pgKind)
forall a b. (a -> b) -> a -> b
$ JsonAggSelect
-> AnnSimpleSelectG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
-> ComputedFieldSelect
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
JsonAggSelect
-> AnnSimpleSelectG b r v -> ComputedFieldSelect b r v
IR.CFSTable JsonAggSelect
JASMultipleRows
            (AnnSimpleSelectG
   ('Postgres pgKind)
   (RemoteRelationshipField UnpreparedValue)
   (UnpreparedValue ('Postgres pgKind))
 -> ComputedFieldSelect
      ('Postgres pgKind)
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue ('Postgres pgKind)))
-> AnnSimpleSelectG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
-> ComputedFieldSelect
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall a b. (a -> b) -> a -> b
$ IR.AnnSelectG
              { $sel:_asnFields:AnnSelectG :: AnnotatedFields ('Postgres pgKind)
IR._asnFields = AnnotatedFields ('Postgres pgKind)
fields,
                $sel:_asnFrom:AnnSelectG :: SelectFromG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnFrom = FunctionName ('Postgres pgKind)
-> FunctionArgsExp
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
-> Maybe
     [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
-> SelectFromG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) v.
FunctionName b
-> FunctionArgsExp b v
-> Maybe [(Column b, ScalarType b)]
-> SelectFromG b v
IR.FromFunction (ComputedFieldFunction ('Postgres pgKind)
-> FunctionName ('Postgres pgKind)
forall (b :: BackendType).
ComputedFieldFunction b -> FunctionName b
_cffName ComputedFieldFunction ('Postgres pgKind)
_cfiFunction) FunctionArgsExp
  ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
functionArgs' Maybe [(Column ('Postgres pgKind), ScalarType ('Postgres pgKind))]
Maybe [(PGCol, PGScalarType)]
forall a. Maybe a
Nothing,
                $sel:_asnPerm:AnnSelectG :: TablePermG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnPerm = SelPermInfo ('Postgres pgKind)
-> TablePermG
     ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType).
Backend b =>
SelPermInfo b -> TablePerms b
tablePermissionsInfo SelPermInfo ('Postgres pgKind)
remotePerms,
                $sel:_asnArgs:AnnSelectG :: SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
IR._asnArgs = SelectArgsG ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))
args,
                $sel:_asnStrfyNum:AnnSelectG :: StringifyNumbers
IR._asnStrfyNum = StringifyNumbers
stringifyNumbers,
                $sel:_asnNamingConvention:AnnSelectG :: Maybe NamingCase
IR._asnNamingConvention = NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase
              }
  where
    fieldDescription :: Maybe G.Description
    fieldDescription :: Maybe Description
fieldDescription = Text -> Description
G.Description (Text -> Description) -> Maybe Text -> Maybe Description
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Text
_cfiDescription

    computedFieldFunctionArgs ::
      SourceName ->
      ComputedFieldFunction ('Postgres pgKind) ->
      SchemaT r m (InputFieldsParser n (FunctionArgsExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))
    computedFieldFunctionArgs :: SourceName
-> ComputedFieldFunction ('Postgres pgKind)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
computedFieldFunctionArgs SourceName
sourceName ComputedFieldFunction {Maybe PGDescription
Seq (FunctionArgument ('Postgres pgKind))
FunctionName ('Postgres pgKind)
ComputedFieldImplicitArguments ('Postgres pgKind)
_cffName :: forall (b :: BackendType).
ComputedFieldFunction b -> FunctionName b
_cffName :: FunctionName ('Postgres pgKind)
_cffInputArgs :: Seq (FunctionArgument ('Postgres pgKind))
_cffComputedFieldImplicitArgs :: ComputedFieldImplicitArguments ('Postgres pgKind)
_cffDescription :: Maybe PGDescription
_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
..} = do
      FunctionTrackedAs ('Postgres pgKind)
-> Seq (FunctionInputArgument ('Postgres pgKind))
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
MonadBuildSchema ('Postgres pgKind) r m n =>
FunctionTrackedAs ('Postgres pgKind)
-> Seq (FunctionInputArgument ('Postgres pgKind))
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
functionArgs (ComputedFieldName
-> SourceName
-> TableName ('Postgres pgKind)
-> FunctionTrackedAs ('Postgres pgKind)
forall (b :: BackendType).
ComputedFieldName
-> SourceName -> TableName b -> FunctionTrackedAs b
FTAComputedField ComputedFieldName
_cfiName SourceName
sourceName TableName ('Postgres pgKind)
parentTable) (FunctionArg -> InputArgument FunctionArg
forall a. a -> InputArgument a
IAUserProvided (FunctionArg -> InputArgument FunctionArg)
-> Seq FunctionArg -> Seq (InputArgument FunctionArg)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Seq (FunctionArgument ('Postgres pgKind))
Seq FunctionArg
_cffInputArgs)
        SchemaT
  r
  m
  (InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> (InputFieldsParser
      MetadataObjId
      n
      (FunctionArgsExpG
         (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
    -> InputFieldsParser
         MetadataObjId
         n
         (FunctionArgsExpG
            (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG
           (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (FunctionArgsExpG
   (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> FunctionArgsExpG
      (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
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 FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
addTableAndSessionArgument
      where
        addTableAndSessionArgument :: FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
addTableAndSessionArgument args :: FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
args@(FunctionArgsExp [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
positional HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
named) =
          let withTable :: FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
withTable = case ComputedFieldImplicitArguments -> FunctionTableArgument
Postgres._cffaTableArgument ComputedFieldImplicitArguments ('Postgres pgKind)
ComputedFieldImplicitArguments
_cffComputedFieldImplicitArgs of
                FunctionTableArgument
Postgres.FTAFirst -> [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. [a] -> HashMap Text a -> FunctionArgsExpG a
FunctionArgsExp (ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall a. ArgumentExp a
Postgres.AETableRow ArgumentExp (UnpreparedValue ('Postgres pgKind))
-> [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
-> [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
forall a. a -> [a] -> [a]
: [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
positional) HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
named
                Postgres.FTANamed FunctionArgName
argName Int
index -> FunctionArgName
-> Int
-> ArgumentExp (UnpreparedValue ('Postgres pgKind))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a.
FunctionArgName
-> Int -> a -> FunctionArgsExpG a -> FunctionArgsExpG a
IR.insertFunctionArg FunctionArgName
argName Int
index ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall a. ArgumentExp a
Postgres.AETableRow FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
args
              sessionArgVal :: ArgumentExp (UnpreparedValue b)
sessionArgVal = UnpreparedValue b -> ArgumentExp (UnpreparedValue b)
forall a. a -> ArgumentExp a
Postgres.AESession UnpreparedValue b
forall (b :: BackendType). UnpreparedValue b
IR.UVSession
           in case ComputedFieldImplicitArguments -> Maybe FunctionSessionArgument
Postgres._cffaSessionArgument ComputedFieldImplicitArguments ('Postgres pgKind)
ComputedFieldImplicitArguments
_cffComputedFieldImplicitArgs of
                Maybe FunctionSessionArgument
Nothing -> FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
withTable
                Just (Postgres.FunctionSessionArgument FunctionArgName
argName Int
index) ->
                  FunctionArgName
-> Int
-> ArgumentExp (UnpreparedValue ('Postgres pgKind))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a.
FunctionArgName
-> Int -> a -> FunctionArgsExpG a -> FunctionArgsExpG a
IR.insertFunctionArg FunctionArgName
argName Int
index ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall {b :: BackendType}. ArgumentExp (UnpreparedValue b)
sessionArgVal FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
withTable

-- | The custom SQL functions' input "args" field parser
-- > function_name(args: function_args)
customSQLFunctionArgs ::
  (MonadBuildSchema ('Postgres pgKind) r m n) =>
  FunctionInfo ('Postgres pgKind) ->
  G.Name ->
  G.Name ->
  SchemaT r m (InputFieldsParser n (FunctionArgsExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))
customSQLFunctionArgs :: forall (pgKind :: PostgresKind) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema ('Postgres pgKind) r m n =>
FunctionInfo ('Postgres pgKind)
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
customSQLFunctionArgs FunctionInfo {Maybe Text
FunctionPermissionsMap
Seq (FunctionInputArgument ('Postgres pgKind))
Name
SystemDefined
JsonAggSelect
TableName ('Postgres pgKind)
FunctionName ('Postgres pgKind)
FunctionExposedAs
FunctionVolatility
_fiSQLName :: forall (b :: BackendType). FunctionInfo b -> FunctionName b
_fiGQLName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLArgsName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLAggregateName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiSystemDefined :: forall (b :: BackendType). FunctionInfo b -> SystemDefined
_fiVolatility :: forall (b :: BackendType). FunctionInfo b -> FunctionVolatility
_fiExposedAs :: forall (b :: BackendType). FunctionInfo b -> FunctionExposedAs
_fiInputArgs :: forall (b :: BackendType).
FunctionInfo b -> Seq (FunctionInputArgument b)
_fiReturnType :: forall (b :: BackendType). FunctionInfo b -> TableName b
_fiDescription :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiPermissions :: forall (b :: BackendType). FunctionInfo b -> FunctionPermissionsMap
_fiJsonAggSelect :: forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiComment :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiSQLName :: FunctionName ('Postgres pgKind)
_fiGQLName :: Name
_fiGQLArgsName :: Name
_fiGQLAggregateName :: Name
_fiSystemDefined :: SystemDefined
_fiVolatility :: FunctionVolatility
_fiExposedAs :: FunctionExposedAs
_fiInputArgs :: Seq (FunctionInputArgument ('Postgres pgKind))
_fiReturnType :: TableName ('Postgres pgKind)
_fiDescription :: Maybe Text
_fiPermissions :: FunctionPermissionsMap
_fiJsonAggSelect :: JsonAggSelect
_fiComment :: Maybe Text
..} Name
functionName Name
functionArgsName =
  FunctionTrackedAs ('Postgres pgKind)
-> Seq (FunctionInputArgument ('Postgres pgKind))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG
           (FunctionArgumentExp
              ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind)))))
forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
MonadBuildSchema ('Postgres pgKind) r m n =>
FunctionTrackedAs ('Postgres pgKind)
-> Seq (FunctionInputArgument ('Postgres pgKind))
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
functionArgs
    ( CustomFunctionNames -> FunctionTrackedAs ('Postgres pgKind)
forall (b :: BackendType).
CustomFunctionNames -> FunctionTrackedAs b
FTACustomFunction
        (CustomFunctionNames -> FunctionTrackedAs ('Postgres pgKind))
-> CustomFunctionNames -> FunctionTrackedAs ('Postgres pgKind)
forall a b. (a -> b) -> a -> b
$ CustomFunctionNames
          { cfnFunctionName :: Name
cfnFunctionName = Name
functionName,
            cfnArgsName :: Name
cfnArgsName = Name
functionArgsName
          }
    )
    Seq (FunctionInputArgument ('Postgres pgKind))
_fiInputArgs

-- | Parses the arguments to the underlying sql function of a computed field or
--   a custom function. All arguments to the underlying sql function are parsed
--   as an "args" object. Named arguments are expected in a field with the same
--   name, while positional arguments are expected in an field named "arg_$n".
--   Note that collisions are possible, but ignored for now, if a named argument
--   is also named "arg_$n". (FIXME: link to an issue?)
--
--   If the function requires no argument, or if its only argument is not
--   user-provided (the session argument in the case of custom functions, the
--   table row argument in the case of computed fields), the args object will
--   be omitted.
functionArgs ::
  forall r m n pgKind.
  (MonadBuildSchema ('Postgres pgKind) r m n) =>
  FunctionTrackedAs ('Postgres pgKind) ->
  Seq.Seq (FunctionInputArgument ('Postgres pgKind)) ->
  SchemaT r m (InputFieldsParser n (FunctionArgsExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))
functionArgs :: forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
MonadBuildSchema ('Postgres pgKind) r m n =>
FunctionTrackedAs ('Postgres pgKind)
-> Seq (FunctionInputArgument ('Postgres pgKind))
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp
           ('Postgres pgKind) (UnpreparedValue ('Postgres pgKind))))
functionArgs FunctionTrackedAs ('Postgres pgKind)
functionTrackedAs (Seq (FunctionInputArgument ('Postgres pgKind))
-> [InputArgument FunctionArg]
Seq (InputArgument FunctionArg) -> [InputArgument FunctionArg]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList -> [InputArgument FunctionArg]
inputArgs) = do
  SourceInfo ('Postgres pgKind)
sourceInfo :: SourceInfo ('Postgres pgKind) <- (r -> SourceInfo ('Postgres pgKind))
-> SchemaT r m (SourceInfo ('Postgres pgKind))
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo ('Postgres pgKind)
forall a t. Has a t => t -> a
getter
  let customization :: ResolvedSourceCustomization
customization = SourceInfo ('Postgres pgKind) -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo ('Postgres pgKind)
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
      -- First, we iterate through the original sql arguments in order, to find the
      -- corresponding graphql names. At the same time, we create the input field
      -- parsers, in three groups: session argument, optional arguments, and
      -- mandatory arguments. Optional arguments have a default value, mandatory
      -- arguments don't.
      ([Text]
names, [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
session, [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
optional, [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
mandatory) = [([Text],
  [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
  [SchemaT
     r
     m
     (InputFieldsParser
        n
        (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
  [SchemaT
     r
     m
     (InputFieldsParser
        n
        (Maybe
           (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])]
-> ([Text],
    [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n
          (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n
          (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])
forall a. Monoid a => [a] -> a
mconcat ([([Text],
   [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe
            (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])]
 -> ([Text],
     [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe
              (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]))
-> [([Text],
     [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe
              (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])]
-> ([Text],
    [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n
          (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n
          (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])
forall a b. (a -> b) -> a -> b
$ (Int,
 [([Text],
   [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe
            (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])])
-> [([Text],
     [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe
              (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])]
forall a b. (a, b) -> b
snd ((Int,
  [([Text],
    [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n
          (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n
          (Maybe
             (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])])
 -> [([Text],
      [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe
               (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])])
-> (Int,
    [([Text],
      [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe
               (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])])
-> [([Text],
     [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe
              (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])]
forall a b. (a -> b) -> a -> b
$ (Int
 -> InputArgument FunctionArg
 -> (Int,
     ([Text],
      [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe
               (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])))
-> Int
-> [InputArgument FunctionArg]
-> (Int,
    [([Text],
      [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n
            (Maybe
               (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))])])
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL Int
-> FunctionInputArgument ('Postgres pgKind)
-> (Int,
    ([Text],
     [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe
              (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]))
Int
-> InputArgument FunctionArg
-> (Int,
    ([Text],
     [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe
              (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]))
splitArguments Int
1 [InputArgument FunctionArg]
inputArgs
      defaultArguments :: FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
defaultArguments = [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. [a] -> HashMap Text a -> FunctionArgsExpG a
FunctionArgsExp ((Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall a b. (a, b) -> b
snd ((Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
session) HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall k v. HashMap k v
HashMap.empty

  if
    | [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
session Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 ->
        -- We somehow found more than one session argument; this should never
        -- happen and is an error on our side.
        Text
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG
           (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall (m :: * -> *) a. QErrM m => Text -> m a
throw500 Text
"there shouldn't be more than one session argument"
    | [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
-> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
optional Bool -> Bool -> Bool
&& [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
-> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
mandatory ->
        -- There are no user-provided arguments to the function: there will be
        -- no args field.
        InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG
           (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputFieldsParser
   MetadataObjId
   n
   (FunctionArgsExpG
      (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
 -> SchemaT
      r
      m
      (InputFieldsParser
         MetadataObjId
         n
         (FunctionArgsExpG
            (ArgumentExp (UnpreparedValue ('Postgres pgKind))))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG
           (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall a b. (a -> b) -> a -> b
$ FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a. a -> InputFieldsParser MetadataObjId n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
defaultArguments
    | Bool
otherwise -> do
        -- There are user-provided arguments: we need to parse an args object.
        [InputFieldsParser
   n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))]
argumentParsers <- [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
-> SchemaT
     r
     m
     [InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA ([SchemaT
    r
    m
    (InputFieldsParser
       n
       (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
 -> SchemaT
      r
      m
      [InputFieldsParser
         n
         (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))])
-> [SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
-> SchemaT
     r
     m
     [InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))]
forall a b. (a -> b) -> a -> b
$ [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
optional [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
-> [SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
-> [SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
forall a. Semigroup a => a -> a -> a
<> [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
mandatory
        Name
objectName <-
          Name -> Name
mkTypename
            (Name -> Name)
-> (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase
            (GQLNameIdentifier -> Name)
-> SchemaT r m GQLNameIdentifier -> SchemaT r m Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case FunctionTrackedAs ('Postgres pgKind)
functionTrackedAs of
              FTAComputedField ComputedFieldName
computedFieldName SourceName
_sourceName TableName ('Postgres pgKind)
tableName -> do
                TableInfo ('Postgres pgKind)
tableInfo <- TableName ('Postgres pgKind)
-> SchemaT r m (TableInfo ('Postgres pgKind))
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName ('Postgres pgKind)
tableName
                Name
computedFieldGQLName <- Text -> SchemaT r m Name
forall (m :: * -> *). MonadError QErr m => Text -> m Name
textToName (Text -> SchemaT r m Name) -> Text -> SchemaT r m Name
forall a b. (a -> b) -> a -> b
$ ComputedFieldName -> Text
computedFieldNameToText ComputedFieldName
computedFieldName
                GQLNameIdentifier
tableGQLName <- forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName @('Postgres pgKind) TableInfo ('Postgres pgKind)
tableInfo
                pure $ Name -> GQLNameIdentifier -> GQLNameIdentifier
mkFunctionArgsTypeName Name
computedFieldGQLName GQLNameIdentifier
tableGQLName
              FTACustomFunction (CustomFunctionNames {Name
cfnArgsName :: CustomFunctionNames -> Name
cfnArgsName :: Name
cfnArgsName}) ->
                GQLNameIdentifier -> SchemaT r m GQLNameIdentifier
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GQLNameIdentifier -> SchemaT r m GQLNameIdentifier)
-> GQLNameIdentifier -> SchemaT r m GQLNameIdentifier
forall a b. (a -> b) -> a -> b
$ Name -> GQLNameIdentifier
C.fromCustomName Name
cfnArgsName
        let fieldName :: Name
fieldName = Name
Name._args
            fieldDesc :: Description
fieldDesc =
              case FunctionTrackedAs ('Postgres pgKind)
functionTrackedAs of
                FTAComputedField ComputedFieldName
computedFieldName SourceName
_sourceName TableName ('Postgres pgKind)
tableName ->
                  Text -> Description
G.Description
                    (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input parameters for computed field "
                    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ComputedFieldName
computedFieldName
                    ComputedFieldName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" defined on table "
                    Text -> QualifiedTable -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName ('Postgres pgKind)
QualifiedTable
tableName
                FTACustomFunction (CustomFunctionNames {Name
cfnFunctionName :: CustomFunctionNames -> Name
cfnFunctionName :: Name
cfnFunctionName}) ->
                  Text -> Description
G.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input parameters for function " Text -> Name -> Text
forall t. ToTxt t => Text -> t -> Text
<>> Name
cfnFunctionName
            objectParser :: Parser
  MetadataObjId
  'Input
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
objectParser =
              Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> Parser
     MetadataObjId
     'Input
     n
     [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
objectName Maybe Description
forall a. Maybe a
Nothing ([InputFieldsParser
   n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))]
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
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
   n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))]
argumentParsers) Parser
  MetadataObjId
  'Input
  n
  [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> ([Maybe
       (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
    -> n (FunctionArgsExpG
            (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> Parser
     MetadataObjId
     'Input
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall (m :: * -> *) origin (k :: Kind) a b.
Monad m =>
Parser origin k m a -> (a -> m b) -> Parser origin k m b
`P.bind` \[Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
arguments -> do
                -- After successfully parsing, we create a dictionary of the parsed fields
                -- and we re-iterate through the original list of sql arguments, now with
                -- the knowledge of their graphql name.
                let foundArguments :: HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
foundArguments = [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
 -> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a b. (a -> b) -> a -> b
$ [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
arguments [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
forall a. Semigroup a => a -> a -> a
<> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
session
                    argsWithNames :: [(Text, InputArgument FunctionArg)]
argsWithNames = [Text]
-> [InputArgument FunctionArg]
-> [(Text, InputArgument FunctionArg)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Text]
names [InputArgument FunctionArg]
inputArgs

                -- All elements (in the orignal sql order) that are found in the result map
                -- are treated as positional arguments, whether they were originally named or
                -- not.
                ([ArgumentExp (UnpreparedValue ('Postgres pgKind))]
positional, [(Text, InputArgument FunctionArg)]
left) <- ((Text, InputArgument FunctionArg)
 -> n (Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> [(Text, InputArgument FunctionArg)]
-> n ([ArgumentExp (UnpreparedValue ('Postgres pgKind))],
      [(Text, InputArgument FunctionArg)])
forall (f :: * -> *) (m :: * -> *) a b.
(Foldable f, Monad m) =>
(a -> m (Maybe b)) -> f a -> m ([b], [a])
spanMaybeM (\(Text
name, InputArgument FunctionArg
_) -> Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a. a -> n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> n (Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ Text
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup Text
name HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
foundArguments) [(Text, InputArgument FunctionArg)]
argsWithNames

                -- If there are arguments left, it means we found one that was not passed
                -- positionally. As a result, any remaining argument will have to be passed
                -- by name. We fail with a parse error if we encounter a positional sql
                -- argument (that does not have a name in the sql function), as:
                --   * only the last positional arguments can be omitted;
                --   * it has no name we can use.
                -- We also fail if we find a mandatory argument that was not
                -- provided by the user.
                HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
named <- [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
 -> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> ([Maybe
       (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
    -> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))])
-> [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
 -> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> n [Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
-> n (HashMap
        Text (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Text, InputArgument FunctionArg)
 -> n (Maybe
         (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> [(Text, InputArgument FunctionArg)]
-> n [Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))]
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 (HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> (Text, FunctionInputArgument ('Postgres pgKind))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
namedArgument HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
foundArguments) [(Text, InputArgument FunctionArg)]
left
                pure $ [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. [a] -> HashMap Text a -> FunctionArgsExpG a
FunctionArgsExp [ArgumentExp (UnpreparedValue ('Postgres pgKind))]
positional HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
named
        InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG
           (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
          (InputFieldsParser
   MetadataObjId
   n
   (FunctionArgsExpG
      (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
 -> SchemaT
      r
      m
      (InputFieldsParser
         MetadataObjId
         n
         (FunctionArgsExpG
            (ArgumentExp (UnpreparedValue ('Postgres pgKind))))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG
           (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall a b. (a -> b) -> a -> b
$ if [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
-> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SchemaT
   r
   m
   (InputFieldsParser
      n
      (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]
mandatory
            then Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (FunctionArgsExpG
           (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
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 (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
fieldDesc) Parser
  MetadataObjId
  'Input
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
objectParser InputFieldsParser
  MetadataObjId
  n
  (Maybe
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> (Maybe
      (FunctionArgsExpG
         (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
    -> FunctionArgsExpG
         (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> Maybe
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. a -> Maybe a -> a
fromMaybe FunctionArgsExpG (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. FunctionArgsExpG a
emptyFunctionArgsExp
            else Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m a
P.field Name
fieldName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
fieldDesc) Parser
  MetadataObjId
  'Input
  n
  (FunctionArgsExpG
     (ArgumentExp (UnpreparedValue ('Postgres pgKind))))
objectParser
  where
    sessionPlaceholder :: Postgres.ArgumentExp (IR.UnpreparedValue b)
    sessionPlaceholder :: forall {b :: BackendType}. ArgumentExp (UnpreparedValue b)
sessionPlaceholder = UnpreparedValue b -> ArgumentExp (UnpreparedValue b)
forall a. a -> ArgumentExp a
Postgres.AEInput UnpreparedValue b
forall (b :: BackendType). UnpreparedValue b
IR.UVSession

    splitArguments ::
      Int ->
      FunctionInputArgument ('Postgres pgKind) ->
      ( Int,
        ( [Text], -- graphql names, in order
          [(Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))], -- session argument
          [SchemaT r m (InputFieldsParser n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))))], -- optional argument
          [SchemaT r m (InputFieldsParser n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))))] -- mandatory argument
        )
      )
    splitArguments :: Int
-> FunctionInputArgument ('Postgres pgKind)
-> (Int,
    ([Text],
     [(Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n
           (Maybe
              (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))]))
splitArguments Int
positionalIndex (IASessionVariables FunctionArgName
name) =
      let argName :: Text
argName = FunctionArgName -> Text
getFuncArgNameTxt FunctionArgName
name
       in (Int
positionalIndex, ([Text
argName], [(Text
argName, ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall {b :: BackendType}. ArgumentExp (UnpreparedValue b)
sessionPlaceholder)], [], []))
    splitArguments Int
positionalIndex (IAUserProvided FunctionArgument ('Postgres pgKind)
arg) =
      let (Text
argName, Int
newIndex) = case FunctionArg -> Maybe FunctionArgName
Postgres.faName FunctionArgument ('Postgres pgKind)
FunctionArg
arg of
            Maybe FunctionArgName
Nothing -> (Text
"arg_" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
tshow Int
positionalIndex, Int
positionalIndex Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
            Just FunctionArgName
name -> (FunctionArgName -> Text
getFuncArgNameTxt FunctionArgName
name, Int
positionalIndex)
       in if HasDefault -> Bool
Postgres.unHasDefault (HasDefault -> Bool) -> HasDefault -> Bool
forall a b. (a -> b) -> a -> b
$ FunctionArg -> HasDefault
Postgres.faHasDefault FunctionArgument ('Postgres pgKind)
FunctionArg
arg
            then (Int
newIndex, ([Text
argName], [], [FunctionArgument ('Postgres pgKind)
-> Text
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
parseArgument FunctionArgument ('Postgres pgKind)
arg Text
argName], []))
            else (Int
newIndex, ([Text
argName], [], [], [FunctionArgument ('Postgres pgKind)
-> Text
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
parseArgument FunctionArgument ('Postgres pgKind)
arg Text
argName]))

    parseArgument :: FunctionArgument ('Postgres pgKind) -> Text -> SchemaT r m (InputFieldsParser n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))))
    parseArgument :: FunctionArgument ('Postgres pgKind)
-> Text
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
parseArgument FunctionArgument ('Postgres pgKind)
arg Text
name = do
      Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind)))
typedParser <- ColumnType ('Postgres pgKind)
-> Nullability
-> SchemaT
     r
     m
     (Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema ('Postgres pgKind) r m n =>
ColumnType ('Postgres pgKind)
-> Nullability
-> SchemaT
     r
     m
     (Parser 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendSchema b, MonadBuildSchema b r m n) =>
ColumnType b
-> Nullability
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
columnParser (ScalarType ('Postgres pgKind) -> ColumnType ('Postgres pgKind)
forall (b :: BackendType). ScalarType b -> ColumnType b
ColumnScalar (ScalarType ('Postgres pgKind) -> ColumnType ('Postgres pgKind))
-> ScalarType ('Postgres pgKind) -> ColumnType ('Postgres pgKind)
forall a b. (a -> b) -> a -> b
$ QualifiedPGType -> PGScalarType
Postgres.mkFunctionArgScalarType (QualifiedPGType -> PGScalarType)
-> QualifiedPGType -> PGScalarType
forall a b. (a -> b) -> a -> b
$ FunctionArg -> QualifiedPGType
Postgres.faType FunctionArgument ('Postgres pgKind)
FunctionArg
arg) (Bool -> Nullability
G.Nullability Bool
True)
      Name
fieldName <- Text -> SchemaT r m Name
forall (m :: * -> *). MonadError QErr m => Text -> m Name
textToName Text
name

      -- Since all postgres function arguments are nullable, we define the
      -- GraphQL fields in nullable types. As explained in Note [When are fields
      -- optional?], this implies that they can be omitted. For backwards
      -- compatibility reasons, and also to avoid surprises, we prefer to reject
      -- the query if a mandatory argument is missing rather than filling the
      -- blanks for the user.
      --
      -- As explained in Note [The value of omitted fields], we can still reject
      -- queries when such nullable fields are omitted, and accept them when an
      -- explicit value of `null` is used, as long as we don't set a default
      -- value, not even `null`.
      let argParser :: InputFieldsParser
  MetadataObjId
  n
  (Maybe (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
argParser = Name
-> Maybe Description
-> Parser
     'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind)))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
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 'Both n (ValueWithOrigin (ColumnValue ('Postgres pgKind)))
typedParser
      InputFieldsParser
  n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputFieldsParser
   n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
 -> SchemaT
      r
      m
      (InputFieldsParser
         n
         (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))))
-> InputFieldsParser
     n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
forall a b. (a -> b) -> a -> b
$ InputFieldsParser
  MetadataObjId
  n
  (Maybe (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
argParser InputFieldsParser
  MetadataObjId
  n
  (Maybe (ValueWithOrigin (ColumnValue ('Postgres pgKind))))
-> (ValueWithOrigin (ColumnValue ('Postgres pgKind))
    -> (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> InputFieldsParser
     n (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall (m :: * -> *) a b.
Functor m =>
InputFieldsParser m (Maybe a)
-> (a -> b) -> InputFieldsParser m (Maybe b)
`mapField` ((Text
name,) (ArgumentExp (UnpreparedValue ('Postgres pgKind))
 -> (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
-> (ValueWithOrigin (ColumnValue ('Postgres pgKind))
    -> ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> ValueWithOrigin (ColumnValue ('Postgres pgKind))
-> (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnpreparedValue ('Postgres pgKind)
-> ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall a. a -> ArgumentExp a
Postgres.AEInput (UnpreparedValue ('Postgres pgKind)
 -> ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> (ValueWithOrigin (ColumnValue ('Postgres pgKind))
    -> UnpreparedValue ('Postgres pgKind))
-> ValueWithOrigin (ColumnValue ('Postgres pgKind))
-> ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueWithOrigin (ColumnValue ('Postgres pgKind))
-> UnpreparedValue ('Postgres pgKind)
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter)

    namedArgument ::
      HashMap Text (Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind))) ->
      (Text, FunctionInputArgument ('Postgres pgKind)) ->
      n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind))))
    namedArgument :: HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> (Text, FunctionInputArgument ('Postgres pgKind))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
namedArgument HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
dictionary (Text
name, FunctionInputArgument ('Postgres pgKind)
inputArgument) = case FunctionInputArgument ('Postgres pgKind)
inputArgument of
      IASessionVariables FunctionArgName
_ -> Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a. a -> n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> n (Maybe
         (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. a -> Maybe a
Just (Text
name, ArgumentExp (UnpreparedValue ('Postgres pgKind))
forall {b :: BackendType}. ArgumentExp (UnpreparedValue b)
sessionPlaceholder)
      IAUserProvided FunctionArgument ('Postgres pgKind)
arg -> case Text
-> HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup Text
name HashMap Text (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
dictionary of
        Just ArgumentExp (UnpreparedValue ('Postgres pgKind))
parsedValue -> case FunctionArg -> Maybe FunctionArgName
Postgres.faName FunctionArgument ('Postgres pgKind)
FunctionArg
arg of
          Just FunctionArgName
_ -> Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a. a -> n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> n (Maybe
         (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> Maybe (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. a -> Maybe a
Just (Text
name, ArgumentExp (UnpreparedValue ('Postgres pgKind))
parsedValue)
          Maybe FunctionArgName
Nothing -> ParseErrorCode
-> ErrorMessage
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a. ParseErrorCode -> ErrorMessage -> n a
forall (m :: * -> *) a.
MonadParse m =>
ParseErrorCode -> ErrorMessage -> m a
P.parseErrorWith ParseErrorCode
P.NotSupported ErrorMessage
"Only last set of positional arguments can be omitted"
        Maybe (ArgumentExp (UnpreparedValue ('Postgres pgKind)))
Nothing ->
          Bool
-> n (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall (m :: * -> *) a. Applicative m => Bool -> m a -> m (Maybe a)
whenMaybe (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ HasDefault -> Bool
Postgres.unHasDefault (HasDefault -> Bool) -> HasDefault -> Bool
forall a b. (a -> b) -> a -> b
$ FunctionArg -> HasDefault
Postgres.faHasDefault FunctionArgument ('Postgres pgKind)
FunctionArg
arg)
            (n (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
 -> n (Maybe
         (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))))
-> n (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
-> n (Maybe
        (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind))))
forall a b. (a -> b) -> a -> b
$ ParseErrorCode
-> ErrorMessage
-> n (Text, ArgumentExp (UnpreparedValue ('Postgres pgKind)))
forall a. ParseErrorCode -> ErrorMessage -> n a
forall (m :: * -> *) a.
MonadParse m =>
ParseErrorCode -> ErrorMessage -> m a
P.parseErrorWith ParseErrorCode
P.NotSupported ErrorMessage
"Non default arguments cannot be omitted"

buildFunctionQueryFieldsPG ::
  forall r m n pgKind.
  ( MonadBuildSchema ('Postgres pgKind) r m n,
    BackendTableSelectSchema ('Postgres pgKind)
  ) =>
  MkRootFieldName ->
  FunctionName ('Postgres pgKind) ->
  FunctionInfo ('Postgres pgKind) ->
  TableName ('Postgres pgKind) ->
  SchemaT r m [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField UnpreparedValue) (UnpreparedValue ('Postgres pgKind)))]
buildFunctionQueryFieldsPG :: forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionName ('Postgres pgKind)
-> FunctionInfo ('Postgres pgKind)
-> TableName ('Postgres pgKind)
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind)))]
buildFunctionQueryFieldsPG MkRootFieldName
mkRootFieldName FunctionName ('Postgres pgKind)
functionName FunctionInfo ('Postgres pgKind)
functionInfo TableName ('Postgres pgKind)
tableName = do
  let -- select function
      funcDesc :: Maybe Description
funcDesc =
        Description -> Maybe Description
forall a. a -> Maybe a
Just
          (Description -> Maybe Description)
-> (Text -> Description) -> Text -> Maybe Description
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Description
G.Description
          (Text -> Maybe Description) -> Text -> Maybe Description
forall a b. (a -> b) -> a -> b
$ (Text -> Maybe Text -> Text) -> Maybe Text -> Text -> Text
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe (FunctionInfo ('Postgres pgKind) -> Maybe Text
forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiComment FunctionInfo ('Postgres pgKind)
functionInfo)
          (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
"execute function "
          Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FunctionName ('Postgres pgKind)
QualifiedFunction
functionName
          QualifiedFunction -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" which returns "
          Text -> QualifiedTable -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName ('Postgres pgKind)
QualifiedTable
tableName
      -- select function agg
      funcAggDesc :: Maybe Description
funcAggDesc =
        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
"execute function " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FunctionName ('Postgres pgKind)
QualifiedFunction
functionName QualifiedFunction -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" and query aggregates on result of table type " Text -> QualifiedTable -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName ('Postgres pgKind)
QualifiedTable
tableName

      queryResultType :: AnnSimpleSelectG
  ('Postgres pgKind)
  (RemoteRelationshipField UnpreparedValue)
  (UnpreparedValue ('Postgres pgKind))
-> QueryDB
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
queryResultType =
        case FunctionInfo ('Postgres pgKind) -> JsonAggSelect
forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiJsonAggSelect FunctionInfo ('Postgres pgKind)
functionInfo of
          JsonAggSelect
JASMultipleRows -> AnnSimpleSelectG
  ('Postgres pgKind)
  (RemoteRelationshipField UnpreparedValue)
  (UnpreparedValue ('Postgres pgKind))
-> QueryDB
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
AnnSimpleSelectG b r v -> QueryDB b r v
QDBMultipleRows
          JsonAggSelect
JASSingleObject -> AnnSimpleSelectG
  ('Postgres pgKind)
  (RemoteRelationshipField UnpreparedValue)
  (UnpreparedValue ('Postgres pgKind))
-> QueryDB
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
AnnSimpleSelectG b r v -> QueryDB b r v
QDBSingleRow

  [Maybe
   (FieldParser
      n
      (QueryDB
         ('Postgres pgKind)
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue ('Postgres pgKind))))]
-> [FieldParser
      n
      (QueryDB
         ('Postgres pgKind)
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue ('Postgres pgKind)))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
    ([Maybe
    (FieldParser
       n
       (QueryDB
          ('Postgres pgKind)
          (RemoteRelationshipField UnpreparedValue)
          (UnpreparedValue ('Postgres pgKind))))]
 -> [FieldParser
       n
       (QueryDB
          ('Postgres pgKind)
          (RemoteRelationshipField UnpreparedValue)
          (UnpreparedValue ('Postgres pgKind)))])
-> SchemaT
     r
     m
     [Maybe
        (FieldParser
           n
           (QueryDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind))))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind)))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [SchemaT
   r
   m
   (Maybe
      (FieldParser
         n
         (QueryDB
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))]
-> SchemaT
     r
     m
     [Maybe
        (FieldParser
           n
           (QueryDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind))))]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA
      [ (AnnSimpleSelectG
   ('Postgres pgKind)
   (RemoteRelationshipField UnpreparedValue)
   (UnpreparedValue ('Postgres pgKind))
 -> QueryDB
      ('Postgres pgKind)
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue ('Postgres pgKind)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnSimpleSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (QueryDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall (n :: * -> *) (m :: * -> *) a b.
(Functor n, Functor m) =>
(a -> b)
-> m (Maybe (FieldParser n a)) -> m (Maybe (FieldParser n b))
optionalFieldParser (AnnSimpleSelectG
  ('Postgres pgKind)
  (RemoteRelationshipField UnpreparedValue)
  (UnpreparedValue ('Postgres pgKind))
-> QueryDB
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
queryResultType) (SchemaT
   r
   m
   (Maybe
      (FieldParser
         n
         (AnnSimpleSelectG
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))
 -> SchemaT
      r
      m
      (Maybe
         (FieldParser
            n
            (QueryDB
               ('Postgres pgKind)
               (RemoteRelationshipField UnpreparedValue)
               (UnpreparedValue ('Postgres pgKind))))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnSimpleSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (QueryDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall a b. (a -> b) -> a -> b
$ MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnSimpleSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r m (Maybe (FieldParser n (SelectExp ('Postgres pgKind))))
selectFunction MkRootFieldName
mkRootFieldName FunctionInfo ('Postgres pgKind)
functionInfo Maybe Description
funcDesc,
        (AnnAggregateSelectG
   ('Postgres pgKind)
   (RemoteRelationshipField UnpreparedValue)
   (UnpreparedValue ('Postgres pgKind))
 -> QueryDB
      ('Postgres pgKind)
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue ('Postgres pgKind)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnAggregateSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (QueryDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall (n :: * -> *) (m :: * -> *) a b.
(Functor n, Functor m) =>
(a -> b)
-> m (Maybe (FieldParser n a)) -> m (Maybe (FieldParser n b))
optionalFieldParser (AnnAggregateSelectG
  ('Postgres pgKind)
  (RemoteRelationshipField UnpreparedValue)
  (UnpreparedValue ('Postgres pgKind))
-> QueryDB
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
AnnAggregateSelectG b r v -> QueryDB b r v
QDBAggregation) (SchemaT
   r
   m
   (Maybe
      (FieldParser
         n
         (AnnAggregateSelectG
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))
 -> SchemaT
      r
      m
      (Maybe
         (FieldParser
            n
            (QueryDB
               ('Postgres pgKind)
               (RemoteRelationshipField UnpreparedValue)
               (UnpreparedValue ('Postgres pgKind))))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnAggregateSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (QueryDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall a b. (a -> b) -> a -> b
$ MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnAggregateSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r m (Maybe (FieldParser n (AggSelectExp ('Postgres pgKind))))
selectFunctionAggregate MkRootFieldName
mkRootFieldName FunctionInfo ('Postgres pgKind)
functionInfo Maybe Description
funcAggDesc
      ]

buildFunctionMutationFieldsPG ::
  forall r m n pgKind.
  ( MonadBuildSchema ('Postgres pgKind) r m n,
    BackendTableSelectSchema ('Postgres pgKind)
  ) =>
  MkRootFieldName ->
  FunctionName ('Postgres pgKind) ->
  FunctionInfo ('Postgres pgKind) ->
  TableName ('Postgres pgKind) ->
  SchemaT r m [FieldParser n (MutationDB ('Postgres pgKind) (RemoteRelationshipField UnpreparedValue) (UnpreparedValue ('Postgres pgKind)))]
buildFunctionMutationFieldsPG :: forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionName ('Postgres pgKind)
-> FunctionInfo ('Postgres pgKind)
-> TableName ('Postgres pgKind)
-> SchemaT
     r
     m
     [FieldParser
        n
        (MutationDB
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind)))]
buildFunctionMutationFieldsPG MkRootFieldName
mkRootFieldName FunctionName ('Postgres pgKind)
functionName FunctionInfo ('Postgres pgKind)
functionInfo TableName ('Postgres pgKind)
tableName = do
  let funcDesc :: Maybe Description
funcDesc = 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
"execute VOLATILE function " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FunctionName ('Postgres pgKind)
QualifiedFunction
functionName QualifiedFunction -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" which returns " Text -> QualifiedTable -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName ('Postgres pgKind)
QualifiedTable
tableName
      jsonAggSelect :: JsonAggSelect
jsonAggSelect = FunctionInfo ('Postgres pgKind) -> JsonAggSelect
forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiJsonAggSelect FunctionInfo ('Postgres pgKind)
functionInfo
  [Maybe
   (FieldParser
      n
      (MutationDB
         ('Postgres pgKind)
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue ('Postgres pgKind))))]
-> [FieldParser
      n
      (MutationDB
         ('Postgres pgKind)
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue ('Postgres pgKind)))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
    ([Maybe
    (FieldParser
       n
       (MutationDB
          ('Postgres pgKind)
          (RemoteRelationshipField UnpreparedValue)
          (UnpreparedValue ('Postgres pgKind))))]
 -> [FieldParser
       n
       (MutationDB
          ('Postgres pgKind)
          (RemoteRelationshipField UnpreparedValue)
          (UnpreparedValue ('Postgres pgKind)))])
-> SchemaT
     r
     m
     [Maybe
        (FieldParser
           n
           (MutationDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind))))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (MutationDB
           ('Postgres pgKind)
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue ('Postgres pgKind)))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [SchemaT
   r
   m
   (Maybe
      (FieldParser
         n
         (MutationDB
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))]
-> SchemaT
     r
     m
     [Maybe
        (FieldParser
           n
           (MutationDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind))))]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA
      [ (AnnSimpleSelectG
   ('Postgres pgKind)
   (RemoteRelationshipField UnpreparedValue)
   (UnpreparedValue ('Postgres pgKind))
 -> MutationDB
      ('Postgres pgKind)
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue ('Postgres pgKind)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnSimpleSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (MutationDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall (n :: * -> *) (m :: * -> *) a b.
(Functor n, Functor m) =>
(a -> b)
-> m (Maybe (FieldParser n a)) -> m (Maybe (FieldParser n b))
optionalFieldParser (JsonAggSelect
-> AnnSimpleSelectG
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
-> MutationDB
     ('Postgres pgKind)
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue ('Postgres pgKind))
forall (b :: BackendType) r v.
JsonAggSelect -> AnnSimpleSelectG b r v -> MutationDB b r v
MDBFunction JsonAggSelect
jsonAggSelect) (SchemaT
   r
   m
   (Maybe
      (FieldParser
         n
         (AnnSimpleSelectG
            ('Postgres pgKind)
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue ('Postgres pgKind)))))
 -> SchemaT
      r
      m
      (Maybe
         (FieldParser
            n
            (MutationDB
               ('Postgres pgKind)
               (RemoteRelationshipField UnpreparedValue)
               (UnpreparedValue ('Postgres pgKind))))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnSimpleSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (MutationDB
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall a b. (a -> b) -> a -> b
$ MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnSimpleSelectG
              ('Postgres pgKind)
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue ('Postgres pgKind)))))
forall r (m :: * -> *) (n :: * -> *) (pgKind :: PostgresKind).
(MonadBuildSchema ('Postgres pgKind) r m n,
 BackendTableSelectSchema ('Postgres pgKind)) =>
MkRootFieldName
-> FunctionInfo ('Postgres pgKind)
-> Maybe Description
-> SchemaT
     r m (Maybe (FieldParser n (SelectExp ('Postgres pgKind))))
selectFunction MkRootFieldName
mkRootFieldName FunctionInfo ('Postgres pgKind)
functionInfo Maybe Description
funcDesc
      -- TODO: do we want aggregate mutation functions?
      ]