-- | The RQL query ('/v1/query')
module Hasura.Server.API.Query
  ( RQLQuery,
    queryModifiesSchemaCache,
    requiresAdmin,
    runQuery,
  )
where

import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Aeson qualified as J
import Data.Aeson.Casing qualified as J (snakeCase)
import Data.Environment qualified as Env
import Data.Has (Has)
import Hasura.App.State
import Hasura.Backends.Postgres.DDL.RunSQL
import Hasura.Base.Error
import Hasura.EncJSON
import Hasura.Function.API qualified as Functions
import Hasura.Logging qualified as L
import Hasura.Metadata.Class
import Hasura.Prelude
import Hasura.QueryTags
import Hasura.RQL.DDL.Action
import Hasura.RQL.DDL.ComputedField
import Hasura.RQL.DDL.CustomTypes
import Hasura.RQL.DDL.Endpoint
import Hasura.RQL.DDL.EventTrigger
import Hasura.RQL.DDL.Metadata
import Hasura.RQL.DDL.Permission
import Hasura.RQL.DDL.QueryCollection
import Hasura.RQL.DDL.Relationship
import Hasura.RQL.DDL.Relationship.Rename
import Hasura.RQL.DDL.RemoteRelationship
import Hasura.RQL.DDL.ScheduledTrigger
import Hasura.RQL.DDL.Schema
import Hasura.RQL.DDL.Schema.Cache.Config
import Hasura.RQL.DML.Count
import Hasura.RQL.DML.Delete
import Hasura.RQL.DML.Insert
import Hasura.RQL.DML.Select
import Hasura.RQL.DML.Types
import Hasura.RQL.DML.Update
import Hasura.RQL.Types.Allowlist
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.CustomTypes
import Hasura.RQL.Types.Endpoint
import Hasura.RQL.Types.Metadata
import Hasura.RQL.Types.Permission
import Hasura.RQL.Types.QueryCollection
import Hasura.RQL.Types.ScheduledTrigger
import Hasura.RQL.Types.SchemaCache
import Hasura.RQL.Types.SchemaCache.Build
import Hasura.RQL.Types.Source
import Hasura.RemoteSchema.MetadataAPI
import Hasura.Server.Types
import Hasura.Server.Utils
import Hasura.Services
import Hasura.Session
import Hasura.Tracing qualified as Tracing

data RQLQueryV1
  = RQAddExistingTableOrView !(TrackTable ('Postgres 'Vanilla))
  | RQTrackTable !(TrackTable ('Postgres 'Vanilla))
  | RQUntrackTable !(UntrackTable ('Postgres 'Vanilla))
  | RQSetTableIsEnum !(SetTableIsEnum ('Postgres 'Vanilla))
  | RQSetTableCustomization !(SetTableCustomization ('Postgres 'Vanilla))
  | RQTrackFunction !(Functions.TrackFunction ('Postgres 'Vanilla))
  | RQUntrackFunction !(Functions.UnTrackFunction ('Postgres 'Vanilla))
  | RQCreateObjectRelationship !(CreateObjRel ('Postgres 'Vanilla))
  | RQCreateArrayRelationship !(CreateArrRel ('Postgres 'Vanilla))
  | RQDropRelationship !(DropRel ('Postgres 'Vanilla))
  | RQSetRelationshipComment !(SetRelComment ('Postgres 'Vanilla))
  | RQRenameRelationship !(RenameRel ('Postgres 'Vanilla))
  | -- computed fields related
    RQAddComputedField !(AddComputedField ('Postgres 'Vanilla))
  | RQDropComputedField !(DropComputedField ('Postgres 'Vanilla))
  | RQCreateRemoteRelationship !(CreateFromSourceRelationship ('Postgres 'Vanilla))
  | RQUpdateRemoteRelationship !(CreateFromSourceRelationship ('Postgres 'Vanilla))
  | RQDeleteRemoteRelationship !(DeleteFromSourceRelationship ('Postgres 'Vanilla))
  | RQCreateInsertPermission !(CreatePerm InsPerm ('Postgres 'Vanilla))
  | RQCreateSelectPermission !(CreatePerm SelPerm ('Postgres 'Vanilla))
  | RQCreateUpdatePermission !(CreatePerm UpdPerm ('Postgres 'Vanilla))
  | RQCreateDeletePermission !(CreatePerm DelPerm ('Postgres 'Vanilla))
  | RQDropInsertPermission !(DropPerm ('Postgres 'Vanilla))
  | RQDropSelectPermission !(DropPerm ('Postgres 'Vanilla))
  | RQDropUpdatePermission !(DropPerm ('Postgres 'Vanilla))
  | RQDropDeletePermission !(DropPerm ('Postgres 'Vanilla))
  | RQSetPermissionComment !(SetPermComment ('Postgres 'Vanilla))
  | RQGetInconsistentMetadata !GetInconsistentMetadata
  | RQDropInconsistentMetadata !DropInconsistentMetadata
  | RQInsert !InsertQuery
  | RQSelect !SelectQuery
  | RQUpdate !UpdateQuery
  | RQDelete !DeleteQuery
  | RQCount !CountQuery
  | RQBulk ![RQLQuery]
  | -- schema-stitching, custom resolver related
    RQAddRemoteSchema !AddRemoteSchemaQuery
  | RQUpdateRemoteSchema !AddRemoteSchemaQuery
  | RQRemoveRemoteSchema !RemoteSchemaNameQuery
  | RQReloadRemoteSchema !RemoteSchemaNameQuery
  | RQIntrospectRemoteSchema !RemoteSchemaNameQuery
  | RQCreateEventTrigger !(CreateEventTriggerQuery ('Postgres 'Vanilla))
  | RQDeleteEventTrigger !(DeleteEventTriggerQuery ('Postgres 'Vanilla))
  | RQRedeliverEvent !(RedeliverEventQuery ('Postgres 'Vanilla))
  | RQInvokeEventTrigger !(InvokeEventTriggerQuery ('Postgres 'Vanilla))
  | -- scheduled triggers
    RQCreateCronTrigger !CreateCronTrigger
  | RQDeleteCronTrigger !ScheduledTriggerName
  | RQCreateScheduledEvent !CreateScheduledEvent
  | -- query collections, allow list related
    RQCreateQueryCollection !CreateCollection
  | RQRenameQueryCollection !RenameCollection
  | RQDropQueryCollection !DropCollection
  | RQAddQueryToCollection !AddQueryToCollection
  | RQDropQueryFromCollection !DropQueryFromCollection
  | RQAddCollectionToAllowlist !AllowlistEntry
  | RQDropCollectionFromAllowlist !DropCollectionFromAllowlist
  | RQRunSql !RunSQL
  | RQReplaceMetadata !ReplaceMetadata
  | RQExportMetadata !ExportMetadata
  | RQClearMetadata !ClearMetadata
  | RQReloadMetadata !ReloadMetadata
  | RQCreateAction !CreateAction
  | RQDropAction !DropAction
  | RQUpdateAction !UpdateAction
  | RQCreateActionPermission !CreateActionPermission
  | RQDropActionPermission !DropActionPermission
  | RQCreateRestEndpoint !CreateEndpoint
  | RQDropRestEndpoint !DropEndpoint
  | RQDumpInternalState !DumpInternalState
  | RQSetCustomTypes !CustomTypes
  deriving stock ((forall x. RQLQueryV1 -> Rep RQLQueryV1 x)
-> (forall x. Rep RQLQueryV1 x -> RQLQueryV1) -> Generic RQLQueryV1
forall x. Rep RQLQueryV1 x -> RQLQueryV1
forall x. RQLQueryV1 -> Rep RQLQueryV1 x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RQLQueryV1 -> Rep RQLQueryV1 x
from :: forall x. RQLQueryV1 -> Rep RQLQueryV1 x
$cto :: forall x. Rep RQLQueryV1 x -> RQLQueryV1
to :: forall x. Rep RQLQueryV1 x -> RQLQueryV1
Generic)

data RQLQueryV2
  = RQV2TrackTable !(TrackTableV2 ('Postgres 'Vanilla))
  | RQV2SetTableCustomFields !SetTableCustomFields -- deprecated
  | RQV2TrackFunction !(Functions.TrackFunctionV2 ('Postgres 'Vanilla))
  | RQV2ReplaceMetadata !ReplaceMetadataV2
  deriving stock ((forall x. RQLQueryV2 -> Rep RQLQueryV2 x)
-> (forall x. Rep RQLQueryV2 x -> RQLQueryV2) -> Generic RQLQueryV2
forall x. Rep RQLQueryV2 x -> RQLQueryV2
forall x. RQLQueryV2 -> Rep RQLQueryV2 x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. RQLQueryV2 -> Rep RQLQueryV2 x
from :: forall x. RQLQueryV2 -> Rep RQLQueryV2 x
$cto :: forall x. Rep RQLQueryV2 x -> RQLQueryV2
to :: forall x. Rep RQLQueryV2 x -> RQLQueryV2
Generic)

data RQLQuery
  = RQV1 !RQLQueryV1
  | RQV2 !RQLQueryV2

