mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
a01d1188f2
The main aim of the PR is: 1. To set up a module structure for 'remote-schemas' package. 2. Move parts by the remote schema codebase into the new module structure to validate it. ## Notes to the reviewer Why a PR with large-ish diff? 1. We've been making progress on the MM project but we don't yet know long it is going to take us to get to the first milestone. To understand this better, we need to figure out the unknowns as soon as possible. Hence I've taken a stab at the first two items in the [end-state](https://gist.github.com/0x777/ca2bdc4284d21c3eec153b51dea255c9) document to figure out the unknowns. Unsurprisingly, there are a bunch of issues that we haven't discussed earlier. These are documented in the 'open questions' section. 1. The diff is large but that is only code moved around and I've added a section that documents how things are moved. In addition, there are fair number of PR comments to help with the review process. ## Changes in the PR ### Module structure Sets up the module structure as follows: ``` Hasura/ RemoteSchema/ Metadata/ Types.hs SchemaCache/ Types.hs Permission.hs RemoteRelationship.hs Build.hs MetadataAPI/ Types.hs Execute.hs ``` ### 1. Types representing metadata are moved Types that capture metadata information (currently scattered across several RQL modules) are moved into `Hasura.RemoteSchema.Metadata.Types`. - This new module only depends on very 'core' modules such as `Hasura.Session` for the notion of roles and `Hasura.Incremental` for `Cacheable` typeclass. - The requirement on database modules is avoided by generalizing the remote schemas metadata to accept an arbitrary 'r' for a remote relationship definition. ### 2. SchemaCache related types and build logic have been moved Types that represent remote schemas information in SchemaCache are moved into `Hasura.RemoteSchema.SchemaCache.Types`. Similar to `H.RS.Metadata.Types`, this module depends on 'core' modules except for `Hasura.GraphQL.Parser.Variable`. It has something to do with remote relationships but I haven't spent time looking into it. The validation of 'remote relationships to remote schema' is also something that needs to be looked at. Rips out the logic that builds remote schema's SchemaCache information from the monolithic `buildSchemaCacheRule` and moves it into `Hasura.RemoteSchema.SchemaCache.Build`. Further, the `.SchemaCache.Permission` and `.SchemaCache.RemoteRelationship` have been created from existing modules that capture schema cache building logic for those two components. This was a fair amount of work. On main, currently remote schema's SchemaCache information is built in two phases - in the first phase, 'permissions' and 'remote relationships' are ignored and in the second phase they are filled in. While remote relationships can only be resolved after partially resolving sources and other remote schemas, the same isn't true for permissions. Further, most of the work that is done to resolve remote relationships can be moved to the first phase so that the second phase can be a very simple traversal. This is the approach that was taken - resolve permissions and as much as remote relationships information in the first phase. ### 3. Metadata APIs related types and build logic have been moved The types that represent remote schema related metadata APIs and the execution logic have been moved to `Hasura.RemoteSchema.MetadataAPI.Types` and `.Execute` modules respectively. ## Open questions: 1. `Hasura.RemoteSchema.Metadata.Types` is so called because I was hoping that all of the metadata related APIs of remote schema can be brought in at `Hasura.RemoteSchema.Metadata.API`. However, as metadata APIs depended on functions from `SchemaCache` module (see [1](ceba6d6226/server/src-lib/Hasura/RQL/DDL/RemoteSchema.hs (L55)
) and [2](ceba6d6226/server/src-lib/Hasura/RQL/DDL/RemoteSchema.hs (L91)
), it made more sense to create a separate top-level module for `MetadataAPI`s. Maybe we can just have `Hasura.RemoteSchema.Metadata` and get rid of the extra nesting or have `Hasura.RemoteSchema.Metadata.{Core,Permission,RemoteRelationship}` if we want to break them down further. 1. `buildRemoteSchemas` in `H.RS.SchemaCache.Build` has the following type: ```haskell buildRemoteSchemas :: ( ArrowChoice arr, Inc.ArrowDistribute arr, ArrowWriter (Seq CollectedInfo) arr, Inc.ArrowCache m arr, MonadIO m, HasHttpManagerM m, Inc.Cacheable remoteRelationshipDefinition, ToJSON remoteRelationshipDefinition, MonadError QErr m ) => Env.Environment -> ( (Inc.Dependency (HashMap RemoteSchemaName Inc.InvalidationKey), OrderedRoles), [RemoteSchemaMetadataG remoteRelationshipDefinition] ) `arr` HashMap RemoteSchemaName (PartiallyResolvedRemoteSchemaCtxG remoteRelationshipDefinition, MetadataObject) ``` Note the dependence on `CollectedInfo` which is defined as ```haskell data CollectedInfo = CIInconsistency InconsistentMetadata | CIDependency MetadataObject -- ^ for error reporting on missing dependencies SchemaObjId SchemaDependency deriving (Eq) ``` this pretty much means that remote schemas is dependent on types from databases, actions, .... How do we fix this? Maybe introduce a typeclass such as `ArrowCollectRemoteSchemaDependencies` which is defined in `Hasura.RemoteSchema` and then implemented in graphql-engine? 1. The dependency on `buildSchemaCacheFor` in `.MetadataAPI.Execute` which has the following signature: ```haskell buildSchemaCacheFor :: (QErrM m, CacheRWM m, MetadataM m) => MetadataObjId -> MetadataModifier -> ``` This can be easily resolved if we restrict what the metadata APIs are allowed to do. Currently, they operate in an unfettered access to modify SchemaCache (the `CacheRWM` constraint): ```haskell runAddRemoteSchema :: ( QErrM m, CacheRWM m, MonadIO m, HasHttpManagerM m, MetadataM m, Tracing.MonadTrace m ) => Env.Environment -> AddRemoteSchemaQuery -> m EncJSON ``` This should instead be changed to restrict remote schema APIs to only modify remote schema metadata (but has access to the remote schemas part of the schema cache), this dependency is completely removed. ```haskell runAddRemoteSchema :: ( QErrM m, MonadIO m, HasHttpManagerM m, MonadReader RemoteSchemasSchemaCache m, MonadState RemoteSchemaMetadata m, Tracing.MonadTrace m ) => Env.Environment -> AddRemoteSchemaQuery -> m RemoteSchemeMetadataObjId ``` The idea is that the core graphql-engine would call these functions and then call `buildSchemaCacheFor`. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6291 GitOrigin-RevId: 51357148c6404afe70219afa71bd1d59bdf4ffc6
565 lines
21 KiB
Haskell
565 lines
21 KiB
Haskell
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
-- | The RQL query ('/v1/query')
|
|
module Hasura.Server.API.Query
|
|
( RQLQuery,
|
|
queryModifiesSchemaCache,
|
|
requiresAdmin,
|
|
runQuery,
|
|
)
|
|
where
|
|
|
|
import Control.Monad.Trans.Control (MonadBaseControl)
|
|
import Data.Aeson
|
|
import Data.Aeson.Casing
|
|
import Data.Aeson.TH
|
|
import Data.Environment qualified as Env
|
|
import Data.Has (Has)
|
|
import Hasura.Backends.Postgres.DDL.RunSQL
|
|
import Hasura.Base.Error
|
|
import Hasura.EncJSON
|
|
import Hasura.GraphQL.Execute.Backend
|
|
import Hasura.Logging qualified as L
|
|
import Hasura.Metadata.Class
|
|
import Hasura.Prelude
|
|
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.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.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.Run
|
|
import Hasura.RQL.Types.ScheduledTrigger
|
|
import Hasura.RQL.Types.SchemaCache.Build
|
|
import Hasura.RQL.Types.Source
|
|
import Hasura.RemoteSchema.MetadataAPI
|
|
import Hasura.SQL.Backend
|
|
import Hasura.Server.Types
|
|
import Hasura.Server.Utils
|
|
import Hasura.Session
|
|
import Hasura.Tracing qualified as Tracing
|
|
import Network.HTTP.Client qualified as HTTP
|
|
import Network.HTTP.Client.Manager (HasHttpManagerM (..))
|
|
|
|
data RQLQueryV1
|
|
= RQAddExistingTableOrView !(TrackTable ('Postgres 'Vanilla))
|
|
| RQTrackTable !(TrackTable ('Postgres 'Vanilla))
|
|
| RQUntrackTable !(UntrackTable ('Postgres 'Vanilla))
|
|
| RQSetTableIsEnum !(SetTableIsEnum ('Postgres 'Vanilla))
|
|
| RQSetTableCustomization !(SetTableCustomization ('Postgres 'Vanilla))
|
|
| RQTrackFunction !(TrackFunction ('Postgres 'Vanilla))
|
|
| RQUntrackFunction !(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
|
|
|
|
data RQLQueryV2
|
|
= RQV2TrackTable !(TrackTableV2 ('Postgres 'Vanilla))
|
|
| RQV2SetTableCustomFields !SetTableCustomFields -- deprecated
|
|
| RQV2TrackFunction !(TrackFunctionV2 ('Postgres 'Vanilla))
|
|
| RQV2ReplaceMetadata !ReplaceMetadataV2
|
|
|
|
data RQLQuery
|
|
= RQV1 !RQLQueryV1
|
|
| RQV2 !RQLQueryV2
|
|
|
|
-- Since at least one of the following mutually recursive instances is defined
|
|
-- via TH, after 9.0 they must all be defined within the same TH splice.
|
|
$( concat
|
|
<$> sequence
|
|
[ [d|
|
|
instance FromJSON RQLQuery where
|
|
parseJSON = withObject "Object" $ \o -> do
|
|
mVersion <- o .:? "version"
|
|
let version = fromMaybe VIVersion1 mVersion
|
|
val = Object o
|
|
case version of
|
|
VIVersion1 -> RQV1 <$> parseJSON val
|
|
VIVersion2 -> RQV2 <$> parseJSON val
|
|
|],
|
|
deriveFromJSON
|
|
defaultOptions
|
|
{ constructorTagModifier = snakeCase . drop 2,
|
|
sumEncoding = TaggedObject "type" "args"
|
|
}
|
|
''RQLQueryV1,
|
|
deriveFromJSON
|
|
defaultOptions
|
|
{ constructorTagModifier = snakeCase . drop 4,
|
|
sumEncoding = TaggedObject "type" "args",
|
|
tagSingleConstructors = True
|
|
}
|
|
''RQLQueryV2
|
|
]
|
|
)
|
|
|
|
runQuery ::
|
|
( MonadIO m,
|
|
Tracing.MonadTrace m,
|
|
MonadBaseControl IO m,
|
|
MonadMetadataStorage m,
|
|
MonadResolveSource m,
|
|
MonadQueryTags m,
|
|
MonadEventLogCleanup m
|
|
) =>
|
|
Env.Environment ->
|
|
L.Logger L.Hasura ->
|
|
InstanceId ->
|
|
UserInfo ->
|
|
RebuildableSchemaCache ->
|
|
HTTP.Manager ->
|
|
ServerConfigCtx ->
|
|
RQLQuery ->
|
|
m (EncJSON, RebuildableSchemaCache)
|
|
runQuery env logger instanceId userInfo sc hMgr serverConfigCtx query = do
|
|
when ((_sccReadOnlyMode serverConfigCtx == ReadOnlyModeEnabled) && queryModifiesUserDB query) $
|
|
throw400 NotSupported "Cannot run write queries when read-only mode is enabled"
|
|
|
|
let exportsMetadata = \case
|
|
RQV1 (RQExportMetadata _) -> True
|
|
_ -> False
|
|
metadataDefaults =
|
|
if (exportsMetadata query)
|
|
then emptyMetadataDefaults
|
|
else _sccMetadataDefaults serverConfigCtx
|
|
|
|
(metadata, currentResourceVersion) <- fetchMetadata
|
|
result <-
|
|
runReaderT (runQueryM env query) logger & \x -> do
|
|
((js, meta), rsc, ci) <-
|
|
x
|
|
& runMetadataT metadata metadataDefaults
|
|
& runCacheRWT sc
|
|
& peelRun runCtx
|
|
& runExceptT
|
|
& liftEitherM
|
|
pure (js, rsc, ci, meta)
|
|
withReload currentResourceVersion result
|
|
where
|
|
runCtx = RunCtx userInfo hMgr serverConfigCtx
|
|
|
|
withReload currentResourceVersion (result, updatedCache, invalidations, updatedMetadata) = do
|
|
when (queryModifiesSchemaCache query) $ do
|
|
case (_sccMaintenanceMode serverConfigCtx) of
|
|
MaintenanceModeDisabled -> do
|
|
-- set modified metadata in storage
|
|
newResourceVersion <- setMetadata currentResourceVersion updatedMetadata
|
|
-- notify schema cache sync
|
|
notifySchemaCacheSync newResourceVersion instanceId invalidations
|
|
MaintenanceModeEnabled () ->
|
|
throw500 "metadata cannot be modified in maintenance mode"
|
|
pure (result, updatedCache)
|
|
|
|
-- | 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 (RQV1 qi) = case qi of
|
|
RQAddExistingTableOrView _ -> True
|
|
RQTrackTable _ -> True
|
|
RQUntrackTable _ -> True
|
|
RQTrackFunction _ -> True
|
|
RQUntrackFunction _ -> True
|
|
RQSetTableIsEnum _ -> True
|
|
RQCreateObjectRelationship _ -> True
|
|
RQCreateArrayRelationship _ -> True
|
|
RQDropRelationship _ -> True
|
|
RQSetRelationshipComment _ -> False
|
|
RQRenameRelationship _ -> True
|
|
RQAddComputedField _ -> True
|
|
RQDropComputedField _ -> True
|
|
RQCreateRemoteRelationship _ -> True
|
|
RQUpdateRemoteRelationship _ -> True
|
|
RQDeleteRemoteRelationship _ -> True
|
|
RQCreateInsertPermission _ -> True
|
|
RQCreateSelectPermission _ -> True
|
|
RQCreateUpdatePermission _ -> True
|
|
RQCreateDeletePermission _ -> True
|
|
RQDropInsertPermission _ -> True
|
|
RQDropSelectPermission _ -> True
|
|
RQDropUpdatePermission _ -> True
|
|
RQDropDeletePermission _ -> True
|
|
RQSetPermissionComment _ -> False
|
|
RQGetInconsistentMetadata _ -> False
|
|
RQDropInconsistentMetadata _ -> True
|
|
RQInsert _ -> False
|
|
RQSelect _ -> False
|
|
RQUpdate _ -> False
|
|
RQDelete _ -> False
|
|
RQCount _ -> False
|
|
RQAddRemoteSchema _ -> True
|
|
RQUpdateRemoteSchema _ -> True
|
|
RQRemoveRemoteSchema _ -> True
|
|
RQReloadRemoteSchema _ -> True
|
|
RQIntrospectRemoteSchema _ -> False
|
|
RQCreateEventTrigger _ -> True
|
|
RQDeleteEventTrigger _ -> True
|
|
RQRedeliverEvent _ -> False
|
|
RQInvokeEventTrigger _ -> False
|
|
RQCreateCronTrigger _ -> True
|
|
RQDeleteCronTrigger _ -> True
|
|
RQCreateScheduledEvent _ -> False
|
|
RQCreateQueryCollection _ -> True
|
|
RQRenameQueryCollection _ -> True
|
|
RQDropQueryCollection _ -> True
|
|
RQAddQueryToCollection _ -> True
|
|
RQDropQueryFromCollection _ -> True
|
|
RQAddCollectionToAllowlist _ -> True
|
|
RQDropCollectionFromAllowlist _ -> True
|
|
RQRunSql q -> isSchemaCacheBuildRequiredRunSQL q
|
|
RQReplaceMetadata _ -> True
|
|
RQExportMetadata _ -> False
|
|
RQClearMetadata _ -> True
|
|
RQReloadMetadata _ -> True
|
|
RQCreateRestEndpoint _ -> True
|
|
RQDropRestEndpoint _ -> True
|
|
RQCreateAction _ -> True
|
|
RQDropAction _ -> True
|
|
RQUpdateAction _ -> True
|
|
RQCreateActionPermission _ -> True
|
|
RQDropActionPermission _ -> True
|
|
RQDumpInternalState _ -> False
|
|
RQSetCustomTypes _ -> True
|
|
RQSetTableCustomization _ -> True
|
|
RQBulk qs -> any queryModifiesSchemaCache qs
|
|
queryModifiesSchemaCache (RQV2 qi) = case qi of
|
|
RQV2TrackTable _ -> True
|
|
RQV2SetTableCustomFields _ -> True
|
|
RQV2TrackFunction _ -> True
|
|
RQV2ReplaceMetadata _ -> 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 (RQV1 qi) = case qi of
|
|
RQAddExistingTableOrView _ -> False
|
|
RQTrackTable _ -> False
|
|
RQUntrackTable _ -> False
|
|
RQTrackFunction _ -> False
|
|
RQUntrackFunction _ -> False
|
|
RQSetTableIsEnum _ -> False
|
|
RQCreateObjectRelationship _ -> False
|
|
RQCreateArrayRelationship _ -> False
|
|
RQDropRelationship _ -> False
|
|
RQSetRelationshipComment _ -> False
|
|
RQRenameRelationship _ -> False
|
|
RQAddComputedField _ -> False
|
|
RQDropComputedField _ -> False
|
|
RQCreateRemoteRelationship _ -> False
|
|
RQUpdateRemoteRelationship _ -> False
|
|
RQDeleteRemoteRelationship _ -> False
|
|
RQCreateInsertPermission _ -> False
|
|
RQCreateSelectPermission _ -> False
|
|
RQCreateUpdatePermission _ -> False
|
|
RQCreateDeletePermission _ -> False
|
|
RQDropInsertPermission _ -> False
|
|
RQDropSelectPermission _ -> False
|
|
RQDropUpdatePermission _ -> False
|
|
RQDropDeletePermission _ -> False
|
|
RQSetPermissionComment _ -> False
|
|
RQGetInconsistentMetadata _ -> False
|
|
RQDropInconsistentMetadata _ -> False
|
|
RQInsert _ -> True
|
|
RQSelect _ -> False
|
|
RQUpdate _ -> True
|
|
RQDelete _ -> True
|
|
RQCount _ -> False
|
|
RQAddRemoteSchema _ -> False
|
|
RQUpdateRemoteSchema _ -> False
|
|
RQRemoveRemoteSchema _ -> False
|
|
RQReloadRemoteSchema _ -> False
|
|
RQIntrospectRemoteSchema _ -> False
|
|
RQCreateEventTrigger _ -> True
|
|
RQDeleteEventTrigger _ -> True
|
|
RQRedeliverEvent _ -> False
|
|
RQInvokeEventTrigger _ -> False
|
|
RQCreateCronTrigger _ -> False
|
|
RQDeleteCronTrigger _ -> False
|
|
RQCreateScheduledEvent _ -> False
|
|
RQCreateQueryCollection _ -> False
|
|
RQRenameQueryCollection _ -> False
|
|
RQDropQueryCollection _ -> False
|
|
RQAddQueryToCollection _ -> False
|
|
RQDropQueryFromCollection _ -> False
|
|
RQAddCollectionToAllowlist _ -> False
|
|
RQDropCollectionFromAllowlist _ -> False
|
|
RQRunSql _ -> True
|
|
RQReplaceMetadata _ -> True
|
|
RQExportMetadata _ -> False
|
|
RQClearMetadata _ -> False
|
|
RQReloadMetadata _ -> False
|
|
RQCreateRestEndpoint _ -> False
|
|
RQDropRestEndpoint _ -> False
|
|
RQCreateAction _ -> False
|
|
RQDropAction _ -> False
|
|
RQUpdateAction _ -> False
|
|
RQCreateActionPermission _ -> False
|
|
RQDropActionPermission _ -> False
|
|
RQDumpInternalState _ -> False
|
|
RQSetCustomTypes _ -> False
|
|
RQSetTableCustomization _ -> False
|
|
RQBulk qs -> any queryModifiesUserDB qs
|
|
queryModifiesUserDB (RQV2 qi) = case qi of
|
|
RQV2TrackTable _ -> False
|
|
RQV2SetTableCustomFields _ -> False
|
|
RQV2TrackFunction _ -> False
|
|
RQV2ReplaceMetadata _ -> True
|
|
|
|
runQueryM ::
|
|
( CacheRWM m,
|
|
UserInfoM m,
|
|
MonadBaseControl IO m,
|
|
MonadIO m,
|
|
HasHttpManagerM m,
|
|
HasServerConfigCtx m,
|
|
Tracing.MonadTrace m,
|
|
MetadataM m,
|
|
MonadMetadataStorageQueryAPI m,
|
|
MonadQueryTags m,
|
|
MonadReader r m,
|
|
Has (L.Logger L.Hasura) r,
|
|
MonadEventLogCleanup m
|
|
) =>
|
|
Env.Environment ->
|
|
RQLQuery ->
|
|
m EncJSON
|
|
runQueryM env rq = withPathK "args" $ case rq of
|
|
RQV1 q -> runQueryV1M q
|
|
RQV2 q -> runQueryV2M q
|
|
where
|
|
runQueryV1M = \case
|
|
RQAddExistingTableOrView q -> runTrackTableQ q
|
|
RQTrackTable q -> runTrackTableQ q
|
|
RQUntrackTable q -> runUntrackTableQ q
|
|
RQSetTableIsEnum q -> runSetExistingTableIsEnumQ q
|
|
RQSetTableCustomization q -> runSetTableCustomization q
|
|
RQTrackFunction q -> runTrackFunc q
|
|
RQUntrackFunction q -> runUntrackFunc q
|
|
RQCreateObjectRelationship q -> runCreateRelationship ObjRel $ unCreateObjRel q
|
|
RQCreateArrayRelationship q -> runCreateRelationship ArrRel $ unCreateArrRel q
|
|
RQDropRelationship q -> runDropRel q
|
|
RQSetRelationshipComment q -> runSetRelComment q
|
|
RQRenameRelationship q -> runRenameRel q
|
|
RQAddComputedField q -> runAddComputedField q
|
|
RQDropComputedField q -> runDropComputedField q
|
|
RQCreateInsertPermission q -> runCreatePerm q
|
|
RQCreateSelectPermission q -> runCreatePerm q
|
|
RQCreateUpdatePermission q -> runCreatePerm q
|
|
RQCreateDeletePermission q -> runCreatePerm q
|
|
RQDropInsertPermission q -> runDropPerm PTInsert q
|
|
RQDropSelectPermission q -> runDropPerm PTSelect q
|
|
RQDropUpdatePermission q -> runDropPerm PTUpdate q
|
|
RQDropDeletePermission q -> runDropPerm PTDelete q
|
|
RQSetPermissionComment q -> runSetPermComment q
|
|
RQGetInconsistentMetadata q -> runGetInconsistentMetadata q
|
|
RQDropInconsistentMetadata q -> runDropInconsistentMetadata q
|
|
RQInsert q -> runInsert q
|
|
RQSelect q -> runSelect q
|
|
RQUpdate q -> runUpdate q
|
|
RQDelete q -> runDelete q
|
|
RQCount q -> runCount q
|
|
RQAddRemoteSchema q -> runAddRemoteSchema env q
|
|
RQUpdateRemoteSchema q -> runUpdateRemoteSchema env q
|
|
RQRemoveRemoteSchema q -> runRemoveRemoteSchema q
|
|
RQReloadRemoteSchema q -> runReloadRemoteSchema q
|
|
RQIntrospectRemoteSchema q -> runIntrospectRemoteSchema q
|
|
RQCreateRemoteRelationship q -> runCreateRemoteRelationship q
|
|
RQUpdateRemoteRelationship q -> runUpdateRemoteRelationship q
|
|
RQDeleteRemoteRelationship q -> runDeleteRemoteRelationship q
|
|
RQCreateEventTrigger q -> runCreateEventTriggerQuery q
|
|
RQDeleteEventTrigger q -> runDeleteEventTriggerQuery q
|
|
RQRedeliverEvent q -> runRedeliverEvent q
|
|
RQInvokeEventTrigger q -> runInvokeEventTrigger q
|
|
RQCreateCronTrigger q -> runCreateCronTrigger q
|
|
RQDeleteCronTrigger q -> runDeleteCronTrigger q
|
|
RQCreateScheduledEvent q -> runCreateScheduledEvent q
|
|
RQCreateQueryCollection q -> runCreateCollection q
|
|
RQRenameQueryCollection q -> runRenameCollection q
|
|
RQDropQueryCollection q -> runDropCollection q
|
|
RQAddQueryToCollection q -> runAddQueryToCollection q
|
|
RQDropQueryFromCollection q -> runDropQueryFromCollection q
|
|
RQAddCollectionToAllowlist q -> runAddCollectionToAllowlist q
|
|
RQDropCollectionFromAllowlist q -> runDropCollectionFromAllowlist q
|
|
RQReplaceMetadata q -> runReplaceMetadata q
|
|
RQClearMetadata q -> runClearMetadata q
|
|
RQExportMetadata q -> runExportMetadata q
|
|
RQReloadMetadata q -> runReloadMetadata q
|
|
RQCreateAction q -> runCreateAction q
|
|
RQDropAction q -> runDropAction q
|
|
RQUpdateAction q -> runUpdateAction q
|
|
RQCreateActionPermission q -> runCreateActionPermission q
|
|
RQDropActionPermission q -> runDropActionPermission q
|
|
RQCreateRestEndpoint q -> runCreateEndpoint q
|
|
RQDropRestEndpoint q -> runDropEndpoint q
|
|
RQDumpInternalState q -> runDumpInternalState q
|
|
RQRunSql q -> runRunSQL @'Vanilla q
|
|
RQSetCustomTypes q -> runSetCustomTypes q
|
|
RQBulk qs -> encJFromList <$> indexedMapM (runQueryM env) qs
|
|
|
|
runQueryV2M = \case
|
|
RQV2TrackTable q -> runTrackTableV2Q q
|
|
RQV2SetTableCustomFields q -> runSetTableCustomFieldsQV2 q
|
|
RQV2TrackFunction q -> runTrackFunctionV2 q
|
|
RQV2ReplaceMetadata q -> runReplaceMetadataV2 q
|
|
|
|
requiresAdmin :: RQLQuery -> Bool
|
|
requiresAdmin = \case
|
|
RQV1 q -> case q of
|
|
RQAddExistingTableOrView _ -> True
|
|
RQTrackTable _ -> True
|
|
RQUntrackTable _ -> True
|
|
RQSetTableIsEnum _ -> True
|
|
RQSetTableCustomization _ -> True
|
|
RQTrackFunction _ -> True
|
|
RQUntrackFunction _ -> True
|
|
RQCreateObjectRelationship _ -> True
|
|
RQCreateArrayRelationship _ -> True
|
|
RQDropRelationship _ -> True
|
|
RQSetRelationshipComment _ -> True
|
|
RQRenameRelationship _ -> True
|
|
RQAddComputedField _ -> True
|
|
RQDropComputedField _ -> True
|
|
RQCreateRemoteRelationship _ -> True
|
|
RQUpdateRemoteRelationship _ -> True
|
|
RQDeleteRemoteRelationship _ -> True
|
|
RQCreateInsertPermission _ -> True
|
|
RQCreateSelectPermission _ -> True
|
|
RQCreateUpdatePermission _ -> True
|
|
RQCreateDeletePermission _ -> True
|
|
RQDropInsertPermission _ -> True
|
|
RQDropSelectPermission _ -> True
|
|
RQDropUpdatePermission _ -> True
|
|
RQDropDeletePermission _ -> True
|
|
RQSetPermissionComment _ -> True
|
|
RQGetInconsistentMetadata _ -> True
|
|
RQDropInconsistentMetadata _ -> True
|
|
RQInsert _ -> False
|
|
RQSelect _ -> False
|
|
RQUpdate _ -> False
|
|
RQDelete _ -> False
|
|
RQCount _ -> False
|
|
RQAddRemoteSchema _ -> True
|
|
RQUpdateRemoteSchema _ -> True
|
|
RQRemoveRemoteSchema _ -> True
|
|
RQReloadRemoteSchema _ -> True
|
|
RQIntrospectRemoteSchema _ -> True
|
|
RQCreateEventTrigger _ -> True
|
|
RQDeleteEventTrigger _ -> True
|
|
RQRedeliverEvent _ -> True
|
|
RQInvokeEventTrigger _ -> True
|
|
RQCreateCronTrigger _ -> True
|
|
RQDeleteCronTrigger _ -> True
|
|
RQCreateScheduledEvent _ -> True
|
|
RQCreateQueryCollection _ -> True
|
|
RQRenameQueryCollection _ -> True
|
|
RQDropQueryCollection _ -> True
|
|
RQAddQueryToCollection _ -> True
|
|
RQDropQueryFromCollection _ -> True
|
|
RQAddCollectionToAllowlist _ -> True
|
|
RQDropCollectionFromAllowlist _ -> True
|
|
RQReplaceMetadata _ -> True
|
|
RQClearMetadata _ -> True
|
|
RQExportMetadata _ -> True
|
|
RQReloadMetadata _ -> True
|
|
RQCreateRestEndpoint _ -> True
|
|
RQDropRestEndpoint _ -> True
|
|
RQCreateAction _ -> True
|
|
RQDropAction _ -> True
|
|
RQUpdateAction _ -> True
|
|
RQCreateActionPermission _ -> True
|
|
RQDropActionPermission _ -> True
|
|
RQDumpInternalState _ -> True
|
|
RQSetCustomTypes _ -> True
|
|
RQRunSql _ -> True
|
|
RQBulk qs -> any requiresAdmin qs
|
|
RQV2 q -> case q of
|
|
RQV2TrackTable _ -> True
|
|
RQV2SetTableCustomFields _ -> True
|
|
RQV2TrackFunction _ -> True
|
|
RQV2ReplaceMetadata _ -> True
|