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

module Hasura.GraphQL.Schema.Mutation
  ( insertIntoTable,
    insertOneIntoTable,
    deleteFromTable,
    deleteFromTableByPk,
    mkDefaultRelationshipParser,
    mutationSelectionSet,
    primaryKeysArguments,
  )
where

import Control.Lens ((^.))
import Data.Has (getter)
import Data.HashMap.Strict qualified as HashMap
import Data.HashSet qualified as Set
import Data.Text.Extended
import Hasura.GraphQL.Schema.Backend
import Hasura.GraphQL.Schema.BoolExp
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.Parser
  ( FieldParser,
    InputFieldsParser,
    Kind (..),
    Parser,
  )
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.BoolExp
import Hasura.RQL.IR.Delete qualified as IR
import Hasura.RQL.IR.Insert qualified as IR
import Hasura.RQL.IR.Returning qualified as IR
import Hasura.RQL.IR.Root qualified as IR
import Hasura.RQL.IR.Value qualified as IR
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.Column
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.Metadata.Object
import Hasura.RQL.Types.NamingCase (NamingCase)
import Hasura.RQL.Types.Relationships.Local
import Hasura.RQL.Types.SchemaCache hiding (askTableInfo)
import Hasura.RQL.Types.Source
import Hasura.RQL.Types.SourceCustomization
import Hasura.SQL.AnyBackend qualified as AB
import Hasura.Table.Cache
import Language.GraphQL.Draft.Syntax qualified as G

-- insert

-- | Construct the parser for a field that can be used to add several rows to a DB table.
--
-- This function is used to create the insert_tablename root field.
-- The field accepts the following arguments:
--   - objects: the list of objects to insert into the table (see 'tableFieldsInput')
--   - parser for backend-specific fields, e.g. upsert fields on_conflict or if_matched
insertIntoTable ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  (BackendTableSelectSchema b) =>
  (TableInfo b -> SchemaT r m (InputFieldsParser n (BackendInsert b (IR.UnpreparedValue b)))) ->
  Scenario ->
  -- | qualified name of the table
  TableInfo b ->
  -- | field display name
  G.Name ->
  -- | field description, if any
  Maybe G.Description ->
  SchemaT r m (Maybe (FieldParser n (IR.AnnotatedInsert b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b))))