instance J.FromJSON RQLQuery where
  parseJSON :: Value -> Parser RQLQuery
parseJSON = String -> (Object -> Parser RQLQuery) -> Value -> Parser RQLQuery
forall a. String -> (Object -> Parser a) -> Value -> Parser a
J.withObject String
"Object" ((Object -> Parser RQLQuery) -> Value -> Parser RQLQuery)
-> (Object -> Parser RQLQuery) -> Value -> Parser RQLQuery
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    Maybe APIVersion
mVersion <- Object
o Object -> Key -> Parser (Maybe APIVersion)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
J..:? Key
"version"
    let version :: APIVersion
version = APIVersion -> Maybe APIVersion -> APIVersion
forall a. a -> Maybe a -> a
fromMaybe APIVersion
VIVersion1 Maybe APIVersion
mVersion
        val :: Value
val = Object -> Value
J.Object Object
o
    case APIVersion
version of
      APIVersion
VIVersion1 -> RQLQueryV1 -> RQLQuery
RQV1 (RQLQueryV1 -> RQLQuery) -> Parser RQLQueryV1 -> Parser RQLQuery
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser RQLQueryV1
forall a. FromJSON a => Value -> Parser a
J.parseJSON Value
val
      APIVersion
VIVersion2 -> RQLQueryV2 -> RQLQuery
RQV2 (RQLQueryV2 -> RQLQuery) -> Parser RQLQueryV2 -> Parser RQLQuery
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser RQLQueryV2
forall a. FromJSON a => Value -> Parser a
J.parseJSON Value
val

instance J.FromJSON RQLQueryV1 where
  parseJSON :: Value -> Parser RQLQueryV1
parseJSON =
    Options -> Value -> Parser RQLQueryV1
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
J.genericParseJSON
      Options
