2020-04-24 10:55:51 +03:00
|
|
|
-- | The RQL query ('/v1/query')
|
2021-11-04 19:08:33 +03:00
|
|
|
module Hasura.Server.API.Query
|
|
|
|
( RQLQuery,
|
|
|
|
queryModifiesSchemaCache,
|
|
|
|
requiresAdmin,
|
|
|
|
runQuery,
|
|
|
|
)
|
|
|
|
where
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
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.RemoteSchema
|
|
|
|
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
|
2022-03-13 10:40:06 +03:00
|
|
|
import Hasura.RQL.Types.Endpoint
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.RQL.Types.Run
|
|
|
|
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 (..))
|
2021-05-11 18:18:31 +03:00
|
|
|
|
2019-09-19 07:47:36 +03:00
|
|
|
data RQLQueryV1
|
2021-04-22 00:44:37 +03:00
|
|
|
= RQAddExistingTableOrView !(TrackTable ('Postgres 'Vanilla))
|
|
|
|
| RQTrackTable !(TrackTable ('Postgres 'Vanilla))
|
|
|
|
| RQUntrackTable !(UntrackTable ('Postgres 'Vanilla))
|
2019-07-22 15:47:13 +03:00
|
|
|
| RQSetTableIsEnum !SetTableIsEnum
|
2021-06-17 16:21:55 +03:00
|
|
|
| RQSetTableCustomization !(SetTableCustomization ('Postgres 'Vanilla))
|
2021-04-22 00:44:37 +03:00
|
|
|
| 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))
|
2021-09-24 01:56:37 +03:00
|
|
|
| -- computed fields related
|
|
|
|
RQAddComputedField !(AddComputedField ('Postgres 'Vanilla))
|
2021-04-22 00:44:37 +03:00
|
|
|
| RQDropComputedField !(DropComputedField ('Postgres 'Vanilla))
|
Fix several issues with remote relationships.
## Remaining Work
- [x] changelog entry
- [x] more tests: `<backend>_delete_remote_relationship` is definitely untested
- [x] negative tests: we probably want to assert that there are some APIs we DON'T support
- [x] update the console to use the new API, if necessary
- [x] ~~adding the corresponding documentation for the API for other backends (only `pg_` was added here)~~
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3170
- [x] ~~deciding which backends should support this API~~
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3170
- [x] ~~deciding what to do about potentially overlapping schematic representations~~
- ~~cf. https://github.com/hasura/graphql-engine-mono/pull/3157#issuecomment-995307624~~
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3171
- [x] ~~add more descriptive versioning information to some of the types that are changing in this PR~~
- cf. https://github.com/hasura/graphql-engine-mono/pull/3157#discussion_r769830920
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3172
## Description
This PR fixes several important issues wrt. the remote relationship API.
- it fixes a regression introduced by [#3124](https://github.com/hasura/graphql-engine-mono/pull/3124), which prevented `<backend>_create_remote_relationship` from accepting the old argument format (break of backwards compatibility, broke the console)
- it removes the command `create_remote_relationship` added to the v1/metadata API as a work-around as part of [#3124](https://github.com/hasura/graphql-engine-mono/pull/3124)
- it reverts the subsequent fix in the console: [#3149](https://github.com/hasura/graphql-engine-mono/pull/3149)
Furthermore, this PR also addresses two other issues:
- THE DOCUMENTATION OF THE METADATA API WAS WRONG, and documented `create_remote_relationship` instead of `<backend>_create_remote_relationship`: this PR fixes this by adding `pg_` everywhere, but does not attempt to add the corresponding documentation for other backends, partly because:
- `<backend>_delete_remote_relationship` WAS BROKEN ON NON-POSTGRES BACKENDS; it always expected an argument parameterized by Postgres.
As of main, the `<backend>_(create|update|delete)_remote_relationship` commands are supported on Postgres, Citus, BigQuery, but **NOT MSSQL**. I do not know if this is intentional or not, if it even should be publicized or not, and as a result this PR doesn't change this.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3157
Co-authored-by: jkachmar <8461423+jkachmar@users.noreply.github.com>
GitOrigin-RevId: 37e2f41522a9229a11c595574c3f4984317d652a
2021-12-16 23:28:08 +03:00
|
|
|
| RQCreateRemoteRelationship !(CreateFromSourceRelationship ('Postgres 'Vanilla))
|
|
|
|
| RQUpdateRemoteRelationship !(CreateFromSourceRelationship ('Postgres 'Vanilla))
|
2021-12-01 07:53:34 +03:00
|
|
|
| RQDeleteRemoteRelationship !(DeleteFromSourceRelationship ('Postgres 'Vanilla))
|
2021-06-09 22:42:37 +03:00
|
|
|
| RQCreateInsertPermission !(CreatePerm InsPerm ('Postgres 'Vanilla))
|
|
|
|
| RQCreateSelectPermission !(CreatePerm SelPerm ('Postgres 'Vanilla))
|
|
|
|
| RQCreateUpdatePermission !(CreatePerm UpdPerm ('Postgres 'Vanilla))
|
|
|
|
| RQCreateDeletePermission !(CreatePerm DelPerm ('Postgres 'Vanilla))
|
|
|
|
| RQDropInsertPermission !(DropPerm InsPerm ('Postgres 'Vanilla))
|
|
|
|
| RQDropSelectPermission !(DropPerm SelPerm ('Postgres 'Vanilla))
|
|
|
|
| RQDropUpdatePermission !(DropPerm UpdPerm ('Postgres 'Vanilla))
|
|
|
|
| RQDropDeletePermission !(DropPerm DelPerm ('Postgres 'Vanilla))
|
2021-04-22 00:44:37 +03:00
|
|
|
| RQSetPermissionComment !(SetPermComment ('Postgres 'Vanilla))
|
2019-04-17 19:29:39 +03:00
|
|
|
| RQGetInconsistentMetadata !GetInconsistentMetadata
|
|
|
|
| RQDropInconsistentMetadata !DropInconsistentMetadata
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQInsert !InsertQuery
|
|
|
|
| RQSelect !SelectQuery
|
|
|
|
| RQUpdate !UpdateQuery
|
|
|
|
| RQDelete !DeleteQuery
|
|
|
|
| RQCount !CountQuery
|
|
|
|
| RQBulk ![RQLQuery]
|
2021-09-24 01:56:37 +03:00
|
|
|
| -- schema-stitching, custom resolver related
|
|
|
|
RQAddRemoteSchema !AddRemoteSchemaQuery
|
2021-06-21 20:41:43 +03:00
|
|
|
| RQUpdateRemoteSchema !AddRemoteSchemaQuery
|
2019-07-08 08:51:41 +03:00
|
|
|
| RQRemoveRemoteSchema !RemoteSchemaNameQuery
|
|
|
|
| RQReloadRemoteSchema !RemoteSchemaNameQuery
|
2020-05-27 18:02:58 +03:00
|
|
|
| RQIntrospectRemoteSchema !RemoteSchemaNameQuery
|
2021-04-22 00:44:37 +03:00
|
|
|
| RQCreateEventTrigger !(CreateEventTriggerQuery ('Postgres 'Vanilla))
|
|
|
|
| RQDeleteEventTrigger !(DeleteEventTriggerQuery ('Postgres 'Vanilla))
|
2021-09-24 01:56:37 +03:00
|
|
|
| RQRedeliverEvent !(RedeliverEventQuery ('Postgres 'Vanilla))
|
2021-04-22 00:44:37 +03:00
|
|
|
| RQInvokeEventTrigger !(InvokeEventTriggerQuery ('Postgres 'Vanilla))
|
2021-09-24 01:56:37 +03:00
|
|
|
| -- scheduled triggers
|
|
|
|
RQCreateCronTrigger !CreateCronTrigger
|
2020-05-13 15:33:16 +03:00
|
|
|
| RQDeleteCronTrigger !ScheduledTriggerName
|
|
|
|
| RQCreateScheduledEvent !CreateScheduledEvent
|
2021-09-24 01:56:37 +03:00
|
|
|
| -- query collections, allow list related
|
|
|
|
RQCreateQueryCollection !CreateCollection
|
2019-05-16 09:13:25 +03:00
|
|
|
| RQDropQueryCollection !DropCollection
|
|
|
|
| RQAddQueryToCollection !AddQueryToCollection
|
|
|
|
| RQDropQueryFromCollection !DropQueryFromCollection
|
2022-02-08 19:53:30 +03:00
|
|
|
| RQAddCollectionToAllowlist !AllowlistEntry
|
|
|
|
| RQDropCollectionFromAllowlist !DropCollectionFromAllowlist
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQRunSql !RunSQL
|
2020-12-28 15:56:00 +03:00
|
|
|
| RQReplaceMetadata !ReplaceMetadata
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQExportMetadata !ExportMetadata
|
|
|
|
| RQClearMetadata !ClearMetadata
|
2018-09-05 18:25:30 +03:00
|
|
|
| RQReloadMetadata !ReloadMetadata
|
2020-02-13 20:38:23 +03:00
|
|
|
| RQCreateAction !CreateAction
|
|
|
|
| RQDropAction !DropAction
|
|
|
|
| RQUpdateAction !UpdateAction
|
|
|
|
| RQCreateActionPermission !CreateActionPermission
|
|
|
|
| RQDropActionPermission !DropActionPermission
|
2021-01-29 04:02:34 +03:00
|
|
|
| RQCreateRestEndpoint !CreateEndpoint
|
|
|
|
| RQDropRestEndpoint !DropEndpoint
|
2018-06-27 16:11:32 +03:00
|
|
|
| RQDumpInternalState !DumpInternalState
|
2020-02-13 20:38:23 +03:00
|
|
|
| RQSetCustomTypes !CustomTypes
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2019-09-19 07:47:36 +03:00
|
|
|
data RQLQueryV2
|
2021-04-22 00:44:37 +03:00
|
|
|
= RQV2TrackTable !(TrackTableV2 ('Postgres 'Vanilla))
|
2020-10-29 15:48:45 +03:00
|
|
|
| RQV2SetTableCustomFields !SetTableCustomFields -- deprecated
|
2021-04-22 00:44:37 +03:00
|
|
|
| RQV2TrackFunction !(TrackFunctionV2 ('Postgres 'Vanilla))
|
2021-02-16 11:08:19 +03:00
|
|
|
| RQV2ReplaceMetadata !ReplaceMetadataV2
|
2019-09-19 07:47:36 +03:00
|
|
|
|
|
|
|
data RQLQuery
|
|
|
|
= RQV1 !RQLQueryV1
|
|
|
|
| RQV2 !RQLQueryV2
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
$( deriveFromJSON
|
|
|
|
defaultOptions
|
|
|
|
{ constructorTagModifier = snakeCase . drop 2,
|
|
|
|
sumEncoding = TaggedObject "type" "args"
|
|
|
|
}
|
|
|
|
''RQLQueryV1
|
|
|
|
)
|
2019-09-19 07:47:36 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
$( deriveFromJSON
|
|
|
|
defaultOptions
|
|
|
|
{ constructorTagModifier = snakeCase . drop 4,
|
|
|
|
sumEncoding = TaggedObject "type" "args",
|
|
|
|
tagSingleConstructors = True
|
|
|
|
}
|
|
|
|
''RQLQueryV2
|
2019-09-19 07:47:36 +03:00
|
|
|
)
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
runQuery ::
|
2021-10-13 19:38:56 +03:00
|
|
|
( MonadIO m,
|
2021-09-24 01:56:37 +03:00
|
|
|
Tracing.MonadTrace m,
|
|
|
|
MonadBaseControl IO m,
|
|
|
|
MonadMetadataStorage m,
|
|
|
|
MonadResolveSource m,
|
|
|
|
MonadQueryTags m
|
|
|
|
) =>
|
|
|
|
Env.Environment ->
|
|
|
|
L.Logger L.Hasura ->
|
|
|
|
InstanceId ->
|
|
|
|
UserInfo ->
|
|
|
|
RebuildableSchemaCache ->
|
|
|
|
HTTP.Manager ->
|
|
|
|
ServerConfigCtx ->
|
|
|
|
RQLQuery ->
|
|
|
|
m (EncJSON, RebuildableSchemaCache)
|
2021-09-09 14:54:19 +03:00
|
|
|
runQuery env logger instanceId userInfo sc hMgr serverConfigCtx query = do
|
2021-12-08 09:26:46 +03:00
|
|
|
when ((_sccReadOnlyMode serverConfigCtx == ReadOnlyModeEnabled) && queryModifiesUserDB query) $
|
|
|
|
throw400 NotSupported "Cannot run write queries when read-only mode is enabled"
|
|
|
|
|
2021-02-19 05:39:30 +03:00
|
|
|
(metadata, currentResourceVersion) <- fetchMetadata
|
2021-09-24 01:56:37 +03:00
|
|
|
result <-
|
2021-09-25 06:59:35 +03:00
|
|
|
runReaderT (runQueryM env query) logger & \x -> do
|
|
|
|
((js, meta), rsc, ci) <-
|
2021-09-24 01:56:37 +03:00
|
|
|
x & runMetadataT metadata
|
|
|
|
& runCacheRWT sc
|
|
|
|
& peelRun runCtx
|
|
|
|
& runExceptT
|
|
|
|
& liftEitherM
|
2021-09-25 06:59:35 +03:00
|
|
|
pure (js, rsc, ci, meta)
|
2021-02-19 05:39:30 +03:00
|
|
|
withReload currentResourceVersion result
|
2019-03-12 08:46:27 +03:00
|
|
|
where
|
2021-01-29 08:48:17 +03:00
|
|
|
runCtx = RunCtx userInfo hMgr serverConfigCtx
|
2020-12-08 17:22:31 +03:00
|
|
|
|
2021-02-19 05:39:30 +03:00
|
|
|
withReload currentResourceVersion (result, updatedCache, invalidations, updatedMetadata) = do
|
2020-01-09 02:19:02 +03:00
|
|
|
when (queryModifiesSchemaCache query) $ do
|
2021-02-18 19:46:14 +03:00
|
|
|
case (_sccMaintenanceMode serverConfigCtx) of
|
2021-04-06 06:25:02 +03:00
|
|
|
MaintenanceModeDisabled -> do
|
2021-02-18 19:46:14 +03:00
|
|
|
-- set modified metadata in storage
|
2021-04-06 06:25:02 +03:00
|
|
|
newResourceVersion <- setMetadata currentResourceVersion updatedMetadata
|
|
|
|
-- notify schema cache sync
|
|
|
|
notifySchemaCacheSync newResourceVersion instanceId invalidations
|
2021-02-18 19:46:14 +03:00
|
|
|
MaintenanceModeEnabled ->
|
|
|
|
throw500 "metadata cannot be modified in maintenance mode"
|
2020-12-14 07:30:19 +03:00
|
|
|
pure (result, updatedCache)
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2020-01-09 02:19:02 +03:00
|
|
|
-- | 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
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
|
|
|
RQDropQueryCollection _ -> True
|
|
|
|
RQAddQueryToCollection _ -> True
|
|
|
|
RQDropQueryFromCollection _ -> True
|
|
|
|
RQAddCollectionToAllowlist _ -> True
|
2020-07-14 22:00:58 +03:00
|
|
|
RQDropCollectionFromAllowlist _ -> True
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
2020-01-09 02:19:02 +03:00
|
|
|
queryModifiesSchemaCache (RQV2 qi) = case qi of
|
2021-09-24 01:56:37 +03:00
|
|
|
RQV2TrackTable _ -> True
|
2019-09-19 07:47:36 +03:00
|
|
|
RQV2SetTableCustomFields _ -> True
|
2021-09-24 01:56:37 +03:00
|
|
|
RQV2TrackFunction _ -> True
|
|
|
|
RQV2ReplaceMetadata _ -> True
|
2018-06-27 16:11:32 +03:00
|
|
|
|
2021-12-08 09:26:46 +03:00
|
|
|
-- | 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
|
|
|
|
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
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
runQueryM ::
|
2021-10-13 19:38:56 +03:00
|
|
|
( CacheRWM m,
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
|
|
|
) =>
|
|
|
|
Env.Environment ->
|
|
|
|
RQLQuery ->
|
|
|
|
m EncJSON
|
2021-01-07 12:04:22 +03:00
|
|
|
runQueryM env rq = withPathK "args" $ case rq of
|
2020-01-09 02:19:02 +03:00
|
|
|
RQV1 q -> runQueryV1M q
|
|
|
|
RQV2 q -> runQueryV2M q
|
2019-07-08 08:51:41 +03:00
|
|
|
where
|
2019-09-19 07:47:36 +03:00
|
|
|
runQueryV1M = \case
|
2021-09-24 01:56:37 +03:00
|
|
|
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 q
|
|
|
|
RQDropSelectPermission q -> runDropPerm q
|
|
|
|
RQDropUpdatePermission q -> runDropPerm q
|
|
|
|
RQDropDeletePermission q -> runDropPerm 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
|
Fix several issues with remote relationships.
## Remaining Work
- [x] changelog entry
- [x] more tests: `<backend>_delete_remote_relationship` is definitely untested
- [x] negative tests: we probably want to assert that there are some APIs we DON'T support
- [x] update the console to use the new API, if necessary
- [x] ~~adding the corresponding documentation for the API for other backends (only `pg_` was added here)~~
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3170
- [x] ~~deciding which backends should support this API~~
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3170
- [x] ~~deciding what to do about potentially overlapping schematic representations~~
- ~~cf. https://github.com/hasura/graphql-engine-mono/pull/3157#issuecomment-995307624~~
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3171
- [x] ~~add more descriptive versioning information to some of the types that are changing in this PR~~
- cf. https://github.com/hasura/graphql-engine-mono/pull/3157#discussion_r769830920
- deferred to https://github.com/hasura/graphql-engine-mono/issues/3172
## Description
This PR fixes several important issues wrt. the remote relationship API.
- it fixes a regression introduced by [#3124](https://github.com/hasura/graphql-engine-mono/pull/3124), which prevented `<backend>_create_remote_relationship` from accepting the old argument format (break of backwards compatibility, broke the console)
- it removes the command `create_remote_relationship` added to the v1/metadata API as a work-around as part of [#3124](https://github.com/hasura/graphql-engine-mono/pull/3124)
- it reverts the subsequent fix in the console: [#3149](https://github.com/hasura/graphql-engine-mono/pull/3149)
Furthermore, this PR also addresses two other issues:
- THE DOCUMENTATION OF THE METADATA API WAS WRONG, and documented `create_remote_relationship` instead of `<backend>_create_remote_relationship`: this PR fixes this by adding `pg_` everywhere, but does not attempt to add the corresponding documentation for other backends, partly because:
- `<backend>_delete_remote_relationship` WAS BROKEN ON NON-POSTGRES BACKENDS; it always expected an argument parameterized by Postgres.
As of main, the `<backend>_(create|update|delete)_remote_relationship` commands are supported on Postgres, Citus, BigQuery, but **NOT MSSQL**. I do not know if this is intentional or not, if it even should be publicized or not, and as a result this PR doesn't change this.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3157
Co-authored-by: jkachmar <8461423+jkachmar@users.noreply.github.com>
GitOrigin-RevId: 37e2f41522a9229a11c595574c3f4984317d652a
2021-12-16 23:28:08 +03:00
|
|
|
RQCreateRemoteRelationship q -> runCreateRemoteRelationship q
|
|
|
|
RQUpdateRemoteRelationship q -> runUpdateRemoteRelationship q
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
|
|
|
RQDropQueryCollection q -> runDropCollection q
|
|
|
|
RQAddQueryToCollection q -> runAddQueryToCollection q
|
|
|
|
RQDropQueryFromCollection q -> runDropQueryFromCollection q
|
|
|
|
RQAddCollectionToAllowlist q -> runAddCollectionToAllowlist q
|
2020-11-02 14:50:40 +03:00
|
|
|
RQDropCollectionFromAllowlist q -> runDropCollectionFromAllowlist q
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
2019-09-19 07:47:36 +03:00
|
|
|
|
|
|
|
runQueryV2M = \case
|
2021-09-24 01:56:37 +03:00
|
|
|
RQV2TrackTable q -> runTrackTableV2Q q
|
2021-01-29 04:02:34 +03:00
|
|
|
RQV2SetTableCustomFields q -> runSetTableCustomFieldsQV2 q
|
2021-09-24 01:56:37 +03:00
|
|
|
RQV2TrackFunction q -> runTrackFunctionV2 q
|
|
|
|
RQV2ReplaceMetadata q -> runReplaceMetadataV2 q
|
2019-11-26 15:14:21 +03:00
|
|
|
|
|
|
|
requiresAdmin :: RQLQuery -> Bool
|
|
|
|
requiresAdmin = \case
|
|
|
|
RQV1 q -> case q of
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
|
|
|
RQDropQueryCollection _ -> True
|
|
|
|
RQAddQueryToCollection _ -> True
|
|
|
|
RQDropQueryFromCollection _ -> True
|
|
|
|
RQAddCollectionToAllowlist _ -> True
|
2020-07-14 22:00:58 +03:00
|
|
|
RQDropCollectionFromAllowlist _ -> True
|
2021-09-24 01:56:37 +03:00
|
|
|
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
|
2019-11-26 15:14:21 +03:00
|
|
|
RQV2 q -> case q of
|
2021-09-24 01:56:37 +03:00
|
|
|
RQV2TrackTable _ -> True
|
2019-11-26 15:14:21 +03:00
|
|
|
RQV2SetTableCustomFields _ -> True
|
2021-09-24 01:56:37 +03:00
|
|
|
RQV2TrackFunction _ -> True
|
|
|
|
RQV2ReplaceMetadata _ -> True
|