insertIntoTable :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> Scenario
-> TableInfo b
-> Name
-> Maybe Description
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnotatedInsert
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
insertIntoTable TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction Scenario
scenario TableInfo b
tableInfo Name
fieldName Maybe Description
description = MaybeT
  (SchemaT r m)
  (FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnotatedInsert
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (FieldParser
      n
      (AnnotatedInsert
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
 -> SchemaT
      r
      m
      (Maybe
         (FieldParser
            n
            (AnnotatedInsert
               b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))))
-> MaybeT
     (SchemaT r m)
     (FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnotatedInsert
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall a b. (a -> b) -> a -> b
$ do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> MaybeT (SchemaT r m) (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  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 b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      viewInfo :: Maybe ViewInfo
viewInfo = TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> Maybe ViewInfo
_tciViewInfo (TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo)
-> TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall a b. (a -> b) -> a -> b
$ TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo TableInfo b
tableInfo
      permissions :: RolePermInfo b
permissions = RoleName -> TableInfo b -> RolePermInfo b
forall (b :: BackendType).
RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
roleName TableInfo b
tableInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention (ResolvedSourceCustomization -> NamingCase)
-> ResolvedSourceCustomization -> NamingCase
forall a b. (a -> b) -> a -> b
$ SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
  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
$ (ViewInfo -> Bool) -> Maybe ViewInfo -> Bool
isMutable ViewInfo -> Bool
viIsInsertable Maybe ViewInfo
viewInfo
  InsPermInfo b
insertPerms <- Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b))
-> Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall a b. (a -> b) -> a -> b
$ RolePermInfo b -> Maybe (InsPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (InsPermInfo b)
_permIns RolePermInfo b
permissions
  -- If we're in a frontend scenario, we should not include backend_only inserts
  -- For more info see Note [Backend only permissions]
  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
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Scenario
scenario Scenario -> Scenario -> Bool
forall a. Eq a => a -> a -> Bool
== Scenario
Frontend Bool -> Bool -> Bool
&& InsPermInfo b -> Bool
forall (b :: BackendType). InsPermInfo b -> Bool
ipiBackendOnly InsPermInfo b
insertPerms
  SchemaT
  r
  m
  (FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift do
    let updatePerms :: Maybe (UpdPermInfo b)
updatePerms = RolePermInfo b -> Maybe (UpdPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (UpdPermInfo b)
_permUpd RolePermInfo b
permissions
    -- objects [{ ... }]
    Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser <- TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
tableFieldsInput TableInfo b
tableInfo
    InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser <- TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
tableInfo
    -- returning clause, affected rows, etc.
    Parser
  'Output
  n
  (MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
selectionParser <- TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
mutationSelectionSet TableInfo b
tableInfo
    let argsParser :: InputFieldsParser
  MetadataObjId n (AnnotatedInsertData b [] (UnpreparedValue b))
argsParser = do
          BackendInsert b (UnpreparedValue b)
backendInsert <- InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser
          [AnnotatedInsertRow b (UnpreparedValue b)]
objects <- Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
-> InputFieldsParser
     MetadataObjId n [AnnotatedInsertRow b (UnpreparedValue b)]
forall {m :: * -> *} {k :: Kind} {origin} {a}.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> InputFieldsParser origin m [a]
mkObjectsArg Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser
          pure $ [AnnotatedInsertRow b (UnpreparedValue b)]
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> AnnotatedInsertData b [] (UnpreparedValue b)
forall (b :: BackendType) (f :: * -> *).
BackendSchema b =>
f (AnnotatedInsertRow b (UnpreparedValue b))
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> AnnotatedInsertData b f (UnpreparedValue b)
mkInsertObject [AnnotatedInsertRow b (UnpreparedValue b)]
objects TableInfo b
tableInfo BackendInsert b (UnpreparedValue b)
backendInsert InsPermInfo b
insertPerms Maybe (UpdPermInfo b)
updatePerms
    FieldParser
  n
  (AnnotatedInsert
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> SchemaT
     r
     m
     (FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      (FieldParser
   n
   (AnnotatedInsert
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> SchemaT
      r
      m
      (FieldParser
         n
         (AnnotatedInsert
            b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> SchemaT
     r
     m
     (FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ MetadataObjId
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (m :: * -> *) origin a.
origin -> FieldParser origin m a -> FieldParser origin m a
P.setFieldParserOrigin (SourceName -> AnyBackend SourceMetadataObjId -> MetadataObjId
MOSourceObjId SourceName
sourceName (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
AB.mkAnyBackend (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId)
-> SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType). TableName b -> SourceMetadataObjId b
SMOTable @b TableName b
tableName))
      (FieldParser
   n
   (AnnotatedInsert
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> FieldParser
      n
      (AnnotatedInsert
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertData b [] (UnpreparedValue b))
-> Parser
     'Output
     n
     (MutFldsG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     MetadataObjId
     n
     (AnnotatedInsertData b [] (UnpreparedValue b),
      MutFldsG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
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 (AnnotatedInsertData b [] (UnpreparedValue b))
argsParser Parser
  'Output
  n
  (MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
selectionParser
      FieldParser
  MetadataObjId
  n
  (AnnotatedInsertData b [] (UnpreparedValue b),
   MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> ((AnnotatedInsertData b [] (UnpreparedValue b),
     MutFldsG
       b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
    -> AnnotatedInsert
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(AnnotatedInsertData b [] (UnpreparedValue b)
insertObject, MutFldsG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
output) -> Text
-> Bool
-> AnnotatedInsertData b [] (UnpreparedValue b)
-> MutationOutputG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
-> Maybe NamingCase
-> AnnotatedInsert
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v.
Text
-> Bool
-> MultiObjectInsert b v
-> MutationOutputG b r v
-> Maybe NamingCase
-> AnnotatedInsert b r v
IR.AnnotatedInsert (Name -> Text
G.unName Name
fieldName) Bool
False AnnotatedInsertData b [] (UnpreparedValue b)
insertObject (MutFldsG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
-> MutationOutputG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v.
MutFldsG b r v -> MutationOutputG b r v
IR.MOutMultirowFields MutFldsG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
output) (NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase)
  where
    mkObjectsArg :: Parser origin k m a -> InputFieldsParser origin m [a]
mkObjectsArg Parser origin k m a
objectParser =
      Name
-> Maybe Description
-> Parser origin k m [a]
-> InputFieldsParser origin m [a]
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
Name._objects
        (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
"the rows to be inserted")
        (Parser origin k m a -> Parser origin k m [a]
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m [a]
P.list Parser origin k m a
objectParser)

-- | Variant of 'insertIntoTable' that inserts a single row.
--
-- Instead of expecting a list of rows to insert in a 'objects' argument, this
-- field instead expects a single 'object'. Its selection set is also slightly
-- different: it only allows selecting columns from the row being inserted.
insertOneIntoTable ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  (BackendTableSelectSchema b) =>
  (TableInfo b -> SchemaT r m (InputFieldsParser n (BackendInsert b (IR.UnpreparedValue b)))) ->
  Scenario ->
  -- | table info
  TableInfo b ->
  -- | field display name
  G.Name ->
  -- | field description, if any
  Maybe G.Description ->
  SchemaT r m (Maybe (FieldParser n (IR.AnnotatedInsert b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b))))
insertOneIntoTable :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> Scenario
-> TableInfo b
-> Name
-> Maybe Description
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnotatedInsert
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
insertOneIntoTable TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction Scenario
scenario TableInfo b
tableInfo Name
fieldName Maybe Description
description = MaybeT
  (SchemaT r m)
  (FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnotatedInsert
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> MaybeT (SchemaT r m) (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  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 b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      viewInfo :: Maybe ViewInfo
viewInfo = TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> Maybe ViewInfo
_tciViewInfo (TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo)
-> TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall a b. (a -> b) -> a -> b
$ TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo TableInfo b
tableInfo
      permissions :: RolePermInfo b
permissions = RoleName -> TableInfo b -> RolePermInfo b
forall (b :: BackendType).
RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
roleName TableInfo b
tableInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention (ResolvedSourceCustomization -> NamingCase)
-> ResolvedSourceCustomization -> NamingCase
forall a b. (a -> b) -> a -> b
$ SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
  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
$ (ViewInfo -> Bool) -> Maybe ViewInfo -> Bool
isMutable ViewInfo -> Bool
viIsInsertable Maybe ViewInfo
viewInfo
  InsPermInfo b
insertPerms <- Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b))
-> Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall a b. (a -> b) -> a -> b
$ RolePermInfo b -> Maybe (InsPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (InsPermInfo b)
_permIns RolePermInfo b
permissions
  -- If we're in a frontend scenario, we should not include backend_only inserts
  -- For more info see Note [Backend only permissions]
  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
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Scenario
scenario Scenario -> Scenario -> Bool
forall a. Eq a => a -> a -> Bool
== Scenario
Frontend Bool -> Bool -> Bool
&& InsPermInfo b -> Bool
forall (b :: BackendType). InsPermInfo b -> Bool
ipiBackendOnly InsPermInfo b
insertPerms
  Parser 'Output n (AnnotatedFields b)
selectionParser <- SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
-> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
 -> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b)))
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
-> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b))
forall a b. (a -> b) -> a -> b
$ TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema b r m n =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
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 b
tableInfo
  SchemaT
  r
  m
  (FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift do
    let updatePerms :: Maybe (UpdPermInfo b)
updatePerms = RolePermInfo b -> Maybe (UpdPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (UpdPermInfo b)
_permUpd RolePermInfo b
permissions
    Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser <- TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
tableFieldsInput TableInfo b
tableInfo
    InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser <- TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
tableInfo
    let argsParser :: InputFieldsParser
  MetadataObjId n (AnnotatedInsertData b [] (UnpreparedValue b))
argsParser = do
          BackendInsert b (UnpreparedValue b)
backendInsert <- InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser
          AnnotatedInsertRow b (UnpreparedValue b)
object <- Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
forall {m :: * -> *} {k :: Kind} {origin} {a}.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> InputFieldsParser origin m a
mkObjectArg Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser
          pure $ [AnnotatedInsertRow b (UnpreparedValue b)]
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> AnnotatedInsertData b [] (UnpreparedValue b)
forall (b :: BackendType) (f :: * -> *).
BackendSchema b =>
f (AnnotatedInsertRow b (UnpreparedValue b))
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> AnnotatedInsertData b f (UnpreparedValue b)
mkInsertObject [AnnotatedInsertRow b (UnpreparedValue b)
object] TableInfo b
tableInfo BackendInsert b (UnpreparedValue b)
backendInsert InsPermInfo b
insertPerms Maybe (UpdPermInfo b)
updatePerms
    FieldParser
  n
  (AnnotatedInsert
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> SchemaT
     r
     m
     (FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      (FieldParser
   n
   (AnnotatedInsert
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> SchemaT
      r
      m
      (FieldParser
         n
         (AnnotatedInsert
            b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> SchemaT
     r
     m
     (FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ MetadataObjId
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (m :: * -> *) origin a.
origin -> FieldParser origin m a -> FieldParser origin m a
P.setFieldParserOrigin (SourceName -> AnyBackend SourceMetadataObjId -> MetadataObjId
MOSourceObjId SourceName
sourceName (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
AB.mkAnyBackend (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId)
-> SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType). TableName b -> SourceMetadataObjId b
SMOTable @b TableName b
tableName))
      (FieldParser
   n
   (AnnotatedInsert
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> FieldParser
      n
      (AnnotatedInsert
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertData b [] (UnpreparedValue b))
-> Parser 'Output n (AnnotatedFields b)
-> FieldParser
     MetadataObjId
     n
     (AnnotatedInsertData b [] (UnpreparedValue b), AnnotatedFields b)
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 (AnnotatedInsertData b [] (UnpreparedValue b))
argsParser Parser 'Output n (AnnotatedFields b)
selectionParser
      FieldParser
  MetadataObjId
  n
  (AnnotatedInsertData b [] (UnpreparedValue b), AnnotatedFields b)
-> ((AnnotatedInsertData b [] (UnpreparedValue b),
     AnnotatedFields b)
    -> AnnotatedInsert
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnotatedInsert
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(AnnotatedInsertData b [] (UnpreparedValue b)
insertObject, AnnotatedFields b
output) -> Text
-> Bool
-> AnnotatedInsertData b [] (UnpreparedValue b)
-> MutationOutputG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
-> Maybe NamingCase
-> AnnotatedInsert
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v.
Text
-> Bool
-> MultiObjectInsert b v
-> MutationOutputG b r v
-> Maybe NamingCase
-> AnnotatedInsert b r v
IR.AnnotatedInsert (Name -> Text
G.unName Name
fieldName) Bool
True AnnotatedInsertData b [] (UnpreparedValue b)
insertObject (AnnotatedFields b
-> MutationOutputG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v.
AnnFieldsG b r v -> MutationOutputG b r v
IR.MOutSinglerowObject AnnotatedFields b
output) (NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase)
  where
    mkObjectArg :: Parser origin k m a -> InputFieldsParser origin m a
mkObjectArg Parser origin k m a
objectParser =
      Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m a
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
Name._object
        (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
"the row to be inserted")
        Parser origin k m a
objectParser

-- | Creates the parser for an input object for a row of the given table.
--
-- This function creates an input object type named "tablename_insert_input" in
-- the GraphQL shema, which has a field for each of the columns of that table
-- that the user has insert permissions for.
--
-- > {
-- >  insert_author (
-- >    objects: [
-- >      { # tableFieldsInput output
-- >        name: "John",
-- >        id:12
-- >      }
-- >    ] ...
-- >  ) ...
-- > }
--
-- TODO: When there are no columns to insert, accessible to a role,
-- this function may generate an empty input object. The GraphQL spec
-- mandates that an input object type must define one or more input fields.
-- In this case, when there are no columns that are accessible to a role,
-- we should disallow generating the `insert_<table>` and the `insert_<table>_one`
-- altogether.
tableFieldsInput ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  -- | qualified name of the table
  TableInfo b ->
  SchemaT r m (Parser 'Input n (IR.AnnotatedInsertRow b (IR.UnpreparedValue b)))
tableFieldsInput :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
tableFieldsInput TableInfo b
tableInfo = do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> SchemaT r m (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  let sourceName :: SourceName
sourceName = SourceInfo b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      allFields :: FieldInfoMap (FieldInfo b)
allFields = TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
-> FieldInfoMap (FieldInfo b)
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> FieldInfoMap field
_tciFieldInfoMap (TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
 -> FieldInfoMap (FieldInfo b))
-> (TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b))
-> TableInfo b
-> FieldInfoMap (FieldInfo b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo (TableInfo b -> FieldInfoMap (FieldInfo b))
-> TableInfo b -> FieldInfoMap (FieldInfo b)
forall a b. (a -> b) -> a -> b
$ TableInfo b
tableInfo
      customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
      mkTypename :: Name -> Name
mkTypename = MkTypename -> Name -> Name
runMkTypename (MkTypename -> Name -> Name) -> MkTypename -> Name -> Name
forall a b. (a -> b) -> a -> b
$ ResolvedSourceCustomization -> MkTypename
_rscTypeNames ResolvedSourceCustomization
customization
  Name
-> (SourceName, TableName b)
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
 Typeable b) =>
Name -> a -> m (p n b) -> m (p n b)
P.memoizeOn 'tableFieldsInput (SourceName
sourceName, TableName b
tableName) do
    GQLNameIdentifier
tableGQLName <- TableInfo b -> SchemaT r m GQLNameIdentifier
forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName TableInfo b
tableInfo
    [Maybe
   (InputFieldsParser
      n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
objectFields <- (FieldInfo b
 -> SchemaT
      r
      m
      (Maybe
         (InputFieldsParser
            n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))))
-> [FieldInfo b]
-> SchemaT
     r
     m
     [Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse FieldInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
mkFieldParser (FieldInfoMap (FieldInfo b) -> [FieldInfo b]
forall k v. HashMap k v -> [v]
HashMap.elems FieldInfoMap (FieldInfo b)
allFields)
    let objectName :: Name
objectName = Name -> Name
mkTypename (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier
mkTableInsertInputTypeName GQLNameIdentifier
tableGQLName
        objectDesc :: Description
objectDesc = Text -> Description
G.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input type for inserting data into table " Text -> TableName b -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName b
tableName
    Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
 -> SchemaT
      r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))))
-> Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
-> Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
objectName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
objectDesc) (InputFieldsParser
   MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
 -> Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
-> Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ [Maybe
   (InputFieldsParser
      n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
coalesceFields [Maybe
   (InputFieldsParser
      n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
objectFields
  where
    -- For each field, we have a Maybe parser: not all fields will be allowed
    -- (we don't allow insertions in computed fields for instance). Each parser
    -- returns a maybe value, as some of the fields may be omitted. This
    -- function does the necessary transformations to coalesce all of this in
    -- one 'InputFieldsParser'.
    coalesceFields ::
      [Maybe (InputFieldsParser n (Maybe (IR.AnnotatedInsertField b (IR.UnpreparedValue b))))] ->
      InputFieldsParser n (IR.AnnotatedInsertRow b (IR.UnpreparedValue b))
    coalesceFields :: [Maybe
   (InputFieldsParser
      n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
coalesceFields = ([Maybe (AnnotatedInsertField b (UnpreparedValue b))]
 -> AnnotatedInsertRow b (UnpreparedValue b))
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe (AnnotatedInsertField b (UnpreparedValue b))]
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
forall a b.
(a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Maybe (AnnotatedInsertField b (UnpreparedValue b))]
-> AnnotatedInsertRow b (UnpreparedValue b)
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes (InputFieldsParser
   MetadataObjId
   n
   [Maybe (AnnotatedInsertField b (UnpreparedValue b))]
 -> InputFieldsParser
      MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b)))
-> ([Maybe
       (InputFieldsParser
          n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
    -> InputFieldsParser
         MetadataObjId
         n
         [Maybe (AnnotatedInsertField b (UnpreparedValue b))])
-> [Maybe
      (InputFieldsParser
         n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [InputFieldsParser
   n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))]
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe (AnnotatedInsertField b (UnpreparedValue b))]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA ([InputFieldsParser
    n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))]
 -> InputFieldsParser
      MetadataObjId
      n
      [Maybe (AnnotatedInsertField b (UnpreparedValue b))])
-> ([Maybe
       (InputFieldsParser
          n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
    -> [InputFieldsParser
          n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))])
-> [Maybe
      (InputFieldsParser
         n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe (AnnotatedInsertField b (UnpreparedValue b))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe
   (InputFieldsParser
      n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))]
-> [InputFieldsParser
      n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes

    mkFieldParser ::
      FieldInfo b ->
      SchemaT r m (Maybe (InputFieldsParser n (Maybe (IR.AnnotatedInsertField b (IR.UnpreparedValue b)))))
    mkFieldParser :: FieldInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
mkFieldParser = \case
      FIComputedField ComputedFieldInfo b
_ -> Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
forall a. Maybe a
Nothing
      FIRemoteRelationship RemoteFieldInfo (DBJoinField b)
_ -> Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
forall a. Maybe a
Nothing
      FIColumn (SCIScalarColumn ColumnInfo b
columnInfo) -> do
        if (ColumnMutability -> Bool
_cmIsInsertable (ColumnMutability -> Bool) -> ColumnMutability -> Bool
forall a b. (a -> b) -> a -> b
$ ColumnInfo b -> ColumnMutability
forall (b :: BackendType). ColumnInfo b -> ColumnMutability
ciMutability ColumnInfo b
columnInfo)
          then ColumnInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
mkColumnParser ColumnInfo b
columnInfo
          else Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
forall a. Maybe a
Nothing
      FIColumn (SCIObjectColumn NestedObjectInfo b
_) -> Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
forall a. Maybe a
Nothing -- TODO(dmoverton)
      FIColumn (SCIArrayColumn NestedArrayInfo b
_) -> Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
forall a. Maybe a
Nothing -- TODO(dmoverton)
      FIRelationship RelInfo b
relInfo -> RelInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
RelInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendSchema b, MonadBuildSchema b r m n) =>
RelInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
mkRelationshipParser RelInfo b
relInfo

    mkColumnParser ::
      ColumnInfo b ->
      SchemaT r m (Maybe (InputFieldsParser n (Maybe (IR.AnnotatedInsertField b (IR.UnpreparedValue b)))))
    mkColumnParser :: ColumnInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
mkColumnParser ColumnInfo b
columnInfo = MaybeT
  (SchemaT r m)
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (InputFieldsParser
      n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
 -> SchemaT
      r
      m
      (Maybe
         (InputFieldsParser
            n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser
        n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall a b. (a -> b) -> a -> b
$ do
      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
      InsPermInfo b
insertPerms <- Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b))
-> Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall a b. (a -> b) -> a -> b
$ RolePermInfo b -> Maybe (InsPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (InsPermInfo b)
_permIns (RolePermInfo b -> Maybe (InsPermInfo b))
-> RolePermInfo b -> Maybe (InsPermInfo b)
forall a b. (a -> b) -> a -> b
$ RoleName -> TableInfo b -> RolePermInfo b
forall (b :: BackendType).
RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
roleName TableInfo b
tableInfo
      let columnName :: Name
columnName = ColumnInfo b -> Name
forall (b :: BackendType). ColumnInfo b -> Name
ciName ColumnInfo b
columnInfo
          columnDesc :: Maybe Description
columnDesc = ColumnInfo b -> Maybe Description
forall (b :: BackendType). ColumnInfo b -> Maybe Description
ciDescription ColumnInfo b
columnInfo
          isAllowed :: Bool
isAllowed = Column b -> HashSet (Column b) -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
Set.member (ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn ColumnInfo b
columnInfo) (InsPermInfo b -> HashSet (Column b)
forall (b :: BackendType). InsPermInfo b -> HashSet (Column b)
ipiCols InsPermInfo b
insertPerms)
      Bool -> MaybeT (SchemaT r m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
isAllowed
      Parser 'Both n (ValueWithOrigin (ColumnValue b))
fieldParser <- SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
-> MaybeT
     (SchemaT r m) (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
 -> MaybeT
      (SchemaT r m) (Parser 'Both n (ValueWithOrigin (ColumnValue b))))
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
-> MaybeT
     (SchemaT r m) (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
forall a b. (a -> b) -> a -> b
$ ColumnType b
-> Nullability
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
ColumnType b
-> Nullability
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue 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 (ColumnInfo b -> ColumnType b
forall (b :: BackendType). ColumnInfo b -> ColumnType b
ciType ColumnInfo b
columnInfo) (Bool -> Nullability
G.Nullability (Bool -> Nullability) -> Bool -> Nullability
forall a b. (a -> b) -> a -> b
$ ColumnInfo b -> Bool
forall (b :: BackendType). ColumnInfo b -> Bool
ciIsNullable ColumnInfo b
columnInfo)
      pure
        $ Name
-> Maybe Description
-> Parser 'Both n (ValueWithOrigin (ColumnValue b))
-> InputFieldsParser
     MetadataObjId n (Maybe (ValueWithOrigin (ColumnValue b)))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
columnName Maybe Description
columnDesc Parser 'Both n (ValueWithOrigin (ColumnValue b))
fieldParser
        InputFieldsParser
  MetadataObjId n (Maybe (ValueWithOrigin (ColumnValue b)))
-> (ValueWithOrigin (ColumnValue b)
    -> AnnotatedInsertField b (UnpreparedValue b))
-> InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))
forall (m :: * -> *) a b.
Functor m =>
InputFieldsParser m (Maybe a)
-> (a -> b) -> InputFieldsParser m (Maybe b)
`mapField` \ValueWithOrigin (ColumnValue b)
value ->
          (Column b, UnpreparedValue b)
-> AnnotatedInsertField b (UnpreparedValue b)
forall (b :: BackendType) v.
(Column b, v) -> AnnotatedInsertField b v
IR.AIColumn (ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn ColumnInfo b
columnInfo, ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter ValueWithOrigin (ColumnValue b)
value)

mkDefaultRelationshipParser ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  (TableInfo b -> SchemaT r m (InputFieldsParser n (BackendInsert b (IR.UnpreparedValue b)))) ->
  XNestedInserts b ->
  RelInfo b ->
  SchemaT r m (Maybe (InputFieldsParser n (Maybe (IR.AnnotatedInsertField b (IR.UnpreparedValue b)))))
mkDefaultRelationshipParser :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> XNestedInserts b
-> RelInfo b
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
mkDefaultRelationshipParser TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction XNestedInserts b
xNestedInserts RelInfo b
relationshipInfo = MaybeT
  (SchemaT r m)
  (InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (InputFieldsParser
           n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
  TableName b
otherTableName <- case RelInfo b -> RelTarget b
forall (b :: BackendType). RelInfo b -> RelTarget b
riTarget RelInfo b
relationshipInfo of
    RelTargetNativeQuery NativeQueryName
_ -> [Char] -> MaybeT (SchemaT r m) (TableName b)
forall a. HasCallStack => [Char] -> a
error [Char]
"mkDefaultRelationshipParser RelTargetNativeQuery"
    RelTargetTable TableName b
tn -> TableName b -> MaybeT (SchemaT r m) (TableName b)
forall a. a -> MaybeT (SchemaT r m) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TableName b
tn
  let relName :: RelName
relName = RelInfo b -> RelName
forall (b :: BackendType). RelInfo b -> RelName
riName RelInfo b
relationshipInfo
  TableInfo b
otherTableInfo <- TableName b -> MaybeT (SchemaT r m) (TableInfo b)
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
askTableInfo TableName b
otherTableName
  Name
relFieldName <- 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
$ RelName -> Text
relNameToTxt RelName
relName
  case RelInfo b -> RelType
forall (b :: BackendType). RelInfo b -> RelType
riType RelInfo b
relationshipInfo of
    RelType
ObjRel -> do
      Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))
parser <- SchemaT
  r
  m
  (Maybe
     (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT
   r
   m
   (Maybe
      (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
 -> MaybeT
      (SchemaT r m)
      (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe
        (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ (TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> TableInfo b
-> SchemaT
     r
     m
     (Maybe
        (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> TableInfo b
-> SchemaT
     r
     m
     (Maybe
        (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
objectRelationshipInput TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
otherTableInfo
      pure
        $ Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe (SingleObjectInsert b (UnpreparedValue b)))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe (SingleObjectInsert b (UnpreparedValue b))))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
relFieldName Maybe Description
forall a. Maybe a
Nothing (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe (SingleObjectInsert b (UnpreparedValue b)))
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))
parser)
        InputFieldsParser
  MetadataObjId
  n
  (Maybe (Maybe (SingleObjectInsert b (UnpreparedValue b))))
-> (Maybe (Maybe (SingleObjectInsert b (UnpreparedValue b)))
    -> Maybe (AnnotatedInsertField b (UnpreparedValue b)))
-> InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Maybe (Maybe (SingleObjectInsert b (UnpreparedValue b)))
objRelIns -> do
          SingleObjectInsert b (UnpreparedValue b)
rel <- Maybe (Maybe (SingleObjectInsert b (UnpreparedValue b)))
-> Maybe (SingleObjectInsert b (UnpreparedValue b))
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join Maybe (Maybe (SingleObjectInsert b (UnpreparedValue b)))
objRelIns
          AnnotatedInsertField b (UnpreparedValue b)
-> Maybe (AnnotatedInsertField b (UnpreparedValue b))
forall a. a -> Maybe a
Just (AnnotatedInsertField b (UnpreparedValue b)
 -> Maybe (AnnotatedInsertField b (UnpreparedValue b)))
-> AnnotatedInsertField b (UnpreparedValue b)
-> Maybe (AnnotatedInsertField b (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ XNestedInserts b
-> ObjectRelationInsert b (UnpreparedValue b)
-> AnnotatedInsertField b (UnpreparedValue b)
forall (b :: BackendType) v.
XNestedInserts b
-> ObjectRelationInsert b v -> AnnotatedInsertField b v
IR.AIObjectRelationship XNestedInserts b
xNestedInserts (ObjectRelationInsert b (UnpreparedValue b)
 -> AnnotatedInsertField b (UnpreparedValue b))
-> ObjectRelationInsert b (UnpreparedValue b)
-> AnnotatedInsertField b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ SingleObjectInsert b (UnpreparedValue b)
-> RelInfo b -> ObjectRelationInsert b (UnpreparedValue b)
forall (b :: BackendType) a. a -> RelInfo b -> RelationInsert b a
IR.RelationInsert SingleObjectInsert b (UnpreparedValue b)
rel RelInfo b
relationshipInfo
    RelType
ArrRel -> do
      Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))
parser <- SchemaT
  r
  m
  (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT
   r
   m
   (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
 -> MaybeT
      (SchemaT r m)
      (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ (TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> TableInfo b
-> SchemaT
     r
     m
     (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> TableInfo b
-> SchemaT
     r
     m
     (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
arrayRelationshipInput TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
otherTableInfo
      pure
        $ Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe (MultiObjectInsert b (UnpreparedValue b)))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (Maybe (MultiObjectInsert b (UnpreparedValue b))))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
relFieldName Maybe Description
forall a. Maybe a
Nothing (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))
-> Parser
     MetadataObjId
     'Input
     n
     (Maybe (MultiObjectInsert b (UnpreparedValue b)))
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))
parser)
        InputFieldsParser
  MetadataObjId
  n
  (Maybe (Maybe (MultiObjectInsert b (UnpreparedValue b))))
-> (Maybe (Maybe (MultiObjectInsert b (UnpreparedValue b)))
    -> Maybe (AnnotatedInsertField b (UnpreparedValue b)))
-> InputFieldsParser
     n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Maybe (Maybe (MultiObjectInsert b (UnpreparedValue b)))
arrRelIns -> do
          MultiObjectInsert b (UnpreparedValue b)
rel <- Maybe (Maybe (MultiObjectInsert b (UnpreparedValue b)))
-> Maybe (MultiObjectInsert b (UnpreparedValue b))
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join Maybe (Maybe (MultiObjectInsert b (UnpreparedValue b)))
arrRelIns
          Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [AnnotatedInsertRow b (UnpreparedValue b)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([AnnotatedInsertRow b (UnpreparedValue b)] -> Bool)
-> [AnnotatedInsertRow b (UnpreparedValue b)] -> Bool
forall a b. (a -> b) -> a -> b
$ MultiObjectInsert b (UnpreparedValue b)
-> [AnnotatedInsertRow b (UnpreparedValue b)]
forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> f (AnnotatedInsertRow b v)
IR._aiInsertObject MultiObjectInsert b (UnpreparedValue b)
rel
          AnnotatedInsertField b (UnpreparedValue b)
-> Maybe (AnnotatedInsertField b (UnpreparedValue b))
forall a. a -> Maybe a
Just (AnnotatedInsertField b (UnpreparedValue b)
 -> Maybe (AnnotatedInsertField b (UnpreparedValue b)))
-> AnnotatedInsertField b (UnpreparedValue b)
-> Maybe (AnnotatedInsertField b (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ XNestedInserts b
-> ArrayRelationInsert b (UnpreparedValue b)
-> AnnotatedInsertField b (UnpreparedValue b)
forall (b :: BackendType) v.
XNestedInserts b
-> ArrayRelationInsert b v -> AnnotatedInsertField b v
IR.AIArrayRelationship XNestedInserts b
xNestedInserts (ArrayRelationInsert b (UnpreparedValue b)
 -> AnnotatedInsertField b (UnpreparedValue b))
-> ArrayRelationInsert b (UnpreparedValue b)
-> AnnotatedInsertField b (UnpreparedValue b)
forall a b. (a -> b) -> a -> b
$ MultiObjectInsert b (UnpreparedValue b)
-> RelInfo b -> ArrayRelationInsert b (UnpreparedValue b)
forall (b :: BackendType) a. a -> RelInfo b -> RelationInsert b a
IR.RelationInsert MultiObjectInsert b (UnpreparedValue b)
rel RelInfo b
relationshipInfo

-- | Construct the parser for an input object that represents an insert through
-- an object relationship.
--
-- When inserting objects into tables, we allow insertions through
-- relationships. This function creates the parser for an object that represents
-- the insertion object across an object relationship; it is co-recursive with
-- 'tableFieldsInput'
objectRelationshipInput ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  (TableInfo b -> SchemaT r m (InputFieldsParser n (BackendInsert b (IR.UnpreparedValue b)))) ->
  TableInfo b ->
  SchemaT r m (Maybe (Parser 'Input n (IR.SingleObjectInsert b (IR.UnpreparedValue b))))
objectRelationshipInput :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> TableInfo b
-> SchemaT
     r
     m
     (Maybe
        (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
objectRelationshipInput TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
tableInfo = MaybeT
  (SchemaT r m)
  (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
 -> SchemaT
      r
      m
      (Maybe
         (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
forall a b. (a -> b) -> a -> b
$ do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> MaybeT (SchemaT r m) (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  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 b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
      mkTypename :: Name -> Name
mkTypename = MkTypename -> Name -> Name
runMkTypename (MkTypename -> Name -> Name) -> MkTypename -> Name -> Name
forall a b. (a -> b) -> a -> b
$ ResolvedSourceCustomization -> MkTypename
_rscTypeNames ResolvedSourceCustomization
customization
      permissions :: RolePermInfo b
permissions = RoleName -> TableInfo b -> RolePermInfo b
forall (b :: BackendType).
RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
roleName TableInfo b
tableInfo
      updatePerms :: Maybe (UpdPermInfo b)
updatePerms = RolePermInfo b -> Maybe (UpdPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (UpdPermInfo b)
_permUpd RolePermInfo b
permissions
  InsPermInfo b
insertPerms <- Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b))
-> Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall a b. (a -> b) -> a -> b
$ RolePermInfo b -> Maybe (InsPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (InsPermInfo b)
_permIns RolePermInfo b
permissions
  SchemaT
  r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SchemaT
   r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
 -> MaybeT
      (SchemaT r m)
      (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
-> SchemaT
     r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ Name
-> (SourceName, TableName b)
-> SchemaT
     r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
-> SchemaT
     r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
 Typeable b) =>
Name -> a -> m (p n b) -> m (p n b)
P.memoizeOn 'objectRelationshipInput (SourceName
sourceName, TableName b
tableName) do
    GQLNameIdentifier
tableGQLName <- TableInfo b -> SchemaT r m GQLNameIdentifier
forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName TableInfo b
tableInfo
    Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser <- TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
tableFieldsInput TableInfo b
tableInfo
    InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser <- TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
tableInfo
    let inputName :: Name
inputName = Name -> Name
mkTypename (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier
mkTableObjRelInsertInputTypeName (GQLNameIdentifier -> GQLNameIdentifier)
-> GQLNameIdentifier -> GQLNameIdentifier
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier
tableGQLName
        objectName :: Name
objectName = Name
Name._data
        inputDesc :: Description
inputDesc = Text -> Description
G.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input type for inserting object relation for remote table " Text -> TableName b -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName b
tableName
        inputParser :: InputFieldsParser
  MetadataObjId n (SingleObjectInsert b (UnpreparedValue b))
inputParser = do
          BackendInsert b (UnpreparedValue b)
backendInsert <- InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser
          AnnotatedInsertRow b (UnpreparedValue b)
object <- Name
-> Maybe Description
-> Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
-> InputFieldsParser
     MetadataObjId n (AnnotatedInsertRow b (UnpreparedValue b))
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
objectName Maybe Description
forall a. Maybe a
Nothing Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser
          pure $ Single (AnnotatedInsertRow b (UnpreparedValue b))
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> SingleObjectInsert b (UnpreparedValue b)
forall (b :: BackendType) (f :: * -> *).
BackendSchema b =>
f (AnnotatedInsertRow b (UnpreparedValue b))
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> AnnotatedInsertData b f (UnpreparedValue b)
mkInsertObject (AnnotatedInsertRow b (UnpreparedValue b)
-> Single (AnnotatedInsertRow b (UnpreparedValue b))
forall a. a -> Single a
IR.Single AnnotatedInsertRow b (UnpreparedValue b)
object) TableInfo b
tableInfo BackendInsert b (UnpreparedValue b)
backendInsert InsPermInfo b
insertPerms Maybe (UpdPermInfo b)
updatePerms
    Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))
-> SchemaT
     r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))
 -> SchemaT
      r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))))
-> Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))
-> SchemaT
     r m (Parser 'Input n (SingleObjectInsert b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId n (SingleObjectInsert b (UnpreparedValue b))
-> Parser 'Input n (SingleObjectInsert b (UnpreparedValue b))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
inputName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
inputDesc) InputFieldsParser
  MetadataObjId n (SingleObjectInsert b (UnpreparedValue b))
inputParser

-- | Construct the parser for an input object that represents an insert through
-- an array relationship.
--
-- When inserting objects into tables, we allow insertions through
-- relationships. This function creates the parser for an object that represents
-- the insertion object across an array relationship; it is co-recursive with
-- 'tableFieldsInput'.
arrayRelationshipInput ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  (TableInfo b -> SchemaT r m (InputFieldsParser n (BackendInsert b (IR.UnpreparedValue b)))) ->
  TableInfo b ->
  SchemaT r m (Maybe (Parser 'Input n (IR.MultiObjectInsert b (IR.UnpreparedValue b))))
arrayRelationshipInput :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> TableInfo b
-> SchemaT
     r
     m
     (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
arrayRelationshipInput TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
tableInfo = MaybeT
  (SchemaT r m)
  (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
 -> SchemaT
      r
      m
      (Maybe
         (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
forall a b. (a -> b) -> a -> b
$ do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> MaybeT (SchemaT r m) (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  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 b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
      mkTypename :: Name -> Name
mkTypename = MkTypename -> Name -> Name
runMkTypename (MkTypename -> Name -> Name) -> MkTypename -> Name -> Name
forall a b. (a -> b) -> a -> b
$ ResolvedSourceCustomization -> MkTypename
_rscTypeNames ResolvedSourceCustomization
customization
      permissions :: RolePermInfo b
permissions = RoleName -> TableInfo b -> RolePermInfo b
forall (b :: BackendType).
RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
roleName TableInfo b
tableInfo
      updatePerms :: Maybe (UpdPermInfo b)
updatePerms = RolePermInfo b -> Maybe (UpdPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (UpdPermInfo b)
_permUpd RolePermInfo b
permissions
  InsPermInfo b
insertPerms <- Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b))
-> Maybe (InsPermInfo b) -> MaybeT (SchemaT r m) (InsPermInfo b)
forall a b. (a -> b) -> a -> b
$ RolePermInfo b -> Maybe (InsPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (InsPermInfo b)
_permIns RolePermInfo b
permissions
  SchemaT
  r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SchemaT
   r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
 -> MaybeT
      (SchemaT r m)
      (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
-> SchemaT
     r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ Name
-> (SourceName, TableName b)
-> SchemaT
     r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
-> SchemaT
     r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
 Typeable b) =>
Name -> a -> m (p n b) -> m (p n b)
P.memoizeOn 'arrayRelationshipInput (SourceName
sourceName, TableName b
tableName) do
    GQLNameIdentifier
tableGQLName <- TableInfo b -> SchemaT r m GQLNameIdentifier
forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName TableInfo b
tableInfo
    Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser <- TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r m (Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b)))
tableFieldsInput TableInfo b
tableInfo
    InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser <- TableInfo b
-> SchemaT
     r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))
backendInsertAction TableInfo b
tableInfo
    let inputName :: Name
inputName = Name -> Name
mkTypename (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier
mkTableArrRelInsertInputTypeName GQLNameIdentifier
tableGQLName
        objectsName :: Name
objectsName = Name
Name._data
        inputDesc :: Description
inputDesc = Text -> Description
G.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input type for inserting array relation for remote table " Text -> TableName b -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName b
tableName
        inputParser :: InputFieldsParser
  MetadataObjId n (MultiObjectInsert b (UnpreparedValue b))
inputParser = do
          BackendInsert b (UnpreparedValue b)
backendInsert <- InputFieldsParser n (BackendInsert b (UnpreparedValue b))
backendInsertParser
          [AnnotatedInsertRow b (UnpreparedValue b)]
objects <- Name
-> Maybe Description
-> Parser
     MetadataObjId 'Input n [AnnotatedInsertRow b (UnpreparedValue b)]
-> InputFieldsParser
     MetadataObjId n [AnnotatedInsertRow b (UnpreparedValue b)]
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
objectsName Maybe Description
forall a. Maybe a
Nothing (Parser
   MetadataObjId 'Input n [AnnotatedInsertRow b (UnpreparedValue b)]
 -> InputFieldsParser
      MetadataObjId n [AnnotatedInsertRow b (UnpreparedValue b)])
-> Parser
     MetadataObjId 'Input n [AnnotatedInsertRow b (UnpreparedValue b)]
-> InputFieldsParser
     MetadataObjId n [AnnotatedInsertRow b (UnpreparedValue b)]
forall a b. (a -> b) -> a -> b
$ Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
-> Parser
     MetadataObjId 'Input n [AnnotatedInsertRow b (UnpreparedValue b)]
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m [a]
P.list Parser 'Input n (AnnotatedInsertRow b (UnpreparedValue b))
objectParser
          pure $ [AnnotatedInsertRow b (UnpreparedValue b)]
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> MultiObjectInsert b (UnpreparedValue b)
forall (b :: BackendType) (f :: * -> *).
BackendSchema b =>
f (AnnotatedInsertRow b (UnpreparedValue b))
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> AnnotatedInsertData b f (UnpreparedValue b)
mkInsertObject [AnnotatedInsertRow b (UnpreparedValue b)]
objects TableInfo b
tableInfo BackendInsert b (UnpreparedValue b)
backendInsert InsPermInfo b
insertPerms Maybe (UpdPermInfo b)
updatePerms
    Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))
-> SchemaT
     r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))
 -> SchemaT
      r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))))
-> Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))
-> SchemaT
     r m (Parser 'Input n (MultiObjectInsert b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId n (MultiObjectInsert b (UnpreparedValue b))
-> Parser 'Input n (MultiObjectInsert b (UnpreparedValue b))
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
inputName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
inputDesc) InputFieldsParser
  MetadataObjId n (MultiObjectInsert b (UnpreparedValue b))
inputParser

-- | Helper function that creates an 'AnnIns' object.
mkInsertObject ::
  forall b f.
  (BackendSchema b) =>
  f (IR.AnnotatedInsertRow b (IR.UnpreparedValue b)) ->
  TableInfo b ->
  BackendInsert b (IR.UnpreparedValue b) ->
  InsPermInfo b ->
  Maybe (UpdPermInfo b) ->
  IR.AnnotatedInsertData b f (IR.UnpreparedValue b)
mkInsertObject :: forall (b :: BackendType) (f :: * -> *).
BackendSchema b =>
f (AnnotatedInsertRow b (UnpreparedValue b))
-> TableInfo b
-> BackendInsert b (UnpreparedValue b)
-> InsPermInfo b
-> Maybe (UpdPermInfo b)
-> AnnotatedInsertData b f (UnpreparedValue b)
mkInsertObject f (AnnotatedInsertRow b (UnpreparedValue b))
objects TableInfo b
tableInfo BackendInsert b (UnpreparedValue b)
backendInsert InsPermInfo b
insertPerms Maybe (UpdPermInfo b)
updatePerms =
  IR.AnnotatedInsertData
    { _aiInsertObject :: f (AnnotatedInsertRow b (UnpreparedValue b))
_aiInsertObject = f (AnnotatedInsertRow b (UnpreparedValue b))
objects,
      _aiTableName :: TableName b
_aiTableName = TableName b
table,
      _aiCheckCondition :: (AnnBoolExp b (UnpreparedValue b),
 Maybe (AnnBoolExp b (UnpreparedValue b)))
_aiCheckCondition = (AnnBoolExp b (UnpreparedValue b)
insertCheck, Maybe (AnnBoolExp b (UnpreparedValue b))
updateCheck),
      _aiTableColumns :: [ColumnInfo b]
_aiTableColumns = [ColumnInfo b]
columns,
      _aiPrimaryKey :: Maybe (NESeq (Column b))
_aiPrimaryKey = Maybe (NESeq (Column b))
primaryKey,
      _aiExtraTableMetadata :: ExtraTableMetadata b
_aiExtraTableMetadata = ExtraTableMetadata b
extraTableMetadata,
      _aiPresetValues :: PreSetColsG b (UnpreparedValue b)
_aiPresetValues = PreSetColsG b (UnpreparedValue b)
presetValues,
      _aiBackendInsert :: BackendInsert b (UnpreparedValue b)
_aiBackendInsert = BackendInsert b (UnpreparedValue b)
backendInsert,
      _aiValidateInput :: Maybe (ValidateInput ResolvedWebhook)
_aiValidateInput = InsPermInfo b -> Maybe (ValidateInput ResolvedWebhook)
forall (b :: BackendType).
InsPermInfo b -> Maybe (ValidateInput ResolvedWebhook)
ipiValidateInput InsPermInfo b
insertPerms
    }
  where
    table :: TableName b
table = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
    columns :: [ColumnInfo b]
columns = TableInfo b -> [ColumnInfo b]
forall (b :: BackendType). TableInfo b -> [ColumnInfo b]
tableColumns TableInfo b
tableInfo
    primaryKey :: Maybe (NESeq (Column b))
primaryKey = TableInfo b
tableInfo TableInfo b
-> Getting
     (Maybe (PrimaryKey b (ColumnInfo b)))
     (TableInfo b)
     (Maybe (PrimaryKey b (ColumnInfo b)))
-> Maybe (PrimaryKey b (ColumnInfo b))
forall s a. s -> Getting a s a -> a
^. (TableCoreInfo b
 -> Const (Maybe (PrimaryKey b (ColumnInfo b))) (TableCoreInfo b))
-> TableInfo b
-> Const (Maybe (PrimaryKey b (ColumnInfo b))) (TableInfo b)
forall (b :: BackendType) (f :: * -> *).
Functor f =>
(TableCoreInfo b -> f (TableCoreInfo b))
-> TableInfo b -> f (TableInfo b)
tiCoreInfo ((TableCoreInfo b
  -> Const (Maybe (PrimaryKey b (ColumnInfo b))) (TableCoreInfo b))
 -> TableInfo b
 -> Const (Maybe (PrimaryKey b (ColumnInfo b))) (TableInfo b))
-> ((Maybe (PrimaryKey b (ColumnInfo b))
     -> Const
          (Maybe (PrimaryKey b (ColumnInfo b)))
          (Maybe (PrimaryKey b (ColumnInfo b))))
    -> TableCoreInfo b
    -> Const (Maybe (PrimaryKey b (ColumnInfo b))) (TableCoreInfo b))
-> Getting
     (Maybe (PrimaryKey b (ColumnInfo b)))
     (TableInfo b)
     (Maybe (PrimaryKey b (ColumnInfo b)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (PrimaryKey b (ColumnInfo b))
 -> Const
      (Maybe (PrimaryKey b (ColumnInfo b)))
      (Maybe (PrimaryKey b (ColumnInfo b))))
-> TableCoreInfo b
-> Const (Maybe (PrimaryKey b (ColumnInfo b))) (TableCoreInfo b)
forall (b :: BackendType) field primaryKeyColumn1 primaryKeyColumn2
       (f :: * -> *).
Functor f =>
(Maybe (PrimaryKey b primaryKeyColumn1)
 -> f (Maybe (PrimaryKey b primaryKeyColumn2)))
-> TableCoreInfoG b field primaryKeyColumn1
-> f (TableCoreInfoG b field primaryKeyColumn2)
tciPrimaryKey Maybe (PrimaryKey b (ColumnInfo b))
-> (PrimaryKey b (ColumnInfo b) -> NESeq (Column b))
-> Maybe (NESeq (Column b))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (PrimaryKey b (ColumnInfo b) -> NESeq (ColumnInfo b)
forall (b :: BackendType) a. PrimaryKey b a -> NESeq a
_pkColumns (PrimaryKey b (ColumnInfo b) -> NESeq (ColumnInfo b))
-> (NESeq (ColumnInfo b) -> NESeq (Column b))
-> PrimaryKey b (ColumnInfo b)
-> NESeq (Column b)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (ColumnInfo b -> Column b)
-> NESeq (ColumnInfo b) -> NESeq (Column b)
forall a b. (a -> b) -> NESeq a -> NESeq b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn)
    extraTableMetadata :: ExtraTableMetadata b
extraTableMetadata = TableInfo b
tableInfo TableInfo b
-> Getting
     (ExtraTableMetadata b) (TableInfo b) (ExtraTableMetadata b)
-> ExtraTableMetadata b
forall s a. s -> Getting a s a -> a
^. (TableCoreInfo b -> Const (ExtraTableMetadata b) (TableCoreInfo b))
-> TableInfo b -> Const (ExtraTableMetadata b) (TableInfo b)
forall (b :: BackendType) (f :: * -> *).
Functor f =>
(TableCoreInfo b -> f (TableCoreInfo b))
-> TableInfo b -> f (TableInfo b)
tiCoreInfo ((TableCoreInfo b
  -> Const (ExtraTableMetadata b) (TableCoreInfo b))
 -> TableInfo b -> Const (ExtraTableMetadata b) (TableInfo b))
-> ((ExtraTableMetadata b
     -> Const (ExtraTableMetadata b) (ExtraTableMetadata b))
    -> TableCoreInfo b
    -> Const (ExtraTableMetadata b) (TableCoreInfo b))
-> Getting
     (ExtraTableMetadata b) (TableInfo b) (ExtraTableMetadata b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ExtraTableMetadata b
 -> Const (ExtraTableMetadata b) (ExtraTableMetadata b))
-> TableCoreInfo b
-> Const (ExtraTableMetadata b) (TableCoreInfo b)
forall (b :: BackendType) field primaryKeyColumn (f :: * -> *).
Functor f =>
(ExtraTableMetadata b -> f (ExtraTableMetadata b))
-> TableCoreInfoG b field primaryKeyColumn
-> f (TableCoreInfoG b field primaryKeyColumn)
tciExtraTableMetadata
    insertCheck :: AnnBoolExp b (UnpreparedValue b)
insertCheck = (PartialSQLExp b -> UnpreparedValue b)
-> AnnBoolExpFld b (PartialSQLExp b)
-> AnnBoolExpFld b (UnpreparedValue b)
forall a b. (a -> b) -> AnnBoolExpFld b a -> AnnBoolExpFld b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PartialSQLExp b -> UnpreparedValue b
forall (b :: BackendType). PartialSQLExp b -> UnpreparedValue b
partialSQLExpToUnpreparedValue (AnnBoolExpFld b (PartialSQLExp b)
 -> AnnBoolExpFld b (UnpreparedValue b))
-> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
-> AnnBoolExp b (UnpreparedValue b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InsPermInfo b -> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
forall (b :: BackendType). InsPermInfo b -> AnnBoolExpPartialSQL b
ipiCheck InsPermInfo b
insertPerms
    updateCheck :: Maybe (AnnBoolExp b (UnpreparedValue b))
updateCheck = ((GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
 -> AnnBoolExp b (UnpreparedValue b))
-> Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b)))
-> Maybe (AnnBoolExp b (UnpreparedValue b))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
  -> AnnBoolExp b (UnpreparedValue b))
 -> Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b)))
 -> Maybe (AnnBoolExp b (UnpreparedValue b)))
-> ((PartialSQLExp b -> UnpreparedValue b)
    -> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
    -> AnnBoolExp b (UnpreparedValue b))
-> (PartialSQLExp b -> UnpreparedValue b)
-> Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b)))
-> Maybe (AnnBoolExp b (UnpreparedValue b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AnnBoolExpFld b (PartialSQLExp b)
 -> AnnBoolExpFld b (UnpreparedValue b))
-> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
-> AnnBoolExp b (UnpreparedValue b)
forall a b. (a -> b) -> GBoolExp b a -> GBoolExp b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((AnnBoolExpFld b (PartialSQLExp b)
  -> AnnBoolExpFld b (UnpreparedValue b))
 -> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
 -> AnnBoolExp b (UnpreparedValue b))
-> ((PartialSQLExp b -> UnpreparedValue b)
    -> AnnBoolExpFld b (PartialSQLExp b)
    -> AnnBoolExpFld b (UnpreparedValue b))
-> (PartialSQLExp b -> UnpreparedValue b)
-> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
-> AnnBoolExp b (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PartialSQLExp b -> UnpreparedValue b)
-> AnnBoolExpFld b (PartialSQLExp b)
-> AnnBoolExpFld b (UnpreparedValue b)
forall a b. (a -> b) -> AnnBoolExpFld b a -> AnnBoolExpFld b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) PartialSQLExp b -> UnpreparedValue b
forall (b :: BackendType). PartialSQLExp b -> UnpreparedValue b
partialSQLExpToUnpreparedValue (Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b)))
 -> Maybe (AnnBoolExp b (UnpreparedValue b)))
-> Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b)))
-> Maybe (AnnBoolExp b (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ UpdPermInfo b
-> Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b)))
forall (b :: BackendType).
UpdPermInfo b -> Maybe (AnnBoolExpPartialSQL b)
upiCheck (UpdPermInfo b
 -> Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))))
-> Maybe (UpdPermInfo b)
-> Maybe (GBoolExp b (AnnBoolExpFld b (PartialSQLExp b)))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe (UpdPermInfo b)
updatePerms
    presetValues :: PreSetColsG b (UnpreparedValue b)
presetValues = PartialSQLExp b -> UnpreparedValue b
forall (b :: BackendType). PartialSQLExp b -> UnpreparedValue b
partialSQLExpToUnpreparedValue (PartialSQLExp b -> UnpreparedValue b)
-> HashMap (Column b) (PartialSQLExp b)
-> PreSetColsG b (UnpreparedValue b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InsPermInfo b -> HashMap (Column b) (PartialSQLExp b)
forall (b :: BackendType). InsPermInfo b -> PreSetColsPartial b
ipiSet InsPermInfo b
insertPerms

-- delete

-- | Construct a root field, normally called delete_tablename, that can be used
-- to delete several rows from a DB table
deleteFromTable ::
  forall b r m n.
  ( MonadBuildSchema b r m n,
    AggregationPredicatesSchema b,
    BackendTableSelectSchema b
  ) =>
  Scenario ->
  -- | table info
  TableInfo b ->
  -- | field display name
  G.Name ->
  -- | field description, if any
  Maybe G.Description ->
  SchemaT r m (Maybe (FieldParser n (IR.AnnDelG b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b))))
deleteFromTable :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, AggregationPredicatesSchema b,
 BackendTableSelectSchema b) =>
Scenario
-> TableInfo b
-> Name
-> Maybe Description
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnDelG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
deleteFromTable Scenario
scenario TableInfo b
tableInfo Name
fieldName Maybe Description
description = MaybeT
  (SchemaT r m)
  (FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnDelG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (FieldParser
      n
      (AnnDelG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
 -> SchemaT
      r
      m
      (Maybe
         (FieldParser
            n
            (AnnDelG
               b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))))
-> MaybeT
     (SchemaT r m)
     (FieldParser
        n
        (AnnDelG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnDelG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall a b. (a -> b) -> a -> b
$ do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> MaybeT (SchemaT r m) (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  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 b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
      viewInfo :: Maybe ViewInfo
viewInfo = TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> Maybe ViewInfo
_tciViewInfo (TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo)
-> TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall a b. (a -> b) -> a -> b
$ TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo TableInfo b
tableInfo
  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
$ (ViewInfo -> Bool) -> Maybe ViewInfo -> Bool
isMutable ViewInfo -> Bool
viIsInsertable Maybe ViewInfo
viewInfo
  DelPermInfo b
deletePerms <- Maybe (DelPermInfo b) -> MaybeT (SchemaT r m) (DelPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (DelPermInfo b) -> MaybeT (SchemaT r m) (DelPermInfo b))
-> Maybe (DelPermInfo b) -> MaybeT (SchemaT r m) (DelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RolePermInfo b -> Maybe (DelPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (DelPermInfo b)
_permDel (RolePermInfo b -> Maybe (DelPermInfo b))
-> RolePermInfo b -> Maybe (DelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RoleName -> TableInfo b -> RolePermInfo b
forall (b :: BackendType).
RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
roleName TableInfo b
tableInfo
  -- If we're in a frontend scenario, we should not include backend_only deletes
  -- For more info see Note [Backend only permissions]
  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
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Scenario
scenario Scenario -> Scenario -> Bool
forall a. Eq a => a -> a -> Bool
== Scenario
Frontend Bool -> Bool -> Bool
&& DelPermInfo b -> Bool
forall (b :: BackendType). DelPermInfo b -> Bool
dpiBackendOnly DelPermInfo b
deletePerms
  SchemaT
  r
  m
  (FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (FieldParser
        n
        (AnnDelG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift do
    let whereName :: Name
whereName = Name
Name._where
        whereDesc :: Description
whereDesc = Description
"filter the rows which have to be deleted"
    InputFieldsParser
  MetadataObjId n (AnnBoolExp b (UnpreparedValue b))
whereArg <- Name
-> Maybe Description
-> Parser MetadataObjId 'Input n (AnnBoolExp b (UnpreparedValue b))
-> InputFieldsParser
     MetadataObjId n (AnnBoolExp b (UnpreparedValue b))
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
whereName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
whereDesc) (Parser MetadataObjId 'Input n (AnnBoolExp b (UnpreparedValue b))
 -> InputFieldsParser
      MetadataObjId n (AnnBoolExp b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Parser MetadataObjId 'Input n (AnnBoolExp b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId n (AnnBoolExp b (UnpreparedValue b)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TableInfo b
-> SchemaT
     r
     m
     (Parser MetadataObjId 'Input n (AnnBoolExp b (UnpreparedValue b)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, AggregationPredicatesSchema b) =>
TableInfo b
-> SchemaT r m (Parser 'Input n (AnnBoolExp b (UnpreparedValue b)))
tableBoolExp TableInfo b
tableInfo
    Parser
  'Output
  n
  (MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
selection <- TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
mutationSelectionSet TableInfo b
tableInfo
    let columns :: [ColumnInfo b]
columns = TableInfo b -> [ColumnInfo b]
forall (b :: BackendType). TableInfo b -> [ColumnInfo b]
tableColumns TableInfo b
tableInfo
    pure
      $ MetadataObjId
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (m :: * -> *) origin a.
origin -> FieldParser origin m a -> FieldParser origin m a
P.setFieldParserOrigin (SourceName -> AnyBackend SourceMetadataObjId -> MetadataObjId
MOSourceObjId SourceName
sourceName (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
AB.mkAnyBackend (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId)
-> SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType). TableName b -> SourceMetadataObjId b
SMOTable @b TableName b
tableName))
      (FieldParser
   n
   (AnnDelG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> FieldParser
      n
      (AnnDelG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId n (AnnBoolExp b (UnpreparedValue b))
-> Parser
     'Output
     n
     (MutFldsG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     MetadataObjId
     n
     (AnnBoolExp b (UnpreparedValue b),
      MutFldsG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
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 (AnnBoolExp b (UnpreparedValue b))
whereArg Parser
  'Output
  n
  (MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
selection
      FieldParser
  MetadataObjId
  n
  (AnnBoolExp b (UnpreparedValue b),
   MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> ((AnnBoolExp b (UnpreparedValue b),
     MutFldsG
       b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
    -> AnnDelG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> TableName b
-> [ColumnInfo b]
-> DelPermInfo b
-> Maybe NamingCase
-> Bool
-> (AnnBoolExp b (UnpreparedValue b),
    MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> AnnDelG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType).
Backend b =>
TableName b
-> [ColumnInfo b]
-> DelPermInfo b
-> Maybe NamingCase
-> Bool
-> (AnnBoolExp b (UnpreparedValue b),
    MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> AnnDelG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
mkDeleteObject (TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo) [ColumnInfo b]
columns DelPermInfo b
deletePerms (NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase) Bool
False
      ((AnnBoolExp b (UnpreparedValue b),
  MutationOutputG
    b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> AnnDelG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> ((AnnBoolExp b (UnpreparedValue b),
     MutFldsG
       b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
    -> (AnnBoolExp b (UnpreparedValue b),
        MutationOutputG
          b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> (AnnBoolExp b (UnpreparedValue b),
    MutFldsG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> AnnDelG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MutFldsG
   b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
 -> MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> (AnnBoolExp b (UnpreparedValue b),
    MutFldsG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> (AnnBoolExp b (UnpreparedValue b),
    MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall a b.
(a -> b)
-> (AnnBoolExp b (UnpreparedValue b), a)
-> (AnnBoolExp b (UnpreparedValue b), b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MutFldsG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
-> MutationOutputG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v.
MutFldsG b r v -> MutationOutputG b r v
IR.MOutMultirowFields

-- | Construct a root field, normally called delete_tablename_by_pk, that can be used to delete an
-- individual rows from a DB table, specified by primary key. Select permissions are required, as
-- the user must be allowed to access all the primary keys of the table.
deleteFromTableByPk ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  (BackendTableSelectSchema b) =>
  Scenario ->
  -- | table info
  TableInfo b ->
  -- | field display name
  G.Name ->
  -- | field description, if any
  Maybe G.Description ->
  SchemaT r m (Maybe (FieldParser n (IR.AnnDelG b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b))))
deleteFromTableByPk :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
Scenario
-> TableInfo b
-> Name
-> Maybe Description
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnDelG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
deleteFromTableByPk Scenario
scenario TableInfo b
tableInfo Name
fieldName Maybe Description
description = MaybeT
  (SchemaT r m)
  (FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnDelG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (FieldParser
      n
      (AnnDelG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
 -> SchemaT
      r
      m
      (Maybe
         (FieldParser
            n
            (AnnDelG
               b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))))
-> MaybeT
     (SchemaT r m)
     (FieldParser
        n
        (AnnDelG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnDelG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall a b. (a -> b) -> a -> b
$ do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> MaybeT (SchemaT r m) (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  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 b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
      viewInfo :: Maybe ViewInfo
viewInfo = TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn -> Maybe ViewInfo
_tciViewInfo (TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo)
-> TableCoreInfoG b (FieldInfo b) (ColumnInfo b) -> Maybe ViewInfo
forall a b. (a -> b) -> a -> b
$ TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo TableInfo b
tableInfo
      columns :: [ColumnInfo b]
columns = TableInfo b -> [ColumnInfo b]
forall (b :: BackendType). TableInfo b -> [ColumnInfo b]
tableColumns TableInfo b
tableInfo
  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
$ (ViewInfo -> Bool) -> Maybe ViewInfo -> Bool
isMutable ViewInfo -> Bool
viIsInsertable Maybe ViewInfo
viewInfo
  InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))
pkArgs <- SchemaT
  r
  m
  (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT
   r
   m
   (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
 -> MaybeT
      (SchemaT r m)
      (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ TableInfo b
-> SchemaT
     r
     m
     (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r
     m
     (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
primaryKeysArguments TableInfo b
tableInfo
  DelPermInfo b
deletePerms <- Maybe (DelPermInfo b) -> MaybeT (SchemaT r m) (DelPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (DelPermInfo b) -> MaybeT (SchemaT r m) (DelPermInfo b))
-> Maybe (DelPermInfo b) -> MaybeT (SchemaT r m) (DelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RolePermInfo b -> Maybe (DelPermInfo b)
forall (b :: BackendType). RolePermInfo b -> Maybe (DelPermInfo b)
_permDel (RolePermInfo b -> Maybe (DelPermInfo b))
-> RolePermInfo b -> Maybe (DelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RoleName -> TableInfo b -> RolePermInfo b
forall (b :: BackendType).
RoleName -> TableInfo b -> RolePermInfo b
getRolePermInfo RoleName
roleName TableInfo b
tableInfo
  -- If we're in a frontend scenario, we should not include backend_only deletes
  -- For more info see Note [Backend only permissions]
  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
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Scenario
scenario Scenario -> Scenario -> Bool
forall a. Eq a => a -> a -> Bool
== Scenario
Frontend Bool -> Bool -> Bool
&& DelPermInfo b -> Bool
forall (b :: BackendType). DelPermInfo b -> Bool
dpiBackendOnly DelPermInfo b
deletePerms
  Parser 'Output n (AnnotatedFields b)
selection <- SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
-> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
 -> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b)))
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
-> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b))
forall a b. (a -> b) -> a -> b
$ TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema b r m n =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
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 b
tableInfo
  pure
    $ MetadataObjId
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (m :: * -> *) origin a.
origin -> FieldParser origin m a -> FieldParser origin m a
P.setFieldParserOrigin (SourceName -> AnyBackend SourceMetadataObjId -> MetadataObjId
MOSourceObjId SourceName
sourceName (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
AB.mkAnyBackend (SourceMetadataObjId b -> AnyBackend SourceMetadataObjId)
-> SourceMetadataObjId b -> AnyBackend SourceMetadataObjId
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType). TableName b -> SourceMetadataObjId b
SMOTable @b TableName b
tableName))
    (FieldParser
   n
   (AnnDelG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> FieldParser
      n
      (AnnDelG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))
-> Parser 'Output n (AnnotatedFields b)
-> FieldParser
     MetadataObjId
     n
     (AnnBoolExp b (UnpreparedValue b), AnnotatedFields b)
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 n (AnnBoolExp b (UnpreparedValue b))
pkArgs Parser 'Output n (AnnotatedFields b)
selection
    FieldParser
  MetadataObjId
  n
  (AnnBoolExp b (UnpreparedValue b), AnnotatedFields b)
-> ((AnnBoolExp b (UnpreparedValue b), AnnotatedFields b)
    -> AnnDelG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser
     n
     (AnnDelG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> TableName b
-> [ColumnInfo b]
-> DelPermInfo b
-> Maybe NamingCase
-> Bool
-> (AnnBoolExp b (UnpreparedValue b),
    MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> AnnDelG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType).
Backend b =>
TableName b
-> [ColumnInfo b]
-> DelPermInfo b
-> Maybe NamingCase
-> Bool
-> (AnnBoolExp b (UnpreparedValue b),
    MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> AnnDelG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
mkDeleteObject (TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo) [ColumnInfo b]
columns DelPermInfo b
deletePerms (NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase) Bool
True
    ((AnnBoolExp b (UnpreparedValue b),
  MutationOutputG
    b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> AnnDelG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> ((AnnBoolExp b (UnpreparedValue b), AnnotatedFields b)
    -> (AnnBoolExp b (UnpreparedValue b),
        MutationOutputG
          b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> (AnnBoolExp b (UnpreparedValue b), AnnotatedFields b)
-> AnnDelG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AnnotatedFields b
 -> MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> (AnnBoolExp b (UnpreparedValue b), AnnotatedFields b)
-> (AnnBoolExp b (UnpreparedValue b),
    MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall a b.
(a -> b)
-> (AnnBoolExp b (UnpreparedValue b), a)
-> (AnnBoolExp b (UnpreparedValue b), b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AnnotatedFields b
-> MutationOutputG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v.
AnnFieldsG b r v -> MutationOutputG b r v
IR.MOutSinglerowObject

mkDeleteObject ::
  (Backend b) =>
  TableName b ->
  [ColumnInfo b] ->
  DelPermInfo b ->
  Maybe NamingCase ->
  Bool ->
  (AnnBoolExp b (IR.UnpreparedValue b), IR.MutationOutputG b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b)) ->
  IR.AnnDelG b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b)
mkDeleteObject :: forall (b :: BackendType).
Backend b =>
TableName b
-> [ColumnInfo b]
-> DelPermInfo b
-> Maybe NamingCase
-> Bool
-> (AnnBoolExp b (UnpreparedValue b),
    MutationOutputG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> AnnDelG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
mkDeleteObject TableName b
table [ColumnInfo b]
columns DelPermInfo b
deletePerms Maybe NamingCase
tCase Bool
isDeleteByPK (AnnBoolExp b (UnpreparedValue b)
whereExp, MutationOutputG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
mutationOutput) =
  IR.AnnDel
    { _adTable :: TableName b
IR._adTable = TableName b
table,
      _adWhere :: (AnnBoolExp b (UnpreparedValue b),
 AnnBoolExp b (UnpreparedValue b))
IR._adWhere = (AnnBoolExp b (UnpreparedValue b)
permissionFilter, AnnBoolExp b (UnpreparedValue b)
whereExp),
      _adOutput :: MutationOutputG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
IR._adOutput = MutationOutputG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
mutationOutput,
      _adAllCols :: [ColumnInfo b]
IR._adAllCols = [ColumnInfo b]
columns,
      _adNamingConvention :: Maybe NamingCase
IR._adNamingConvention = Maybe NamingCase
tCase,
      _adValidateInput :: Maybe (ValidateInput ResolvedWebhook)
IR._adValidateInput = DelPermInfo b -> Maybe (ValidateInput ResolvedWebhook)
forall (b :: BackendType).
DelPermInfo b -> Maybe (ValidateInput ResolvedWebhook)
dpiValidateInput DelPermInfo b
deletePerms,
      _adIsDeleteByPk :: Bool
IR._adIsDeleteByPk = Bool
isDeleteByPK
    }
  where
    permissionFilter :: AnnBoolExp b (UnpreparedValue b)
permissionFilter = (PartialSQLExp b -> UnpreparedValue b)
-> AnnBoolExpFld b (PartialSQLExp b)
-> AnnBoolExpFld b (UnpreparedValue b)
forall a b. (a -> b) -> AnnBoolExpFld b a -> AnnBoolExpFld b b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PartialSQLExp b -> UnpreparedValue b
forall (b :: BackendType). PartialSQLExp b -> UnpreparedValue b
partialSQLExpToUnpreparedValue (AnnBoolExpFld b (PartialSQLExp b)
 -> AnnBoolExpFld b (UnpreparedValue b))
-> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
-> AnnBoolExp b (UnpreparedValue b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DelPermInfo b -> GBoolExp b (AnnBoolExpFld b (PartialSQLExp b))
forall (b :: BackendType). DelPermInfo b -> AnnBoolExpPartialSQL b
dpiFilter DelPermInfo b
deletePerms

-- common

-- | All mutations allow returning results, such as what the updated database
-- rows look like. This parser allows a query to specify what data to fetch.
mutationSelectionSet ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  (BackendTableSelectSchema b) =>
  TableInfo b ->
  SchemaT r m (Parser 'Output n (IR.MutFldsG b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b)))
mutationSelectionSet :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
mutationSelectionSet TableInfo b
tableInfo = do
  SourceInfo b
sourceInfo :: SourceInfo b <- (r -> SourceInfo b) -> SchemaT r m (SourceInfo b)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo b
forall a t. Has a t => t -> a
getter
  RoleName
roleName <- (SchemaContext -> RoleName) -> SchemaT r m RoleName
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
retrieve SchemaContext -> RoleName
scRole
  let sourceName :: SourceName
sourceName = SourceInfo b -> SourceName
forall (b :: BackendType). SourceInfo b -> SourceName
_siName SourceInfo b
sourceInfo
      tableName :: TableName b
tableName = TableInfo b -> TableName b
forall (b :: BackendType). TableInfo b -> TableName b
tableInfoName TableInfo b
tableInfo
      customization :: ResolvedSourceCustomization
customization = SourceInfo b -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
_siCustomization SourceInfo b
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
_rscNamingConvention ResolvedSourceCustomization
customization
      mkTypename :: Name -> Name
mkTypename = MkTypename -> Name -> Name
runMkTypename (MkTypename -> Name -> Name) -> MkTypename -> Name -> Name
forall a b. (a -> b) -> a -> b
$ ResolvedSourceCustomization -> MkTypename
_rscTypeNames ResolvedSourceCustomization
customization
  Name
-> (SourceName, TableName b)
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
 Typeable b) =>
Name -> a -> m (p n b) -> m (p n b)
P.memoizeOn 'mutationSelectionSet (SourceName
sourceName, TableName b
tableName) do
    GQLNameIdentifier
tableGQLName <- TableInfo b -> SchemaT r m GQLNameIdentifier
forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
getTableIdentifierName TableInfo b
tableInfo
    Maybe
  (FieldParser
     MetadataObjId
     n
     (MutFldG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
returning <- MaybeT
  (SchemaT r m)
  (FieldParser
     MetadataObjId
     n
     (MutFldG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           MetadataObjId
           n
           (MutFldG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
      SelPermInfo b
_permissions <- Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b))
-> Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RoleName -> TableInfo b -> Maybe (SelPermInfo b)
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo b
tableInfo
      Parser 'Output n (AnnotatedFields b)
tableSet <- SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
-> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
 -> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b)))
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
-> MaybeT (SchemaT r m) (Parser 'Output n (AnnotatedFields b))
forall a b. (a -> b) -> a -> b
$ TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
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 b
tableInfo
      let returningName :: Name
returningName = Name
Name._returning
          returningDesc :: Description
returningDesc = Description
"data from the rows affected by the mutation"
      pure $ AnnotatedFields b
-> MutFldG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v. AnnFieldsG b r v -> MutFldG b r v
IR.MRet (AnnotatedFields b
 -> MutFldG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> FieldParser MetadataObjId n (AnnotatedFields b)
-> FieldParser
     MetadataObjId
     n
     (MutFldG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser 'Output n (AnnotatedFields b)
-> FieldParser MetadataObjId n (AnnotatedFields b)
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Output m a
-> FieldParser origin m a
P.subselection_ Name
returningName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
returningDesc) Parser 'Output n (AnnotatedFields b)
tableSet
    let selectionName :: Name
selectionName = Name -> Name
mkTypename (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ NamingCase -> GQLNameIdentifier -> Name
applyTypeNameCaseIdentifier NamingCase
tCase (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall a b. (a -> b) -> a -> b
$ GQLNameIdentifier -> GQLNameIdentifier
mkTableMutationResponseTypeName GQLNameIdentifier
tableGQLName
        affectedRowsName :: Name
affectedRowsName = NamingCase -> GQLNameIdentifier -> Name
applyFieldNameCaseIdentifier NamingCase
tCase GQLNameIdentifier
affectedRowsFieldName
        affectedRowsDesc :: Description
affectedRowsDesc = Description
"number of rows affected by the mutation"
        selectionDesc :: Description
selectionDesc = Text -> Description
G.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"response of any mutation on the table " Text -> TableName b -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName b
tableName
        selectionFields :: [FieldParser
   MetadataObjId
   n
   (MutFldG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
selectionFields =
          [Maybe
   (FieldParser
      MetadataObjId
      n
      (MutFldG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))]
-> [FieldParser
      MetadataObjId
      n
      (MutFldG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
            [ FieldParser
  MetadataObjId
  n
  (MutFldG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> Maybe
     (FieldParser
        MetadataObjId
        n
        (MutFldG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. a -> Maybe a
Just
                (FieldParser
   MetadataObjId
   n
   (MutFldG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> Maybe
      (FieldParser
         MetadataObjId
         n
         (MutFldG
            b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
-> FieldParser
     MetadataObjId
     n
     (MutFldG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> Maybe
     (FieldParser
        MetadataObjId
        n
        (MutFldG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ MutFldG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v. MutFldG b r v
IR.MCount
                MutFldG
  b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
-> FieldParser MetadataObjId n ()
-> FieldParser
     MetadataObjId
     n
     (MutFldG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall a b.
a -> FieldParser MetadataObjId n b -> FieldParser MetadataObjId n a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Name
-> Maybe Description
-> Parser MetadataObjId 'Both n Int32
-> FieldParser MetadataObjId n ()
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> Parser origin 'Both m a
-> FieldParser origin m ()
P.selection_ Name
affectedRowsName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
affectedRowsDesc) Parser MetadataObjId 'Both n Int32
forall (m :: * -> *) origin.
MonadParse m =>
Parser origin 'Both m Int32
P.int,
              Maybe
  (FieldParser
     MetadataObjId
     n
     (MutFldG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
returning
            ]
    Parser
  'Output
  n
  (MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      (Parser
   'Output
   n
   (MutFldsG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
 -> SchemaT
      r
      m
      (Parser
         'Output
         n
         (MutFldsG
            b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
-> Parser
     'Output
     n
     (MutFldsG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> SchemaT
     r
     m
     (Parser
        'Output
        n
        (MutFldsG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> [FieldParser
      MetadataObjId
      n
      (MutFldG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
-> Parser
     MetadataObjId
     'Output
     n
     (InsOrdHashMap
        Name
        (ParsedSelection
           (MutFldG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
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 (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
selectionDesc) [FieldParser
   MetadataObjId
   n
   (MutFldG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
selectionFields
      Parser
  MetadataObjId
  'Output
  n
  (InsOrdHashMap
     Name
     (ParsedSelection
        (MutFldG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
-> (InsOrdHashMap
      Name
      (ParsedSelection
         (MutFldG
            b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
    -> MutFldsG
         b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> Parser
     'Output
     n
     (MutFldsG
        b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (Text
 -> MutFldG
      b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))
-> InsOrdHashMap
     Name
     (ParsedSelection
        (MutFldG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> MutFldsG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall a.
(Text -> a) -> InsOrdHashMap Name (ParsedSelection a) -> Fields a
parsedSelectionsToFields Text
-> MutFldG
     b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)
forall (b :: BackendType) r v. Text -> MutFldG b r v
IR.MExp

-- | How to specify a database row by primary key.
--
-- This will give @Nothing@ when either there are no primary keys defined for
-- the table or when the given permissions do not permit selecting from all the
-- columns that make up the key.
primaryKeysArguments ::
  forall b r m n.
  (MonadBuildSchema b r m n) =>
  TableInfo b ->
  SchemaT r m (Maybe (InputFieldsParser n (AnnBoolExp b (IR.UnpreparedValue b))))
primaryKeysArguments :: forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r
     m
     (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
primaryKeysArguments TableInfo b
tableInfo = MaybeT
  (SchemaT r m)
  (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
   (SchemaT r m)
   (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
 -> SchemaT
      r
      m
      (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (Maybe (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
forall a b. (a -> b) -> a -> b
$ do
  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
  SelPermInfo b
selectPerms <- Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b))
-> Maybe (SelPermInfo b) -> MaybeT (SchemaT r m) (SelPermInfo b)
forall a b. (a -> b) -> a -> b
$ RoleName -> TableInfo b -> Maybe (SelPermInfo b)
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
tableSelectPermissions RoleName
roleName TableInfo b
tableInfo
  PrimaryKey b (ColumnInfo b)
primaryKeys <- Maybe (PrimaryKey b (ColumnInfo b))
-> MaybeT (SchemaT r m) (PrimaryKey b (ColumnInfo b))
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (PrimaryKey b (ColumnInfo b))
 -> MaybeT (SchemaT r m) (PrimaryKey b (ColumnInfo b)))
-> Maybe (PrimaryKey b (ColumnInfo b))
-> MaybeT (SchemaT r m) (PrimaryKey b (ColumnInfo b))
forall a b. (a -> b) -> a -> b
$ TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
-> Maybe (PrimaryKey b (ColumnInfo b))
forall (b :: BackendType) field primaryKeyColumn.
TableCoreInfoG b field primaryKeyColumn
-> Maybe (PrimaryKey b primaryKeyColumn)
_tciPrimaryKey (TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
 -> Maybe (PrimaryKey b (ColumnInfo b)))
-> (TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b))
-> TableInfo b
-> Maybe (PrimaryKey b (ColumnInfo b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TableInfo b -> TableCoreInfoG b (FieldInfo b) (ColumnInfo b)
forall (b :: BackendType). TableInfo b -> TableCoreInfo b
_tiCoreInfo (TableInfo b -> Maybe (PrimaryKey b (ColumnInfo b)))
-> TableInfo b -> Maybe (PrimaryKey b (ColumnInfo b))
forall a b. (a -> b) -> a -> b
$ TableInfo b
tableInfo
  let columns :: NESeq (ColumnInfo b)
columns = PrimaryKey b (ColumnInfo b) -> NESeq (ColumnInfo b)
forall (b :: BackendType) a. PrimaryKey b a -> NESeq a
_pkColumns PrimaryKey b (ColumnInfo b)
primaryKeys
  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
$ (ColumnInfo b -> Bool) -> NESeq (ColumnInfo b) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\ColumnInfo b
c -> ColumnInfo b -> Column b
forall (b :: BackendType). ColumnInfo b -> Column b
ciColumn ColumnInfo b
c Column b
-> HashMap (Column b) (AnnRedactionExpPartialSQL b) -> Bool
forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
`HashMap.member` SelPermInfo b -> HashMap (Column b) (AnnRedactionExpPartialSQL b)
forall (b :: BackendType).
SelPermInfo b -> HashMap (Column b) (AnnRedactionExpPartialSQL b)
spiCols SelPermInfo b
selectPerms) NESeq (ColumnInfo b)
columns
  SchemaT
  r m (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
    (SchemaT
   r m (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
 -> MaybeT
      (SchemaT r m)
      (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
-> SchemaT
     r m (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> MaybeT
     (SchemaT r m)
     (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
forall a b. (a -> b) -> a -> b
$ (NESeq (AnnBoolExp b (UnpreparedValue b))
 -> AnnBoolExp b (UnpreparedValue b))
-> InputFieldsParser
     MetadataObjId n (NESeq (AnnBoolExp b (UnpreparedValue b)))
-> InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))
forall a b.
(a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([AnnBoolExp b (UnpreparedValue b)]
-> AnnBoolExp b (UnpreparedValue b)
forall (backend :: BackendType) field.
[GBoolExp backend field] -> GBoolExp backend field
BoolAnd ([AnnBoolExp b (UnpreparedValue b)]
 -> AnnBoolExp b (UnpreparedValue b))
-> (NESeq (AnnBoolExp b (UnpreparedValue b))
    -> [AnnBoolExp b (UnpreparedValue b)])
-> NESeq (AnnBoolExp b (UnpreparedValue b))
-> AnnBoolExp b (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NESeq (AnnBoolExp b (UnpreparedValue b))
-> [AnnBoolExp b (UnpreparedValue b)]
forall a. NESeq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList)
    (InputFieldsParser
   MetadataObjId n (NESeq (AnnBoolExp b (UnpreparedValue b)))
 -> InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> (NESeq (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
    -> InputFieldsParser
         MetadataObjId n (NESeq (AnnBoolExp b (UnpreparedValue b))))
-> NESeq (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NESeq (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> InputFieldsParser
     MetadataObjId n (NESeq (AnnBoolExp b (UnpreparedValue b)))
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => NESeq (f a) -> f (NESeq a)
sequenceA
    (NESeq (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
 -> InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
-> SchemaT
     r
     m
     (NESeq (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
-> SchemaT
     r m (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NESeq (ColumnInfo b)
-> (ColumnInfo b
    -> SchemaT
         r m (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
-> SchemaT
     r
     m
     (NESeq (InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for NESeq (ColumnInfo b)
columns \ColumnInfo b
columnInfo -> do
      Parser 'Both n (ValueWithOrigin (ColumnValue b))
field <- ColumnType b
-> Nullability
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
ColumnType b
-> Nullability
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue 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 (ColumnInfo b -> ColumnType b
forall (b :: BackendType). ColumnInfo b -> ColumnType b
ciType ColumnInfo b
columnInfo) (Bool -> Nullability
G.Nullability Bool
False)
      pure
        $ AnnBoolExpFld b (UnpreparedValue b)
-> AnnBoolExp b (UnpreparedValue b)
forall (backend :: BackendType) field.
field -> GBoolExp backend field
BoolField
        (AnnBoolExpFld b (UnpreparedValue b)
 -> AnnBoolExp b (UnpreparedValue b))
-> (ValueWithOrigin (ColumnValue b)
    -> AnnBoolExpFld b (UnpreparedValue b))
-> ValueWithOrigin (ColumnValue b)
-> AnnBoolExp b (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ColumnInfo b
-> [OpExpG b (UnpreparedValue b)]
-> AnnBoolExpFld b (UnpreparedValue b)
forall (backend :: BackendType) leaf.
ColumnInfo backend
-> [OpExpG backend leaf] -> AnnBoolExpFld backend leaf
AVColumn ColumnInfo b
columnInfo
        ([OpExpG b (UnpreparedValue b)]
 -> AnnBoolExpFld b (UnpreparedValue b))
-> (ValueWithOrigin (ColumnValue b)
    -> [OpExpG b (UnpreparedValue b)])
-> ValueWithOrigin (ColumnValue b)
-> AnnBoolExpFld b (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OpExpG b (UnpreparedValue b) -> [OpExpG b (UnpreparedValue b)]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
        (OpExpG b (UnpreparedValue b) -> [OpExpG b (UnpreparedValue b)])
-> (ValueWithOrigin (ColumnValue b)
    -> OpExpG b (UnpreparedValue b))
-> ValueWithOrigin (ColumnValue b)
-> [OpExpG b (UnpreparedValue b)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ComparisonNullability
-> UnpreparedValue b -> OpExpG b (UnpreparedValue b)
forall (backend :: BackendType) field.
ComparisonNullability -> field -> OpExpG backend field
AEQ ComparisonNullability
NonNullableComparison
        (UnpreparedValue b -> OpExpG b (UnpreparedValue b))
-> (ValueWithOrigin (ColumnValue b) -> UnpreparedValue b)
-> ValueWithOrigin (ColumnValue b)
-> OpExpG b (UnpreparedValue b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter
        (ValueWithOrigin (ColumnValue b)
 -> AnnBoolExp b (UnpreparedValue b))
-> InputFieldsParser
     MetadataObjId n (ValueWithOrigin (ColumnValue b))
-> InputFieldsParser n (AnnBoolExp b (UnpreparedValue b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser 'Both n (ValueWithOrigin (ColumnValue b))
-> InputFieldsParser
     MetadataObjId n (ValueWithOrigin (ColumnValue b))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m a
P.field (ColumnInfo b -> Name
forall (b :: BackendType). ColumnInfo b -> Name
ciName ColumnInfo b
columnInfo) (ColumnInfo b -> Maybe Description
forall (b :: BackendType). ColumnInfo b -> Maybe Description
ciDescription ColumnInfo b
columnInfo) Parser 'Both n (ValueWithOrigin (ColumnValue b))
field