J.defaultOptions
        { constructorTagModifier :: String -> String
J.constructorTagModifier = String -> String
J.snakeCase (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
forall a. Int -> [a] -> [a]
drop Int
2,
          sumEncoding :: SumEncoding
J.sumEncoding = String -> String -> SumEncoding
J.TaggedObject String
"type" String
"args"
        }

instance J.FromJSON RQLQueryV2 where
  parseJSON :: Value -> Parser RQLQueryV2
parseJSON =
    Options -> Value -> Parser RQLQueryV2
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
J.genericParseJSON
      Options
J.defaultOptions
        { constructorTagModifier :: String -> String
J.constructorTagModifier = String -> String
J.snakeCase (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
forall a. Int -> [a] -> [a]
drop Int
4,
          sumEncoding :: SumEncoding
J.sumEncoding = String -> String -> SumEncoding
J.TaggedObject String
"type" String
"args",
          tagSingleConstructors :: Bool
J.tagSingleConstructors = Bool
True
        }

runQuery ::
  ( MonadIO m,
    MonadError QErr m,
    HasAppEnv m,
    HasCacheStaticConfig m,
    Tracing.MonadTrace m,
    MonadBaseControl IO m,
    MonadMetadataStorage m,
    MonadResolveSource m,
    MonadQueryTags m,
    MonadEventLogCleanup m,
    ProvidesHasuraServices m,
    MonadGetPolicies m,
    UserInfoM m
  ) =>
  AppContext ->
  RebuildableSchemaCache ->
  RQLQuery ->
  m (EncJSON, RebuildableSchemaCache)
runQuery :: forall (m :: * -> *).
(MonadIO m, MonadError QErr m, HasAppEnv m, HasCacheStaticConfig m,
 MonadTrace m, MonadBaseControl IO m, MonadMetadataStorage m,
 MonadResolveSource m, MonadQueryTags m, MonadEventLogCleanup m,
 ProvidesHasuraServices m, MonadGetPolicies m, UserInfoM m) =>
AppContext
-> RebuildableSchemaCache
-> RQLQuery
-> m (EncJSON, RebuildableSchemaCache)
runQuery AppContext
appContext RebuildableSchemaCache
sc RQLQuery
query = do
  AppEnv {Int
Maybe Text
Maybe PGPool
Maybe (CredentialCache AgentLicenseKey)
SamplingPolicy
HostPreference
Manager
TxIsolation
ConnParams
PGPool
Refined NonNegative Seconds
TMVar MetadataResourceVersion
ConnectionOptions
CheckFeatureFlag
ServerMetrics
EventingMode
ReadOnlyMode
MaintenanceMode ()
InstanceId
PrometheusMetrics
ShutdownLatch
LoggingSettings
LockedEventsCtx
WSConnectionInitTimeout
KeepAliveDelay
OptionalInterval
Port
SubscriptionsState
Loggers
appEnvPort :: Port
appEnvHost :: HostPreference
appEnvMetadataDbPool :: PGPool
appEnvIntrospectionDbPool :: Maybe PGPool
appEnvManager :: Manager
appEnvLoggers :: Loggers
appEnvMetadataVersionRef :: TMVar MetadataResourceVersion
appEnvInstanceId :: InstanceId
appEnvEnableMaintenanceMode :: MaintenanceMode ()
appEnvLoggingSettings :: LoggingSettings
appEnvEventingMode :: EventingMode
appEnvEnableReadOnlyMode :: ReadOnlyMode
appEnvServerMetrics :: ServerMetrics
appEnvShutdownLatch :: ShutdownLatch
appEnvMetaVersionRef :: TMVar MetadataResourceVersion
appEnvPrometheusMetrics :: PrometheusMetrics
appEnvTraceSamplingPolicy :: SamplingPolicy
appEnvSubscriptionState :: SubscriptionsState
appEnvLockedEventsCtx :: LockedEventsCtx
appEnvConnParams :: ConnParams
appEnvTxIso :: TxIsolation
appEnvConsoleAssetsDir :: Maybe Text
appEnvConsoleSentryDsn :: Maybe Text
appEnvConnectionOptions :: ConnectionOptions
appEnvWebSocketKeepAlive :: KeepAliveDelay
appEnvWebSocketConnectionInitTimeout :: WSConnectionInitTimeout
appEnvGracefulShutdownTimeout :: Refined NonNegative Seconds
appEnvSchemaPollInterval :: OptionalInterval
appEnvCheckFeatureFlag :: CheckFeatureFlag
appEnvLicenseKeyCache :: Maybe (CredentialCache AgentLicenseKey)
appEnvMaxTotalHeaderLength :: Int
appEnvPort :: AppEnv -> Port
appEnvHost :: AppEnv -> HostPreference
appEnvMetadataDbPool :: AppEnv -> PGPool
appEnvIntrospectionDbPool :: AppEnv -> Maybe PGPool
appEnvManager :: AppEnv -> Manager
appEnvLoggers :: AppEnv -> Loggers
appEnvMetadataVersionRef :: AppEnv -> TMVar MetadataResourceVersion
appEnvInstanceId :: AppEnv -> InstanceId
appEnvEnableMaintenanceMode :: AppEnv -> MaintenanceMode ()
appEnvLoggingSettings :: AppEnv -> LoggingSettings
appEnvEventingMode :: AppEnv -> EventingMode
appEnvEnableReadOnlyMode :: AppEnv -> ReadOnlyMode
appEnvServerMetrics :: AppEnv -> ServerMetrics
appEnvShutdownLatch :: AppEnv -> ShutdownLatch
appEnvMetaVersionRef :: AppEnv -> TMVar MetadataResourceVersion
appEnvPrometheusMetrics :: AppEnv -> PrometheusMetrics
appEnvTraceSamplingPolicy :: AppEnv -> SamplingPolicy
appEnvSubscriptionState :: AppEnv -> SubscriptionsState
appEnvLockedEventsCtx :: AppEnv -> LockedEventsCtx
appEnvConnParams :: AppEnv -> ConnParams
appEnvTxIso :: AppEnv -> TxIsolation
appEnvConsoleAssetsDir :: AppEnv -> Maybe Text
appEnvConsoleSentryDsn :: AppEnv -> Maybe Text
appEnvConnectionOptions :: AppEnv -> ConnectionOptions
appEnvWebSocketKeepAlive :: AppEnv -> KeepAliveDelay
appEnvWebSocketConnectionInitTimeout :: AppEnv -> WSConnectionInitTimeout
appEnvGracefulShutdownTimeout :: AppEnv -> Refined NonNegative Seconds
appEnvSchemaPollInterval :: AppEnv -> OptionalInterval
appEnvCheckFeatureFlag :: AppEnv -> CheckFeatureFlag
appEnvLicenseKeyCache :: AppEnv -> Maybe (CredentialCache AgentLicenseKey)
appEnvMaxTotalHeaderLength :: AppEnv -> Int
..} <- m AppEnv
forall (m :: * -> *). HasAppEnv m => m AppEnv
askAppEnv
  let logger :: Logger Hasura
logger = Loggers -> Logger Hasura
_lsLogger Loggers
appEnvLoggers
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ((ReadOnlyMode
appEnvEnableReadOnlyMode ReadOnlyMode -> ReadOnlyMode -> Bool
forall a. Eq a => a -> a -> Bool
== ReadOnlyMode
ReadOnlyModeEnabled) Bool -> Bool -> Bool
&& RQLQuery -> Bool
queryModifiesUserDB RQLQuery
query)
    (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ Code -> Text -> m ()
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"Cannot run write queries when read-only mode is enabled"

  let exportsMetadata :: RQLQuery -> Bool
exportsMetadata = \case
        RQV1 (RQExportMetadata ExportMetadata
_) -> Bool
True
        RQLQuery
_ -> Bool
False
      metadataDefaults :: MetadataDefaults
metadataDefaults =
        if (RQLQuery -> Bool
exportsMetadata RQLQuery
query)
          then MetadataDefaults
emptyMetadataDefaults
          else AppContext -> MetadataDefaults
acMetadataDefaults AppContext
appContext
  let dynamicConfig :: CacheDynamicConfig
dynamicConfig = AppContext -> CacheDynamicConfig
buildCacheDynamicConfig AppContext
appContext

  MetadataWithResourceVersion Metadata
metadata MetadataResourceVersion
currentResourceVersion <- m (Either QErr MetadataWithResourceVersion)
-> m MetadataWithResourceVersion
forall e (m :: * -> *) a. MonadError e m => m (Either e a) -> m a
liftEitherM m (Either QErr MetadataWithResourceVersion)
forall (m :: * -> *).
MonadMetadataStorage m =>
m (Either QErr MetadataWithResourceVersion)
fetchMetadata
  ((EncJSON
result, Metadata
updatedMetadata), RebuildableSchemaCache
modSchemaCache, CacheInvalidations
invalidations, SourcesIntrospectionStatus
sourcesIntrospection, SchemaRegistryAction
schemaRegistryAction) <-
    Environment
-> SQLGenCtx
-> RQLQuery
-> ReaderT (Logger Hasura) (MetadataT (CacheRWT m)) EncJSON
forall (m :: * -> *) r.
(CacheRWM m, UserInfoM m, MonadBaseControl IO m, MonadIO m,
 MonadTrace m, MetadataM m, MonadMetadataStorage m,
 MonadQueryTags m, MonadReader r m, MonadError QErr m,
 Has (Logger Hasura) r, MonadEventLogCleanup m,
 ProvidesHasuraServices m, MonadGetPolicies m) =>
Environment -> SQLGenCtx -> RQLQuery -> m EncJSON
runQueryM (AppContext -> Environment
acEnvironment AppContext
appContext) (AppContext -> SQLGenCtx
acSQLGenCtx AppContext
appContext) RQLQuery
query
      -- TODO: remove this straight runReaderT that provides no actual new info
      ReaderT (Logger Hasura) (MetadataT (CacheRWT m)) EncJSON
-> (ReaderT (Logger Hasura) (MetadataT (CacheRWT m)) EncJSON
    -> MetadataT (CacheRWT m) EncJSON)
-> MetadataT (CacheRWT m) EncJSON
forall a b. a -> (a -> b) -> b
& (ReaderT (Logger Hasura) (MetadataT (CacheRWT m)) EncJSON
 -> Logger Hasura -> MetadataT (CacheRWT m) EncJSON)
-> Logger Hasura
-> ReaderT (Logger Hasura) (MetadataT (CacheRWT m)) EncJSON
-> MetadataT (CacheRWT m) EncJSON
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT (Logger Hasura) (MetadataT (CacheRWT m)) EncJSON
-> Logger Hasura -> MetadataT (CacheRWT m) EncJSON
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Logger Hasura
logger
      MetadataT (CacheRWT m) EncJSON
-> (MetadataT (CacheRWT m) EncJSON
    -> CacheRWT m (EncJSON, Metadata))
-> CacheRWT m (EncJSON, Metadata)
forall a b. a -> (a -> b) -> b
& Metadata
-> MetadataDefaults
-> MetadataT (CacheRWT m) EncJSON
-> CacheRWT m (EncJSON, Metadata)
forall (m :: * -> *) a.
Metadata -> MetadataDefaults -> MetadataT m a -> m (a, Metadata)
runMetadataT Metadata
metadata MetadataDefaults
metadataDefaults
      CacheRWT m (EncJSON, Metadata)
-> (CacheRWT m (EncJSON, Metadata)
    -> m ((EncJSON, Metadata), RebuildableSchemaCache,
          CacheInvalidations, SourcesIntrospectionStatus,
          SchemaRegistryAction))
-> m ((EncJSON, Metadata), RebuildableSchemaCache,
      CacheInvalidations, SourcesIntrospectionStatus,
      SchemaRegistryAction)
forall a b. a -> (a -> b) -> b
& CacheDynamicConfig
-> RebuildableSchemaCache
-> CacheRWT m (EncJSON, Metadata)
-> m ((EncJSON, Metadata), RebuildableSchemaCache,
      CacheInvalidations, SourcesIntrospectionStatus,
      SchemaRegistryAction)
forall (m :: * -> *) a.
Monad m =>
CacheDynamicConfig
-> RebuildableSchemaCache
-> CacheRWT m a
-> m (a, RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
runCacheRWT CacheDynamicConfig
dynamicConfig RebuildableSchemaCache
sc
  if RQLQuery -> Bool
queryModifiesSchemaCache RQLQuery
query
    then case MaintenanceMode ()
appEnvEnableMaintenanceMode of
      MaintenanceMode ()
MaintenanceModeDisabled -> do
        -- set modified metadata in storage
        MetadataResourceVersion
newResourceVersion <- m (Either QErr MetadataResourceVersion)
-> m MetadataResourceVersion
forall e (m :: * -> *) a. MonadError e m => m (Either e a) -> m a
liftEitherM (m (Either QErr MetadataResourceVersion)
 -> m MetadataResourceVersion)
-> m (Either QErr MetadataResourceVersion)
-> m MetadataResourceVersion
forall a b. (a -> b) -> a -> b
$ MetadataResourceVersion
-> Metadata -> m (Either QErr MetadataResourceVersion)
forall (m :: * -> *).
MonadMetadataStorage m =>
MetadataResourceVersion
-> Metadata -> m (Either QErr MetadataResourceVersion)
setMetadata MetadataResourceVersion
currentResourceVersion Metadata
updatedMetadata

        (()
_, RebuildableSchemaCache
modSchemaCache', CacheInvalidations
_, SourcesIntrospectionStatus
_, SchemaRegistryAction
_) <-
          Text
-> m ((), RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
-> m ((), RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
forall (m :: * -> *) a.
(MonadIO m, MonadTrace m) =>
Text -> m a -> m a
Tracing.newSpan Text
"setMetadataResourceVersionInSchemaCache"
            (m ((), RebuildableSchemaCache, CacheInvalidations,
    SourcesIntrospectionStatus, SchemaRegistryAction)
 -> m ((), RebuildableSchemaCache, CacheInvalidations,
       SourcesIntrospectionStatus, SchemaRegistryAction))
-> m ((), RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
-> m ((), RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
forall a b. (a -> b) -> a -> b
$ MetadataResourceVersion -> CacheRWT m ()
forall (m :: * -> *). CacheRWM m => MetadataResourceVersion -> m ()
setMetadataResourceVersionInSchemaCache MetadataResourceVersion
newResourceVersion
            CacheRWT m ()
-> (CacheRWT m ()
    -> m ((), RebuildableSchemaCache, CacheInvalidations,
          SourcesIntrospectionStatus, SchemaRegistryAction))
-> m ((), RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
forall a b. a -> (a -> b) -> b
& CacheDynamicConfig
-> RebuildableSchemaCache
-> CacheRWT m ()
-> m ((), RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
forall (m :: * -> *) a.
Monad m =>
CacheDynamicConfig
-> RebuildableSchemaCache
-> CacheRWT m a
-> m (a, RebuildableSchemaCache, CacheInvalidations,
      SourcesIntrospectionStatus, SchemaRegistryAction)
runCacheRWT CacheDynamicConfig
dynamicConfig RebuildableSchemaCache
modSchemaCache

        -- save sources introspection to stored-introspection DB
        Logger Hasura
-> SourcesIntrospectionStatus -> MetadataResourceVersion -> m ()
forall (m :: * -> *).
(MonadIO m, MonadMetadataStorage m) =>
Logger Hasura
-> SourcesIntrospectionStatus -> MetadataResourceVersion -> m ()
saveSourcesIntrospection Logger Hasura
logger SourcesIntrospectionStatus
sourcesIntrospection MetadataResourceVersion
newResourceVersion
        -- run schema registry action
        SchemaRegistryAction
-> ((MetadataResourceVersion
     -> [InconsistentMetadata] -> Metadata -> IO ())
    -> m ())
-> m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ SchemaRegistryAction
schemaRegistryAction (((MetadataResourceVersion
   -> [InconsistentMetadata] -> Metadata -> IO ())
  -> m ())
 -> m ())
-> ((MetadataResourceVersion
     -> [InconsistentMetadata] -> Metadata -> IO ())
    -> m ())
-> m ()
forall a b. (a -> b) -> a -> b
$ \MetadataResourceVersion
-> [InconsistentMetadata] -> Metadata -> IO ()
action -> do
          IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ MetadataResourceVersion
-> [InconsistentMetadata] -> Metadata -> IO ()
action MetadataResourceVersion
newResourceVersion (SchemaCache -> [InconsistentMetadata]
scInconsistentObjs (RebuildableSchemaCache -> SchemaCache
lastBuiltSchemaCache RebuildableSchemaCache
modSchemaCache')) Metadata
updatedMetadata
        -- notify schema cache sync
        m (Either QErr ()) -> m ()
forall e (m :: * -> *) a. MonadError e m => m (Either e a) -> m a
liftEitherM (m (Either QErr ()) -> m ()) -> m (Either QErr ()) -> m ()
forall a b. (a -> b) -> a -> b
$ MetadataResourceVersion
-> InstanceId -> CacheInvalidations -> m (Either QErr ())
forall (m :: * -> *).
MonadMetadataStorage m =>
MetadataResourceVersion
-> InstanceId -> CacheInvalidations -> m (Either QErr ())
notifySchemaCacheSync MetadataResourceVersion
newResourceVersion InstanceId
appEnvInstanceId CacheInvalidations
invalidations

        (EncJSON, RebuildableSchemaCache)
-> m (EncJSON, RebuildableSchemaCache)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EncJSON
result, RebuildableSchemaCache
modSchemaCache')
      MaintenanceModeEnabled () ->
        Text -> m (EncJSON, RebuildableSchemaCache)
forall (m :: * -> *) a. QErrM m => Text -> m a
throw500 Text
"metadata cannot be modified in maintenance mode"
    else (EncJSON, RebuildableSchemaCache)
-> m (EncJSON, RebuildableSchemaCache)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EncJSON
result, RebuildableSchemaCache
modSchemaCache)

-- | A predicate that determines whether the given query might modify/rebuild the schema cache. If
-- so, it needs to acquire the global lock on the schema cache so that other queries do not modify
-- it concurrently.
--
-- Ideally, we would enforce this using the type system — queries for which this function returns
-- 'False' should not be allowed to modify the schema cache. But for now we just ensure consistency
-- by hand.
queryModifiesSchemaCache :: RQLQuery -> Bool
queryModifiesSchemaCache :: RQLQuery -> Bool
queryModifiesSchemaCache (RQV1 RQLQueryV1
qi) = case RQLQueryV1
qi of
  RQAddExistingTableOrView TrackTable ('Postgres 'Vanilla)
_ -> Bool
True
  RQTrackTable TrackTable ('Postgres 'Vanilla)
_ -> Bool
True
  RQUntrackTable UntrackTable ('Postgres 'Vanilla)
_ -> Bool
True
  RQTrackFunction TrackFunction ('Postgres 'Vanilla)
_ -> Bool
True
  RQUntrackFunction UnTrackFunction ('Postgres 'Vanilla)
_ -> Bool
True
  RQSetTableIsEnum SetTableIsEnum ('Postgres 'Vanilla)
_ -> Bool
True
  RQCreateObjectRelationship CreateObjRel ('Postgres 'Vanilla)
_ -> Bool
True
  RQCreateArrayRelationship CreateArrRel ('Postgres 'Vanilla)
_ -> Bool
True
  RQDropRelationship DropRel ('Postgres 'Vanilla)
_ -> Bool
True
  RQSetRelationshipComment SetRelComment ('Postgres 'Vanilla)
_ -> Bool
False
  RQRenameRelationship RenameRel ('Postgres 'Vanilla)
_ -> Bool
True
  RQAddComputedField AddComputedField ('Postgres 'Vanilla)
_ -> Bool
True
  RQDropComputedField DropComputedField ('Postgres 'Vanilla)
_ -> Bool
True
  RQCreateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
True
  RQUpdateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
True
  RQDeleteRemoteRelationship DeleteFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
True
  RQCreateInsertPermission CreatePerm InsPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQCreateSelectPermission CreatePerm SelPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQCreateUpdatePermission CreatePerm UpdPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQCreateDeletePermission CreatePerm DelPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQDropInsertPermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQDropSelectPermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQDropUpdatePermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQDropDeletePermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
  RQSetPermissionComment SetPermComment ('Postgres 'Vanilla)
_ -> Bool
False
  RQGetInconsistentMetadata GetInconsistentMetadata
_ -> Bool
False
  RQDropInconsistentMetadata DropInconsistentMetadata
_ -> Bool
True
  RQInsert InsertQuery
_ -> Bool
False
  RQSelect SelectQuery
_ -> Bool
False
  RQUpdate UpdateQuery
_ -> Bool
False
  RQDelete DeleteQuery
_ -> Bool
False
  RQCount CountQuery
_ -> Bool
False
  RQAddRemoteSchema AddRemoteSchemaQuery
_ -> Bool
True
  RQUpdateRemoteSchema AddRemoteSchemaQuery
_ -> Bool
True
  RQRemoveRemoteSchema RemoteSchemaNameQuery
_ -> Bool
True
  RQReloadRemoteSchema RemoteSchemaNameQuery
_ -> Bool
True
  RQIntrospectRemoteSchema RemoteSchemaNameQuery
_ -> Bool
False
  RQCreateEventTrigger CreateEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
True
  RQDeleteEventTrigger DeleteEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
True
  RQRedeliverEvent RedeliverEventQuery ('Postgres 'Vanilla)
_ -> Bool
False
  RQInvokeEventTrigger InvokeEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateCronTrigger CreateCronTrigger
_ -> Bool
True
  RQDeleteCronTrigger ScheduledTriggerName
_ -> Bool
True
  RQCreateScheduledEvent CreateScheduledEvent
_ -> Bool
False
  RQCreateQueryCollection CreateCollection
_ -> Bool
True
  RQRenameQueryCollection RenameCollection
_ -> Bool
True
  RQDropQueryCollection DropCollection
_ -> Bool
True
  RQAddQueryToCollection AddQueryToCollection
_ -> Bool
True
  RQDropQueryFromCollection DropQueryFromCollection
_ -> Bool
True
  RQAddCollectionToAllowlist AllowlistEntry
_ -> Bool
True
  RQDropCollectionFromAllowlist DropCollectionFromAllowlist
_ -> Bool
True
  RQRunSql RunSQL
q -> RunSQL -> Bool
isSchemaCacheBuildRequiredRunSQL RunSQL
q
  RQReplaceMetadata ReplaceMetadata
_ -> Bool
True
  RQExportMetadata ExportMetadata
_ -> Bool
False
  RQClearMetadata ClearMetadata
_ -> Bool
True
  RQReloadMetadata ReloadMetadata
_ -> Bool
True
  RQCreateRestEndpoint CreateEndpoint
_ -> Bool
True
  RQDropRestEndpoint DropEndpoint
_ -> Bool
True
  RQCreateAction CreateAction
_ -> Bool
True
  RQDropAction DropAction
_ -> Bool
True
  RQUpdateAction UpdateAction
_ -> Bool
True
  RQCreateActionPermission CreateActionPermission
_ -> Bool
True
  RQDropActionPermission DropActionPermission
_ -> Bool
True
  RQDumpInternalState DumpInternalState
_ -> Bool
False
  RQSetCustomTypes CustomTypes
_ -> Bool
True
  RQSetTableCustomization SetTableCustomization ('Postgres 'Vanilla)
_ -> Bool
True
  RQBulk [RQLQuery]
qs -> (RQLQuery -> Bool) -> [RQLQuery] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any RQLQuery -> Bool
queryModifiesSchemaCache [RQLQuery]
qs
queryModifiesSchemaCache (RQV2 RQLQueryV2
qi) = case RQLQueryV2
qi of
  RQV2TrackTable TrackTableV2 ('Postgres 'Vanilla)
_ -> Bool
True
  RQV2SetTableCustomFields SetTableCustomFields
_ -> Bool
True
  RQV2TrackFunction TrackFunctionV2 ('Postgres 'Vanilla)
_ -> Bool
True
  RQV2ReplaceMetadata ReplaceMetadataV2
_ -> Bool
True

-- | A predicate that determines whether the given query might modify user's Database. If
-- so, when the server is run in safe mode, we should not proceed with those operations.
queryModifiesUserDB :: RQLQuery -> Bool
queryModifiesUserDB :: RQLQuery -> Bool
queryModifiesUserDB (RQV1 RQLQueryV1
qi) = case RQLQueryV1
qi of
  RQAddExistingTableOrView TrackTable ('Postgres 'Vanilla)
_ -> Bool
False
  RQTrackTable TrackTable ('Postgres 'Vanilla)
_ -> Bool
False
  RQUntrackTable UntrackTable ('Postgres 'Vanilla)
_ -> Bool
False
  RQTrackFunction TrackFunction ('Postgres 'Vanilla)
_ -> Bool
False
  RQUntrackFunction UnTrackFunction ('Postgres 'Vanilla)
_ -> Bool
False
  RQSetTableIsEnum SetTableIsEnum ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateObjectRelationship CreateObjRel ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateArrayRelationship CreateArrRel ('Postgres 'Vanilla)
_ -> Bool
False
  RQDropRelationship DropRel ('Postgres 'Vanilla)
_ -> Bool
False
  RQSetRelationshipComment SetRelComment ('Postgres 'Vanilla)
_ -> Bool
False
  RQRenameRelationship RenameRel ('Postgres 'Vanilla)
_ -> Bool
False
  RQAddComputedField AddComputedField ('Postgres 'Vanilla)
_ -> Bool
False
  RQDropComputedField DropComputedField ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
False
  RQUpdateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
False
  RQDeleteRemoteRelationship DeleteFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateInsertPermission CreatePerm InsPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateSelectPermission CreatePerm SelPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateUpdatePermission CreatePerm UpdPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateDeletePermission CreatePerm DelPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQDropInsertPermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQDropSelectPermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQDropUpdatePermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQDropDeletePermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
False
  RQSetPermissionComment SetPermComment ('Postgres 'Vanilla)
_ -> Bool
False
  RQGetInconsistentMetadata GetInconsistentMetadata
_ -> Bool
False
  RQDropInconsistentMetadata DropInconsistentMetadata
_ -> Bool
False
  RQInsert InsertQuery
_ -> Bool
True
  RQSelect SelectQuery
_ -> Bool
False
  RQUpdate UpdateQuery
_ -> Bool
True
  RQDelete DeleteQuery
_ -> Bool
True
  RQCount CountQuery
_ -> Bool
False
  RQAddRemoteSchema AddRemoteSchemaQuery
_ -> Bool
False
  RQUpdateRemoteSchema AddRemoteSchemaQuery
_ -> Bool
False
  RQRemoveRemoteSchema RemoteSchemaNameQuery
_ -> Bool
False
  RQReloadRemoteSchema RemoteSchemaNameQuery
_ -> Bool
False
  RQIntrospectRemoteSchema RemoteSchemaNameQuery
_ -> Bool
False
  RQCreateEventTrigger CreateEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
True
  RQDeleteEventTrigger DeleteEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
True
  RQRedeliverEvent RedeliverEventQuery ('Postgres 'Vanilla)
_ -> Bool
False
  RQInvokeEventTrigger InvokeEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
False
  RQCreateCronTrigger CreateCronTrigger
_ -> Bool
False
  RQDeleteCronTrigger ScheduledTriggerName
_ -> Bool
False
  RQCreateScheduledEvent CreateScheduledEvent
_ -> Bool
False
  RQCreateQueryCollection CreateCollection
_ -> Bool
False
  RQRenameQueryCollection RenameCollection
_ -> Bool
False
  RQDropQueryCollection DropCollection
_ -> Bool
False
  RQAddQueryToCollection AddQueryToCollection
_ -> Bool
False
  RQDropQueryFromCollection DropQueryFromCollection
_ -> Bool
False
  RQAddCollectionToAllowlist AllowlistEntry
_ -> Bool
False
  RQDropCollectionFromAllowlist DropCollectionFromAllowlist
_ -> Bool
False
  RQRunSql RunSQL
_ -> Bool
True
  RQReplaceMetadata ReplaceMetadata
_ -> Bool
True
  RQExportMetadata ExportMetadata
_ -> Bool
False
  RQClearMetadata ClearMetadata
_ -> Bool
False
  RQReloadMetadata ReloadMetadata
_ -> Bool
False
  RQCreateRestEndpoint CreateEndpoint
_ -> Bool
False
  RQDropRestEndpoint DropEndpoint
_ -> Bool
False
  RQCreateAction CreateAction
_ -> Bool
False
  RQDropAction DropAction
_ -> Bool
False
  RQUpdateAction UpdateAction
_ -> Bool
False
  RQCreateActionPermission CreateActionPermission
_ -> Bool
False
  RQDropActionPermission DropActionPermission
_ -> Bool
False
  RQDumpInternalState DumpInternalState
_ -> Bool
False
  RQSetCustomTypes CustomTypes
_ -> Bool
False
  RQSetTableCustomization SetTableCustomization ('Postgres 'Vanilla)
_ -> Bool
False
  RQBulk [RQLQuery]
qs -> (RQLQuery -> Bool) -> [RQLQuery] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any RQLQuery -> Bool
queryModifiesUserDB [RQLQuery]
qs
queryModifiesUserDB (RQV2 RQLQueryV2
qi) = case RQLQueryV2
qi of
  RQV2TrackTable TrackTableV2 ('Postgres 'Vanilla)
_ -> Bool
False
  RQV2SetTableCustomFields SetTableCustomFields
_ -> Bool
False
  RQV2TrackFunction TrackFunctionV2 ('Postgres 'Vanilla)
_ -> Bool
False
  RQV2ReplaceMetadata ReplaceMetadataV2
_ -> Bool
True

runQueryM ::
  ( CacheRWM m,
    UserInfoM m,
    MonadBaseControl IO m,
    MonadIO m,
    Tracing.MonadTrace m,
    MetadataM m,
    MonadMetadataStorage m,
    MonadQueryTags m,
    MonadReader r m,
    MonadError QErr m,
    Has (L.Logger L.Hasura) r,
    MonadEventLogCleanup m,
    ProvidesHasuraServices m,
    MonadGetPolicies m
  ) =>
  Env.Environment ->
  SQLGenCtx ->
  RQLQuery ->
  m EncJSON
runQueryM :: forall (m :: * -> *) r.
(CacheRWM m, UserInfoM m, MonadBaseControl IO m, MonadIO m,
 MonadTrace m, MetadataM m, MonadMetadataStorage m,
 MonadQueryTags m, MonadReader r m, MonadError QErr m,
 Has (Logger Hasura) r, MonadEventLogCleanup m,
 ProvidesHasuraServices m, MonadGetPolicies m) =>
Environment -> SQLGenCtx -> RQLQuery -> m EncJSON
runQueryM Environment
env SQLGenCtx
sqlGen RQLQuery
rq = Text -> m EncJSON -> m EncJSON
forall (m :: * -> *) a. QErrM m => Text -> m a -> m a
withPathK Text
"args" (m EncJSON -> m EncJSON) -> m EncJSON -> m EncJSON
forall a b. (a -> b) -> a -> b
$ case RQLQuery
rq of
  RQV1 RQLQueryV1
q -> RQLQueryV1 -> m EncJSON
runQueryV1M RQLQueryV1
q
  RQV2 RQLQueryV2
q -> RQLQueryV2 -> m EncJSON
runQueryV2M RQLQueryV2
q
  where
    runQueryV1M :: RQLQueryV1 -> m EncJSON
runQueryV1M = \case
      RQAddExistingTableOrView TrackTable ('Postgres 'Vanilla)
q -> TrackTable ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
TrackTable b -> m EncJSON
runTrackTableQ TrackTable ('Postgres 'Vanilla)
q
      RQTrackTable TrackTable ('Postgres 'Vanilla)
q -> TrackTable ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
TrackTable b -> m EncJSON
runTrackTableQ TrackTable ('Postgres 'Vanilla)
q
      RQUntrackTable UntrackTable ('Postgres 'Vanilla)
q -> UntrackTable ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(CacheRWM m, QErrM m, MetadataM m, BackendMetadata b,
 BackendEventTrigger b, MonadIO m) =>
UntrackTable b -> m EncJSON
runUntrackTableQ UntrackTable ('Postgres 'Vanilla)
q
      RQSetTableIsEnum SetTableIsEnum ('Postgres 'Vanilla)
q -> SetTableIsEnum ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
SetTableIsEnum b -> m EncJSON
runSetExistingTableIsEnumQ SetTableIsEnum ('Postgres 'Vanilla)
q
      RQSetTableCustomization SetTableCustomization ('Postgres 'Vanilla)
q -> SetTableCustomization ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m, Backend b) =>
SetTableCustomization b -> m EncJSON
runSetTableCustomization SetTableCustomization ('Postgres 'Vanilla)
q
      RQTrackFunction TrackFunction ('Postgres 'Vanilla)
q -> TrackFunction ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
TrackFunction b -> m EncJSON
Functions.runTrackFunc TrackFunction ('Postgres 'Vanilla)
q
      RQUntrackFunction UnTrackFunction ('Postgres 'Vanilla)
q -> UnTrackFunction ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(CacheRWM m, MonadError QErr m, MetadataM m, BackendMetadata b) =>
UnTrackFunction b -> m EncJSON
Functions.runUntrackFunc UnTrackFunction ('Postgres 'Vanilla)
q
      RQCreateObjectRelationship CreateObjRel ('Postgres 'Vanilla)
q -> RelType
-> WithTable
     ('Postgres 'Vanilla) (RelDef (ObjRelUsing ('Postgres 'Vanilla)))
-> m EncJSON
forall (m :: * -> *) (b :: BackendType) a.
(MonadError QErr m, CacheRWM m, ToJSON a, MetadataM m,
 BackendMetadata b) =>
RelType -> WithTable b (RelDef a) -> m EncJSON
runCreateRelationship RelType
ObjRel (WithTable
   ('Postgres 'Vanilla) (RelDef (ObjRelUsing ('Postgres 'Vanilla)))
 -> m EncJSON)
-> WithTable
     ('Postgres 'Vanilla) (RelDef (ObjRelUsing ('Postgres 'Vanilla)))
-> m EncJSON
forall a b. (a -> b) -> a -> b
$ CreateObjRel ('Postgres 'Vanilla)
-> WithTable
     ('Postgres 'Vanilla) (RelDef (ObjRelUsing ('Postgres 'Vanilla)))
forall (b :: BackendType).
CreateObjRel b -> WithTable b (ObjRelDef b)
unCreateObjRel CreateObjRel ('Postgres 'Vanilla)
q
      RQCreateArrayRelationship CreateArrRel ('Postgres 'Vanilla)
q -> RelType
-> WithTable
     ('Postgres 'Vanilla) (RelDef (ArrRelUsing ('Postgres 'Vanilla)))
-> m EncJSON
forall (m :: * -> *) (b :: BackendType) a.
(MonadError QErr m, CacheRWM m, ToJSON a, MetadataM m,
 BackendMetadata b) =>
RelType -> WithTable b (RelDef a) -> m EncJSON
runCreateRelationship RelType
ArrRel (WithTable
   ('Postgres 'Vanilla) (RelDef (ArrRelUsing ('Postgres 'Vanilla)))
 -> m EncJSON)
-> WithTable
     ('Postgres 'Vanilla) (RelDef (ArrRelUsing ('Postgres 'Vanilla)))
-> m EncJSON
forall a b. (a -> b) -> a -> b
$ CreateArrRel ('Postgres 'Vanilla)
-> WithTable
     ('Postgres 'Vanilla) (RelDef (ArrRelUsing ('Postgres 'Vanilla)))
forall (b :: BackendType).
CreateArrRel b -> WithTable b (ArrRelDef b)
unCreateArrRel CreateArrRel ('Postgres 'Vanilla)
q
      RQDropRelationship DropRel ('Postgres 'Vanilla)
q -> DropRel ('Postgres 'Vanilla) -> m EncJSON
forall (m :: * -> *) (b :: BackendType).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
DropRel b -> m EncJSON
runDropRel DropRel ('Postgres 'Vanilla)
q
      RQSetRelationshipComment SetRelComment ('Postgres 'Vanilla)
q -> SetRelComment ('Postgres 'Vanilla) -> m EncJSON
forall (m :: * -> *) (b :: BackendType).
(CacheRWM m, MonadError QErr m, MetadataM m, BackendMetadata b) =>
SetRelComment b -> m EncJSON
runSetRelComment SetRelComment ('Postgres 'Vanilla)
q
      RQRenameRelationship RenameRel ('Postgres 'Vanilla)
q -> RenameRel ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
RenameRel b -> m EncJSON
runRenameRel RenameRel ('Postgres 'Vanilla)
q
      RQAddComputedField AddComputedField ('Postgres 'Vanilla)
q -> AddComputedField ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(BackendMetadata b, MonadError QErr m, CacheRWM m, MetadataM m) =>
AddComputedField b -> m EncJSON
runAddComputedField AddComputedField ('Postgres 'Vanilla)
q
      RQDropComputedField DropComputedField ('Postgres 'Vanilla)
q -> DropComputedField ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m, BackendMetadata b) =>
DropComputedField b -> m EncJSON
runDropComputedField DropComputedField ('Postgres 'Vanilla)
q
      RQCreateInsertPermission CreatePerm InsPerm ('Postgres 'Vanilla)
q -> CreatePerm InsPerm ('Postgres 'Vanilla) -> m EncJSON
forall (m :: * -> *) (b :: BackendType) (a :: BackendType -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
CreatePerm a b -> m EncJSON
runCreatePerm CreatePerm InsPerm ('Postgres 'Vanilla)
q
      RQCreateSelectPermission CreatePerm SelPerm ('Postgres 'Vanilla)
q -> CreatePerm SelPerm ('Postgres 'Vanilla) -> m EncJSON
forall (m :: * -> *) (b :: BackendType) (a :: BackendType -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
CreatePerm a b -> m EncJSON
runCreatePerm CreatePerm SelPerm ('Postgres 'Vanilla)
q
      RQCreateUpdatePermission CreatePerm UpdPerm ('Postgres 'Vanilla)
q -> CreatePerm UpdPerm ('Postgres 'Vanilla) -> m EncJSON
forall (m :: * -> *) (b :: BackendType) (a :: BackendType -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
CreatePerm a b -> m EncJSON
runCreatePerm CreatePerm UpdPerm ('Postgres 'Vanilla)
q
      RQCreateDeletePermission CreatePerm DelPerm ('Postgres 'Vanilla)
q -> CreatePerm DelPerm ('Postgres 'Vanilla) -> m EncJSON
forall (m :: * -> *) (b :: BackendType) (a :: BackendType -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
CreatePerm a b -> m EncJSON
runCreatePerm CreatePerm DelPerm ('Postgres 'Vanilla)
q
      RQDropInsertPermission DropPerm ('Postgres 'Vanilla)
q -> PermType -> DropPerm ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
PermType -> DropPerm b -> m EncJSON
runDropPerm PermType
PTInsert DropPerm ('Postgres 'Vanilla)
q
      RQDropSelectPermission DropPerm ('Postgres 'Vanilla)
q -> PermType -> DropPerm ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
PermType -> DropPerm b -> m EncJSON
runDropPerm PermType
PTSelect DropPerm ('Postgres 'Vanilla)
q
      RQDropUpdatePermission DropPerm ('Postgres 'Vanilla)
q -> PermType -> DropPerm ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
PermType -> DropPerm b -> m EncJSON
runDropPerm PermType
PTUpdate DropPerm ('Postgres 'Vanilla)
q
      RQDropDeletePermission DropPerm ('Postgres 'Vanilla)
q -> PermType -> DropPerm ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(UserInfoM m, CacheRWM m, MonadError QErr m, MetadataM m,
 BackendMetadata b) =>
PermType -> DropPerm b -> m EncJSON
runDropPerm PermType
PTDelete DropPerm ('Postgres 'Vanilla)
q
      RQSetPermissionComment SetPermComment ('Postgres 'Vanilla)
q -> SetPermComment ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m, BackendMetadata b) =>
SetPermComment b -> m EncJSON
runSetPermComment SetPermComment ('Postgres 'Vanilla)
q
      RQGetInconsistentMetadata GetInconsistentMetadata
q -> GetInconsistentMetadata -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRM m) =>
GetInconsistentMetadata -> m EncJSON
runGetInconsistentMetadata GetInconsistentMetadata
q
      RQDropInconsistentMetadata DropInconsistentMetadata
q -> DropInconsistentMetadata -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
DropInconsistentMetadata -> m EncJSON
runDropInconsistentMetadata DropInconsistentMetadata
q
      RQInsert InsertQuery
q -> SQLGenCtx -> InsertQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, UserInfoM m, CacheRM m, MonadIO m, MonadTrace m,
 MonadBaseControl IO m, MetadataM m) =>
SQLGenCtx -> InsertQuery -> m EncJSON
runInsert SQLGenCtx
sqlGen InsertQuery
q
      RQSelect SelectQuery
q -> SQLGenCtx -> SelectQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, UserInfoM m, CacheRM m, MonadIO m, MonadBaseControl IO m,
 MonadTrace m, MetadataM m) =>
SQLGenCtx -> SelectQuery -> m EncJSON
runSelect SQLGenCtx
sqlGen SelectQuery
q
      RQUpdate UpdateQuery
q -> SQLGenCtx -> UpdateQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, UserInfoM m, CacheRM m, MonadBaseControl IO m, MonadIO m,
 MonadTrace m, MetadataM m) =>
SQLGenCtx -> UpdateQuery -> m EncJSON
runUpdate SQLGenCtx
sqlGen UpdateQuery
q
      RQDelete DeleteQuery
q -> SQLGenCtx -> DeleteQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, UserInfoM m, CacheRM m, MonadIO m, MonadTrace m,
 MonadBaseControl IO m, MetadataM m) =>
SQLGenCtx -> DeleteQuery -> m EncJSON
runDelete SQLGenCtx
sqlGen DeleteQuery
q
      RQCount CountQuery
q -> CountQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, UserInfoM m, CacheRM m, MonadIO m, MonadBaseControl IO m,
 MonadTrace m, MetadataM m) =>
CountQuery -> m EncJSON
runCount CountQuery
q
      RQAddRemoteSchema AddRemoteSchemaQuery
q -> Environment -> AddRemoteSchemaQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MonadIO m, ProvidesNetwork m, MetadataM m,
 MonadTrace m) =>
Environment -> AddRemoteSchemaQuery -> m EncJSON
runAddRemoteSchema Environment
env AddRemoteSchemaQuery
q
      RQUpdateRemoteSchema AddRemoteSchemaQuery
q -> Environment -> AddRemoteSchemaQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MonadIO m, ProvidesNetwork m, MetadataM m,
 MonadTrace m) =>
Environment -> AddRemoteSchemaQuery -> m EncJSON
runUpdateRemoteSchema Environment
env AddRemoteSchemaQuery
q
      RQRemoveRemoteSchema RemoteSchemaNameQuery
q -> RemoteSchemaNameQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, UserInfoM m, CacheRWM m, MetadataM m) =>
RemoteSchemaNameQuery -> m EncJSON
runRemoveRemoteSchema RemoteSchemaNameQuery
q
      RQReloadRemoteSchema RemoteSchemaNameQuery
q -> RemoteSchemaNameQuery -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
RemoteSchemaNameQuery -> m EncJSON
runReloadRemoteSchema RemoteSchemaNameQuery
q
      RQIntrospectRemoteSchema RemoteSchemaNameQuery
q -> RemoteSchemaNameQuery -> m EncJSON
forall (m :: * -> *).
(CacheRM m, QErrM m) =>
RemoteSchemaNameQuery -> m EncJSON
runIntrospectRemoteSchema RemoteSchemaNameQuery
q
      RQCreateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
q -> CreateFromSourceRelationship ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
CreateFromSourceRelationship b -> m EncJSON
runCreateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
q
      RQUpdateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
q -> CreateFromSourceRelationship ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
CreateFromSourceRelationship b -> m EncJSON
runUpdateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
q
      RQDeleteRemoteRelationship DeleteFromSourceRelationship ('Postgres 'Vanilla)
q -> DeleteFromSourceRelationship ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(BackendMetadata b, MonadError QErr m, CacheRWM m, MetadataM m) =>
DeleteFromSourceRelationship b -> m EncJSON
runDeleteRemoteRelationship DeleteFromSourceRelationship ('Postgres 'Vanilla)
q
      RQCreateEventTrigger CreateEventTriggerQuery ('Postgres 'Vanilla)
q -> CreateEventTriggerQuery ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *) r.
(BackendMetadata b, BackendEventTrigger b, QErrM m, UserInfoM m,
 CacheRWM m, MetadataM m, MonadIO m, MonadEventLogCleanup m,
 MonadReader r m, Has (Logger Hasura) r) =>
CreateEventTriggerQuery b -> m EncJSON
runCreateEventTriggerQuery CreateEventTriggerQuery ('Postgres 'Vanilla)
q
      RQDeleteEventTrigger DeleteEventTriggerQuery ('Postgres 'Vanilla)
q -> DeleteEventTriggerQuery ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(BackendEventTrigger b, MonadError QErr m, CacheRWM m, MonadIO m,
 MetadataM m) =>
DeleteEventTriggerQuery b -> m EncJSON
runDeleteEventTriggerQuery DeleteEventTriggerQuery ('Postgres 'Vanilla)
q
      RQRedeliverEvent RedeliverEventQuery ('Postgres 'Vanilla)
q -> RedeliverEventQuery ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(BackendEventTrigger b, MonadIO m, CacheRM m, QErrM m,
 MetadataM m) =>
RedeliverEventQuery b -> m EncJSON
runRedeliverEvent RedeliverEventQuery ('Postgres 'Vanilla)
q
      RQInvokeEventTrigger InvokeEventTriggerQuery ('Postgres 'Vanilla)
q -> InvokeEventTriggerQuery ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadIO m, QErrM m, CacheRM m, MetadataM m, MonadTrace m,
 UserInfoM m, BackendEventTrigger b) =>
InvokeEventTriggerQuery b -> m EncJSON
runInvokeEventTrigger InvokeEventTriggerQuery ('Postgres 'Vanilla)
q
      RQCreateCronTrigger CreateCronTrigger
q -> CreateCronTrigger -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, CacheRWM m, MonadIO m, MetadataM m,
 MonadMetadataStorage m) =>
CreateCronTrigger -> m EncJSON
runCreateCronTrigger CreateCronTrigger
q
      RQDeleteCronTrigger ScheduledTriggerName
q -> ScheduledTriggerName -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m,
 MonadMetadataStorage m) =>
ScheduledTriggerName -> m EncJSON
runDeleteCronTrigger ScheduledTriggerName
q
      RQCreateScheduledEvent CreateScheduledEvent
q -> CreateScheduledEvent -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, MonadMetadataStorage m) =>
CreateScheduledEvent -> m EncJSON
runCreateScheduledEvent CreateScheduledEvent
q
      RQCreateQueryCollection CreateCollection
q -> CreateCollection -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
CreateCollection -> m EncJSON
runCreateCollection CreateCollection
q
      RQRenameQueryCollection RenameCollection
q -> RenameCollection -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
RenameCollection -> m EncJSON
runRenameCollection RenameCollection
q
      RQDropQueryCollection DropCollection
q -> DropCollection -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, MetadataM m, CacheRWM m) =>
DropCollection -> m EncJSON
runDropCollection DropCollection
q
      RQAddQueryToCollection AddQueryToCollection
q -> AddQueryToCollection -> m EncJSON
forall (m :: * -> *).
(CacheRWM m, MonadError QErr m, MetadataM m) =>
AddQueryToCollection -> m EncJSON
runAddQueryToCollection AddQueryToCollection
q
      RQDropQueryFromCollection DropQueryFromCollection
q -> DropQueryFromCollection -> m EncJSON
forall (m :: * -> *).
(CacheRWM m, MonadError QErr m, MetadataM m) =>
DropQueryFromCollection -> m EncJSON
runDropQueryFromCollection DropQueryFromCollection
q
      RQAddCollectionToAllowlist AllowlistEntry
q -> AllowlistEntry -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, MetadataM m, CacheRWM m) =>
AllowlistEntry -> m EncJSON
runAddCollectionToAllowlist AllowlistEntry
q
      RQDropCollectionFromAllowlist DropCollectionFromAllowlist
q -> DropCollectionFromAllowlist -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, MetadataM m, CacheRWM m) =>
DropCollectionFromAllowlist -> m EncJSON
runDropCollectionFromAllowlist DropCollectionFromAllowlist
q
      RQReplaceMetadata ReplaceMetadata
q -> ReplaceMetadata -> m EncJSON
forall (m :: * -> *) r.
(CacheRWM m, MetadataM m, MonadIO m, MonadBaseControl IO m,
 MonadMetadataStorage m, MonadReader r m, MonadError QErr m,
 Has (Logger Hasura) r, MonadEventLogCleanup m,
 MonadGetPolicies m) =>
ReplaceMetadata -> m EncJSON
runReplaceMetadata ReplaceMetadata
q
      RQClearMetadata ClearMetadata
q -> ClearMetadata -> m EncJSON
forall (m :: * -> *) r.
(MonadIO m, CacheRWM m, MetadataM m, MonadMetadataStorage m,
 MonadBaseControl IO m, MonadReader r m, MonadError QErr m,
 Has (Logger Hasura) r, MonadEventLogCleanup m,
 MonadGetPolicies m) =>
ClearMetadata -> m EncJSON
runClearMetadata ClearMetadata
q
      RQExportMetadata ExportMetadata
q -> ExportMetadata -> m EncJSON
forall (m :: * -> *).
(QErrM m, MetadataM m) =>
ExportMetadata -> m EncJSON
runExportMetadata ExportMetadata
q
      RQReloadMetadata ReloadMetadata
q -> ReloadMetadata -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
ReloadMetadata -> m EncJSON
runReloadMetadata ReloadMetadata
q
      RQCreateAction CreateAction
q -> CreateAction -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
CreateAction -> m EncJSON
runCreateAction CreateAction
q
      RQDropAction DropAction
q -> DropAction -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m,
 MonadMetadataStorage m) =>
DropAction -> m EncJSON
runDropAction DropAction
q
      RQUpdateAction UpdateAction
q -> UpdateAction -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
UpdateAction -> m EncJSON
runUpdateAction UpdateAction
q
      RQCreateActionPermission CreateActionPermission
q -> CreateActionPermission -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
CreateActionPermission -> m EncJSON
runCreateActionPermission CreateActionPermission
q
      RQDropActionPermission DropActionPermission
q -> DropActionPermission -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
DropActionPermission -> m EncJSON
runDropActionPermission DropActionPermission
q
      RQCreateRestEndpoint CreateEndpoint
q -> CreateEndpoint -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m) =>
CreateEndpoint -> m EncJSON
runCreateEndpoint CreateEndpoint
q
      RQDropRestEndpoint DropEndpoint
q -> DropEndpoint -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m) =>
DropEndpoint -> m EncJSON
runDropEndpoint DropEndpoint
q
      RQDumpInternalState DumpInternalState
q -> DumpInternalState -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRM m) =>
DumpInternalState -> m EncJSON
runDumpInternalState DumpInternalState
q
      RQRunSql RunSQL
q -> forall (pgKind :: PostgresKind) (m :: * -> *).
(BackendMetadata ('Postgres pgKind), ToMetadataFetchQuery pgKind,
 FetchTableMetadata pgKind, FetchFunctionMetadata pgKind,
 CacheRWM m, MetadataM m, MonadBaseControl IO m, MonadError QErr m,
 MonadIO m, MonadTrace m, UserInfoM m) =>
SQLGenCtx -> RunSQL -> m EncJSON
runRunSQL @'Vanilla SQLGenCtx
sqlGen RunSQL
q
      RQSetCustomTypes CustomTypes
q -> CustomTypes -> m EncJSON
forall (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m) =>
CustomTypes -> m EncJSON
runSetCustomTypes CustomTypes
q
      RQBulk [RQLQuery]
qs -> [EncJSON] -> EncJSON
encJFromList ([EncJSON] -> EncJSON) -> m [EncJSON] -> m EncJSON
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (RQLQuery -> m EncJSON) -> [RQLQuery] -> m [EncJSON]
forall (m :: * -> *) a b. QErrM m => (a -> m b) -> [a] -> m [b]
indexedMapM (Environment -> SQLGenCtx -> RQLQuery -> m EncJSON
forall (m :: * -> *) r.
(CacheRWM m, UserInfoM m, MonadBaseControl IO m, MonadIO m,
 MonadTrace m, MetadataM m, MonadMetadataStorage m,
 MonadQueryTags m, MonadReader r m, MonadError QErr m,
 Has (Logger Hasura) r, MonadEventLogCleanup m,
 ProvidesHasuraServices m, MonadGetPolicies m) =>
Environment -> SQLGenCtx -> RQLQuery -> m EncJSON
runQueryM Environment
env SQLGenCtx
sqlGen) [RQLQuery]
qs

    runQueryV2M :: RQLQueryV2 -> m EncJSON
runQueryV2M = \case
      RQV2TrackTable TrackTableV2 ('Postgres 'Vanilla)
q -> TrackTableV2 ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
TrackTableV2 b -> m EncJSON
runTrackTableV2Q TrackTableV2 ('Postgres 'Vanilla)
q
      RQV2SetTableCustomFields SetTableCustomFields
q -> SetTableCustomFields -> m EncJSON
forall (m :: * -> *).
(QErrM m, CacheRWM m, MetadataM m) =>
SetTableCustomFields -> m EncJSON
runSetTableCustomFieldsQV2 SetTableCustomFields
q
      RQV2TrackFunction TrackFunctionV2 ('Postgres 'Vanilla)
q -> TrackFunctionV2 ('Postgres 'Vanilla) -> m EncJSON
forall (b :: BackendType) (m :: * -> *).
(BackendMetadata b, QErrM m, CacheRWM m, MetadataM m) =>
TrackFunctionV2 b -> m EncJSON
Functions.runTrackFunctionV2 TrackFunctionV2 ('Postgres 'Vanilla)
q
      RQV2ReplaceMetadata ReplaceMetadataV2
q -> ReplaceMetadataV2 -> m EncJSON
forall (m :: * -> *) r.
(CacheRWM m, MetadataM m, MonadIO m, MonadBaseControl IO m,
 MonadMetadataStorage m, MonadReader r m, MonadError QErr m,
 Has (Logger Hasura) r, MonadEventLogCleanup m,
 MonadGetPolicies m) =>
ReplaceMetadataV2 -> m EncJSON
runReplaceMetadataV2 ReplaceMetadataV2
q

requiresAdmin :: RQLQuery -> Bool
requiresAdmin :: RQLQuery -> Bool
requiresAdmin = \case
  RQV1 RQLQueryV1
q -> case RQLQueryV1
q of
    RQAddExistingTableOrView TrackTable ('Postgres 'Vanilla)
_ -> Bool
True
    RQTrackTable TrackTable ('Postgres 'Vanilla)
_ -> Bool
True
    RQUntrackTable UntrackTable ('Postgres 'Vanilla)
_ -> Bool
True
    RQSetTableIsEnum SetTableIsEnum ('Postgres 'Vanilla)
_ -> Bool
True
    RQSetTableCustomization SetTableCustomization ('Postgres 'Vanilla)
_ -> Bool
True
    RQTrackFunction TrackFunction ('Postgres 'Vanilla)
_ -> Bool
True
    RQUntrackFunction UnTrackFunction ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateObjectRelationship CreateObjRel ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateArrayRelationship CreateArrRel ('Postgres 'Vanilla)
_ -> Bool
True
    RQDropRelationship DropRel ('Postgres 'Vanilla)
_ -> Bool
True
    RQSetRelationshipComment SetRelComment ('Postgres 'Vanilla)
_ -> Bool
True
    RQRenameRelationship RenameRel ('Postgres 'Vanilla)
_ -> Bool
True
    RQAddComputedField AddComputedField ('Postgres 'Vanilla)
_ -> Bool
True
    RQDropComputedField DropComputedField ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
True
    RQUpdateRemoteRelationship CreateFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
True
    RQDeleteRemoteRelationship DeleteFromSourceRelationship ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateInsertPermission CreatePerm InsPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateSelectPermission CreatePerm SelPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateUpdatePermission CreatePerm UpdPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateDeletePermission CreatePerm DelPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQDropInsertPermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQDropSelectPermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQDropUpdatePermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQDropDeletePermission DropPerm ('Postgres 'Vanilla)
_ -> Bool
True
    RQSetPermissionComment SetPermComment ('Postgres 'Vanilla)
_ -> Bool
True
    RQGetInconsistentMetadata GetInconsistentMetadata
_ -> Bool
True
    RQDropInconsistentMetadata DropInconsistentMetadata
_ -> Bool
True
    RQInsert InsertQuery
_ -> Bool
False
    RQSelect SelectQuery
_ -> Bool
False
    RQUpdate UpdateQuery
_ -> Bool
False
    RQDelete DeleteQuery
_ -> Bool
False
    RQCount CountQuery
_ -> Bool
False
    RQAddRemoteSchema AddRemoteSchemaQuery
_ -> Bool
True
    RQUpdateRemoteSchema AddRemoteSchemaQuery
_ -> Bool
True
    RQRemoveRemoteSchema RemoteSchemaNameQuery
_ -> Bool
True
    RQReloadRemoteSchema RemoteSchemaNameQuery
_ -> Bool
True
    RQIntrospectRemoteSchema RemoteSchemaNameQuery
_ -> Bool
True
    RQCreateEventTrigger CreateEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
True
    RQDeleteEventTrigger DeleteEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
True
    RQRedeliverEvent RedeliverEventQuery ('Postgres 'Vanilla)
_ -> Bool
True
    RQInvokeEventTrigger InvokeEventTriggerQuery ('Postgres 'Vanilla)
_ -> Bool
True
    RQCreateCronTrigger CreateCronTrigger
_ -> Bool
True
    RQDeleteCronTrigger ScheduledTriggerName
_ -> Bool
True
    RQCreateScheduledEvent CreateScheduledEvent
_ -> Bool
True
    RQCreateQueryCollection CreateCollection
_ -> Bool
True
    RQRenameQueryCollection RenameCollection
_ -> Bool
True
    RQDropQueryCollection DropCollection
_ -> Bool
True
    RQAddQueryToCollection AddQueryToCollection
_ -> Bool
True
    RQDropQueryFromCollection DropQueryFromCollection
_ -> Bool
True
    RQAddCollectionToAllowlist AllowlistEntry
_ -> Bool
True
    RQDropCollectionFromAllowlist DropCollectionFromAllowlist
_ -> Bool
True
    RQReplaceMetadata ReplaceMetadata
_ -> Bool
True
    RQClearMetadata ClearMetadata
_ -> Bool
True
    RQExportMetadata ExportMetadata
_ -> Bool
True
    RQReloadMetadata ReloadMetadata
_ -> Bool
True
    RQCreateRestEndpoint CreateEndpoint
_ -> Bool
True
    RQDropRestEndpoint DropEndpoint
_ -> Bool
True
    RQCreateAction CreateAction
_ -> Bool
True
    RQDropAction DropAction
_ -> Bool
True
    RQUpdateAction UpdateAction
_ -> Bool
True
    RQCreateActionPermission CreateActionPermission
_ -> Bool
True
    RQDropActionPermission DropActionPermission
_ -> Bool
True
    RQDumpInternalState DumpInternalState
_ -> Bool
True
    RQSetCustomTypes CustomTypes
_ -> Bool
True
    RQRunSql RunSQL
_ -> Bool
True
    RQBulk [RQLQuery]
qs -> (RQLQuery -> Bool) -> [RQLQuery] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any RQLQuery -> Bool
requiresAdmin [RQLQuery]
qs
  RQV2 RQLQueryV2
q -> case RQLQueryV2
q of
    RQV2TrackTable TrackTableV2 ('Postgres 'Vanilla)
_ -> Bool
True
    RQV2SetTableCustomFields SetTableCustomFields
_ -> Bool
True
    RQV2TrackFunction TrackFunctionV2 ('Postgres 'Vanilla)
_ -> Bool
True
    RQV2ReplaceMetadata ReplaceMetadataV2
_ -> Bool
True