server: delegate Metadata API parsing to a new backend class

https://github.com/hasura/graphql-engine-mono/pull/1179

Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
Co-authored-by: Tirumarai Selvan <8663570+tirumaraiselvan@users.noreply.github.com>
GitOrigin-RevId: b565de269e215ae8172bddd895f3d057ddcc8695
This commit is contained in:
Antoine Leblanc 2021-07-07 02:43:42 +01:00 committed by hasura-bot
parent 76c322589c
commit 80161e4208
16 changed files with 681 additions and 409 deletions

View File

@ -317,6 +317,7 @@ library
, Hasura.Backends.BigQuery.DDL.RunSQL
, Hasura.Backends.BigQuery.DDL.Source
, Hasura.Backends.BigQuery.FromIr
, Hasura.Backends.BigQuery.Instances.API
, Hasura.Backends.BigQuery.Instances.Execute
, Hasura.Backends.BigQuery.Instances.Schema
, Hasura.Backends.BigQuery.Instances.Transport
@ -328,6 +329,26 @@ library
, Hasura.Backends.BigQuery.ToQuery
, Hasura.Backends.BigQuery.Types
, Hasura.Backends.MSSQL.Connection
, Hasura.Backends.MSSQL.DDL
, Hasura.Backends.MSSQL.DDL.BoolExp
, Hasura.Backends.MSSQL.DDL.RunSQL
, Hasura.Backends.MSSQL.DDL.Source
, Hasura.Backends.MSSQL.FromIr
, Hasura.Backends.MSSQL.Instances.API
, Hasura.Backends.MSSQL.Instances.Execute
, Hasura.Backends.MSSQL.Instances.Metadata
, Hasura.Backends.MSSQL.Instances.Schema
, Hasura.Backends.MSSQL.Instances.Transport
, Hasura.Backends.MSSQL.Instances.Types
, Hasura.Backends.MSSQL.Meta
, Hasura.Backends.MSSQL.Plan
, Hasura.Backends.MSSQL.SQL.Value
, Hasura.Backends.MSSQL.ToQuery
, Hasura.Backends.MSSQL.Types
, Hasura.Backends.MSSQL.Types.Instances
, Hasura.Backends.MSSQL.Types.Internal
, Hasura.Backends.Postgres.Connection
, Hasura.Backends.Postgres.DDL
, Hasura.Backends.Postgres.DDL.BoolExp
@ -340,8 +361,9 @@ library
, Hasura.Backends.Postgres.Execute.LiveQuery
, Hasura.Backends.Postgres.Execute.Insert
, Hasura.Backends.Postgres.Execute.Mutation
, Hasura.Backends.Postgres.Execute.Types
, Hasura.Backends.Postgres.Execute.Prepare
, Hasura.Backends.Postgres.Execute.Types
, Hasura.Backends.Postgres.Instances.API
, Hasura.Backends.Postgres.Instances.Execute
, Hasura.Backends.Postgres.Instances.Metadata
, Hasura.Backends.Postgres.Instances.Schema
@ -366,26 +388,6 @@ library
, Hasura.Backends.Postgres.Types.Table
, Hasura.Backends.Postgres.Types.CitusExtraTableMetadata
, Hasura.Backends.MSSQL.Connection
, Hasura.Backends.MSSQL.DDL
, Hasura.Backends.MSSQL.DDL.BoolExp
, Hasura.Backends.MSSQL.DDL.RunSQL
, Hasura.Backends.MSSQL.DDL.Source
, Hasura.Backends.MSSQL.FromIr
, Hasura.Backends.MSSQL.Instances.Execute
, Hasura.Backends.MSSQL.Instances.Metadata
, Hasura.Backends.MSSQL.Instances.Schema
, Hasura.Backends.MSSQL.Instances.Transport
, Hasura.Backends.MSSQL.Instances.Types
, Hasura.Backends.MSSQL.Meta
, Hasura.Backends.MSSQL.Plan
, Hasura.Backends.MSSQL.SQL.Value
, Hasura.Backends.MSSQL.ToQuery
, Hasura.Backends.MSSQL.Types
, Hasura.Backends.MSSQL.Types.Instances
, Hasura.Backends.MSSQL.Types.Internal
-- Exposed for benchmark:
, Hasura.Cache.Bounded
, Hasura.Logging
@ -395,9 +397,11 @@ library
, Hasura.Server.Auth
, Hasura.Server.Init
, Hasura.Server.Init.Config
, Hasura.Server.API.Backend
, Hasura.Server.API.Instances
, Hasura.Server.API.Metadata
, Hasura.Server.API.Query
, Hasura.Server.API.V2Query
, Hasura.Server.API.Metadata
, Hasura.Server.Utils
, Hasura.Server.Version
, Hasura.Server.Version.TH

View File

@ -0,0 +1,17 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Hasura.Backends.BigQuery.Instances.API where
import Hasura.Prelude
import Hasura.SQL.Backend
import Hasura.Server.API.Backend
instance BackendAPI 'BigQuery where
metadataV1CommandParsers = concat
[ sourceCommands @'BigQuery
, tableCommands @'BigQuery
, tablePermissionsCommands @'BigQuery
, relationshipCommands @'BigQuery
]

View File

@ -0,0 +1,17 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Hasura.Backends.MSSQL.Instances.API where
import Hasura.Prelude
import Hasura.SQL.Backend
import Hasura.Server.API.Backend
instance BackendAPI 'MSSQL where
metadataV1CommandParsers = concat
[ sourceCommands @'MSSQL
, tableCommands @'MSSQL
, tablePermissionsCommands @'MSSQL
, relationshipCommands @'MSSQL
]

View File

@ -0,0 +1,43 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Hasura.Backends.Postgres.Instances.API where
import Hasura.Prelude
import Hasura.SQL.Backend
import Hasura.Server.API.Backend
import {-# SOURCE #-} Hasura.Server.API.Metadata
instance BackendAPI ('Postgres 'Vanilla) where
metadataV1CommandParsers = concat
[ sourceCommands @('Postgres 'Vanilla)
, tableCommands @('Postgres 'Vanilla)
, tablePermissionsCommands @('Postgres 'Vanilla)
, functionCommands @('Postgres 'Vanilla)
, functionPermissionsCommands @('Postgres 'Vanilla)
, relationshipCommands @('Postgres 'Vanilla)
, remoteRelationshipCommands @('Postgres 'Vanilla)
-- postgres specific
, [ commandParser "set_table_is_enum" RMPgSetTableIsEnum
, commandParser "add_computed_field" RMAddComputedField
, commandParser "drop_computed_field" RMDropComputedField
, commandParser "create_event_trigger" RMPgCreateEventTrigger
, commandParser "delete_event_trigger" RMPgDeleteEventTrigger
, commandParser "redeliver_event" RMPgRedeliverEvent
, commandParser "invoke_event_trigger" RMPgInvokeEventTrigger
]
]
instance BackendAPI ('Postgres 'Citus) where
metadataV1CommandParsers = concat
[ sourceCommands @('Postgres 'Citus)
, tableCommands @('Postgres 'Citus)
, tablePermissionsCommands @('Postgres 'Citus)
, functionCommands @('Postgres 'Citus)
, functionPermissionsCommands @('Postgres 'Citus)
, relationshipCommands @('Postgres 'Citus)
, remoteRelationshipCommands @('Postgres 'Citus)
]

View File

@ -191,11 +191,13 @@ instance (Backend b) => FromJSON (ArrRelUsingFKeyOn b) where
type ArrRelUsing b = RelUsing b (ArrRelUsingFKeyOn b)
type ArrRelDef b = RelDef (ArrRelUsing b)
type CreateArrRel b = WithTable b (ArrRelDef b)
newtype CreateArrRel b = CreateArrRel { unCreateArrRel :: WithTable b (ArrRelDef b) }
deriving newtype (Eq, ToJSON, FromJSON)
type ObjRelUsing b = RelUsing b (ObjRelUsingChoice b)
type ObjRelDef b = RelDef (ObjRelUsing b)
type CreateObjRel b = WithTable b (ObjRelDef b)
newtype CreateObjRel b = CreateObjRel { unCreateObjRel :: WithTable b (ObjRelDef b) }
deriving newtype (Eq, ToJSON, FromJSON)
data DropRel b
= DropRel

View File

@ -3,6 +3,7 @@
module Hasura.SQL.AnyBackend
( AnyBackend
, liftTag
, mkAnyBackend
, mapBackend
, traverseBackend
@ -142,6 +143,25 @@ type SatisfiesForAllBackends
--------------------------------------------------------------------------------
-- Functions on AnyBackend
-- | How to obtain a tag from a runtime value. This function is generated with
-- Template Haskell for each 'Backend'. The case switch looks like this:
--
-- Postgres -> PostgresValue PostgresTag
-- MSSQL -> MSSQLValue MSSQLTag
-- ...
liftTag :: BackendType -> AnyBackend BackendTag
liftTag t = $(backendCase
-- the expression on which we do the case switch
[| t |]
-- the pattern for a given backend: the backend type itself
(\(con :| args) -> pure $ ConP con [ConP a [] | a <- args])
-- the body for a given backend: creating and wrapping the tag
(\b -> [| $(pure $ ConE $ getBackendValueName b) $(pure $ ConE $ getBackendTagName b) |])
-- no default case: every constructor should be handled
Nothing
)
-- | Transforms an `AnyBackend i` into an `AnyBackend j`.
mapBackend
:: forall
@ -215,7 +235,7 @@ mkAnyBackend
mkAnyBackend =
-- generates a case switch that associates a tag constructor to a value constructor
-- case backendTag @b of
-- FooTag-> FooValue
-- FooTag -> FooValue
-- BarTag -> BarValue
$(backendCase [| backendTag @b |]
-- the pattern for a backend
@ -535,10 +555,7 @@ parseAnyBackendFromJSON backendKind value = do
-- ...
$(backendCase [| backendKind |]
-- the pattern for a given backend
( \b -> do
(con:args) <- pure b
pure $ ConP con [ConP arg [] | arg <- args]
)
( \(con :| args) -> pure $ ConP con [ConP arg [] | arg <- args] )
-- the body for each backend
( \b -> do
let valueCon = pure $ ConE $ getBackendValueName b

View File

@ -1,12 +1,14 @@
module Hasura.SQL.Backend
( PostgresKind(..)
, BackendType(..)
, backendShortName
, supportedBackends
) where
import Hasura.Prelude
import Data.Aeson
import Data.List.Extended (uniques)
import Data.Proxy
import Data.Text (unpack)
import Data.Text.Extended
@ -19,15 +21,14 @@ import Hasura.Incremental
data PostgresKind
= Vanilla
| Citus
deriving (Eq, Ord)
deriving (Show, Eq, Ord)
-- | An enum that represents each backend we support.
-- As we lift values to the type level, we expect this type to have an Enum instance.
data BackendType
= Postgres PostgresKind
| MSSQL
| BigQuery
deriving (Eq, Ord)
deriving (Show, Eq, Ord)
-- | The name of the backend, as we expect it to appear in our metadata and API.
@ -37,12 +38,17 @@ instance ToTxt BackendType where
toTxt MSSQL = "mssql"
toTxt BigQuery = "bigquery"
-- | The FromJSON instance uses this lookup mechanism to avoid having
-- to duplicate and hardcode the backend string.
-- | The FromJSON instance uses this lookup mechanism to avoid having to duplicate and hardcode the
-- backend string. We accept both the short form and the long form of the backend's name.
instance FromJSON BackendType where
parseJSON = withText "backend type" \name ->
lookup name [(toTxt b, b) | b <- supportedBackends]
`onNothing` fail ("got: " <> unpack name <> ", expected one of: " <> unpack (commaSeparated supportedBackends))
parseJSON = withText "backend type" \name -> do
let knownBackends = supportedBackends >>= \b ->
[ (toTxt b, b) -- long form
, (backendShortName b, b) -- short form
]
uniqueBackends = commaSeparated $ fst <$> uniques knownBackends
lookup name knownBackends `onNothing`
fail ("got: " <> unpack name <> ", expected one of: " <> unpack uniqueBackends)
instance ToJSON BackendType where
toJSON = String . toTxt
@ -50,6 +56,13 @@ instance ToJSON BackendType where
instance Cacheable (Proxy (b :: BackendType))
-- | Some generated APIs use a shortened version of the backend's name rather than its full
-- name. This function returns the "short form" of a backend, if any.
backendShortName :: BackendType -> Text
backendShortName = \case
Postgres Vanilla -> "pg"
b -> toTxt b
supportedBackends :: [BackendType]
supportedBackends =
[ Postgres Vanilla

View File

@ -32,7 +32,7 @@ import Language.Haskell.TH
import Hasura.SQL.Backend
type BackendConstructor = [Name]
type BackendConstructor = NonEmpty Name
-- | Inspects the 'BackendType' to produce a list of its constructors in the 'Q' monad. Each
-- constructor is represented as a list of names, to include the arguments, if any.
@ -47,7 +47,7 @@ backendConstructors = do
ConT argName <- pure arg
TyConI (DataD _ _ _ _ argCons _) <- reify argName
pure [argCon | NormalC argCon _ <- argCons]
pure $ map (name :) $ sequenceA argsConstructors
pure $ map (name :|) $ sequenceA argsConstructors
-- | Associates a value in the 'Q' monad to each backend @Name@.
forEachBackend :: (BackendConstructor -> Q a) -> Q [a]

View File

@ -60,6 +60,7 @@ $(concat <$> forEachBackend \b -> do
[d| instance HasTag $promotedName where backendTag = $tagName |]
)
-- | How to convert back from a tag to a runtime value. This function
-- is generated with Template Haskell for each 'Backend'. The case
-- switch looks like this:

View File

@ -0,0 +1,92 @@
{- | BackendAPI
This module defines the 'BackendAPI' class, alongside a few helpers. Its goal is to delegate to
backends the responsibility of creating the parsers for the metadata API. Each backend is expected
to provide a list of 'CommandParser', which in turn is a simple function from command name and
command arguments to a corresponding parser. Command parsers can easily be created using the
'commandParser' function.
Furthermore, for each set of related features, such as table tracking commands, or permission
commands, a helper function is provided, that allows a backend to write its instance by simply
listing the set of features it supports.
-}
module Hasura.Server.API.Backend where
import Hasura.Prelude
import qualified Data.Aeson.Types as J
import Data.Aeson ((<?>))
import Hasura.RQL.Types.Backend
import Hasura.SQL.AnyBackend
import Hasura.SQL.Backend
import {-# SOURCE #-} Hasura.Server.API.Metadata
-- API class
type CommandParser = Text -> J.Value -> J.Parser (Maybe RQLMetadataV1)
class BackendAPI (b :: BackendType) where
metadataV1CommandParsers :: [CommandParser]
-- helpers
commandParser
:: J.FromJSON a
=> Text -- ^ expected command name
-> (a -> RQLMetadataV1) -- ^ corresponding parser
-> CommandParser
commandParser expected constructor provided arguments =
-- We return a Maybe parser here if the command name doesn't match, as Aeson's alternative
-- instance backtracks: if we used 'fail', we would not be able to distinguish between "this is
-- the correct branch, the name matches, but the argument fails to parse, we must fail" and "this
-- is not the command we were expecting here, it is fine to continue with another".
whenMaybe (expected == provided) $ constructor <$> (J.parseJSON arguments <?> J.Key "args")
sourceCommands, tableCommands, tablePermissionsCommands, functionCommands, functionPermissionsCommands, relationshipCommands, remoteRelationshipCommands
:: forall (b :: BackendType). Backend b
=> [CommandParser]
sourceCommands =
[ commandParser "add_source" $ RMAddSource . mkAnyBackend @b
, commandParser "drop_source" $ RMDropSource
, commandParser "set_table_customization" $ RMSetTableCustomization . mkAnyBackend @b
]
tableCommands =
[ commandParser "track_table" $ RMTrackTable . mkAnyBackend @b
, commandParser "untrack_table" $ RMUntrackTable . mkAnyBackend @b
]
tablePermissionsCommands =
[ commandParser "create_insert_permission" $ RMCreateInsertPermission . mkAnyBackend @b
, commandParser "create_select_permission" $ RMCreateSelectPermission . mkAnyBackend @b
, commandParser "create_update_permission" $ RMCreateUpdatePermission . mkAnyBackend @b
, commandParser "create_delete_permission" $ RMCreateDeletePermission . mkAnyBackend @b
, commandParser "drop_insert_permission" $ RMDropInsertPermission . mkAnyBackend @b
, commandParser "drop_select_permission" $ RMDropSelectPermission . mkAnyBackend @b
, commandParser "drop_update_permission" $ RMDropUpdatePermission . mkAnyBackend @b
, commandParser "drop_delete_permission" $ RMDropDeletePermission . mkAnyBackend @b
, commandParser "set_permission_comment" $ RMSetPermissionComment . mkAnyBackend @b
]
functionCommands =
[ commandParser "track_function" $ RMTrackFunction . mkAnyBackend @b
, commandParser "untrack_function" $ RMUntrackFunction . mkAnyBackend @b
]
functionPermissionsCommands =
[ commandParser "create_function_permission" $ RMCreateFunctionPermission . mkAnyBackend @b
, commandParser "drop_function_permission" $ RMDropFunctionPermission . mkAnyBackend @b
]
relationshipCommands =
[ commandParser "create_object_relationship" $ RMCreateObjectRelationship . mkAnyBackend @b
, commandParser "create_array_relationship" $ RMCreateArrayRelationship . mkAnyBackend @b
, commandParser "set_relationship_comment" $ RMSetRelationshipComment . mkAnyBackend @b
, commandParser "rename_relationship" $ RMRenameRelationship . mkAnyBackend @b
, commandParser "drop_relationship" $ RMDropRelationship . mkAnyBackend @b
]
remoteRelationshipCommands =
[ commandParser "create_remote_relationship" $ RMCreateRemoteRelationship . mkAnyBackend @b
, commandParser "update_remote_relationship" $ RMUpdateRemoteRelationship . mkAnyBackend @b
, commandParser "delete_remote_relationship" $ RMDeleteRemoteRelationship
]

View File

@ -0,0 +1,7 @@
{-# OPTIONS_GHC -Wno-dodgy-exports #-}
module Hasura.Server.API.Instances (module B) where
import Hasura.Backends.BigQuery.Instances.API as B ()
import Hasura.Backends.MSSQL.Instances.API as B ()
import Hasura.Backends.Postgres.Instances.API as B ()

View File

@ -1,16 +1,21 @@
-- | The RQL metadata query ('/v1/metadata')
{-# LANGUAGE ViewPatterns #-}
module Hasura.Server.API.Metadata where
import Hasura.Prelude
import qualified Data.Aeson.Types as A
import qualified Data.Environment as Env
import qualified Data.Text as T
import qualified Data.Text.Extended as T
import qualified Network.HTTP.Client.Extended as HTTP
import Control.Monad.Trans.Control (MonadBaseControl)
import Control.Monad.Unique
import Data.Aeson
import Data.Aeson.Casing
import Data.Aeson.TH
import qualified Hasura.Tracing as Tracing
@ -37,6 +42,10 @@ import Hasura.RQL.DDL.Schema
import Hasura.RQL.DDL.Schema.Source
import Hasura.RQL.Types
import Hasura.RQL.Types.Run
import Hasura.SQL.AnyBackend
import Hasura.SQL.Tag
import Hasura.Server.API.Backend
import Hasura.Server.API.Instances ()
import Hasura.Server.Types (InstanceId (..), MaintenanceMode (..))
import Hasura.Server.Utils (APIVersion (..))
import Hasura.Server.Version (HasVersion)
@ -44,215 +53,226 @@ import Hasura.Session
data RQLMetadataV1
= RMPgAddSource !(AddSource ('Postgres 'Vanilla))
| RMPgDropSource !DropSource
-- Sources
= RMAddSource !(AnyBackend AddSource)
| RMDropSource DropSource
| RMRenameSource !RenameSource
| RMPgTrackTable !(TrackTableV2 ('Postgres 'Vanilla))
| RMPgUntrackTable !(UntrackTable ('Postgres 'Vanilla))
| RMPgSetTableIsEnum !SetTableIsEnum
| RMPgSetTableCustomization !(SetTableCustomization ('Postgres 'Vanilla))
-- Tables
| RMTrackTable !(AnyBackend TrackTableV2)
| RMUntrackTable !(AnyBackend UntrackTable)
| RMSetTableCustomization !(AnyBackend SetTableCustomization)
-- Postgres functions
| RMPgTrackFunction !(TrackFunctionV2 ('Postgres 'Vanilla))
| RMPgUntrackFunction !(UnTrackFunction ('Postgres 'Vanilla))
-- Tables (PG-specific)
| RMPgSetTableIsEnum !SetTableIsEnum
-- Postgres function permissions
| RMPgCreateFunctionPermission !(CreateFunctionPermission ('Postgres 'Vanilla))
| RMPgDropFunctionPermission !(DropFunctionPermission ('Postgres 'Vanilla))
-- Tables permissions
| RMCreateInsertPermission !(AnyBackend (CreatePerm InsPerm))
| RMCreateSelectPermission !(AnyBackend (CreatePerm SelPerm))
| RMCreateUpdatePermission !(AnyBackend (CreatePerm UpdPerm))
| RMCreateDeletePermission !(AnyBackend (CreatePerm DelPerm))
| RMDropInsertPermission !(AnyBackend (DropPerm InsPerm))
| RMDropSelectPermission !(AnyBackend (DropPerm SelPerm))
| RMDropUpdatePermission !(AnyBackend (DropPerm UpdPerm))
| RMDropDeletePermission !(AnyBackend (DropPerm DelPerm))
| RMSetPermissionComment !(AnyBackend SetPermComment)
-- Postgres table relationships
| RMPgCreateObjectRelationship !(CreateObjRel ('Postgres 'Vanilla))
| RMPgCreateArrayRelationship !(CreateArrRel ('Postgres 'Vanilla))
| RMPgDropRelationship !(DropRel ('Postgres 'Vanilla))
| RMPgSetRelationshipComment !(SetRelComment ('Postgres 'Vanilla))
| RMPgRenameRelationship !(RenameRel ('Postgres 'Vanilla))
-- Tables relationships
| RMCreateObjectRelationship !(AnyBackend CreateObjRel)
| RMCreateArrayRelationship !(AnyBackend CreateArrRel)
| RMDropRelationship !(AnyBackend DropRel)
| RMSetRelationshipComment !(AnyBackend SetRelComment)
| RMRenameRelationship !(AnyBackend RenameRel)
-- Postgres computed fields
| RMPgAddComputedField !(AddComputedField ('Postgres 'Vanilla))
| RMPgDropComputedField !(DropComputedField ('Postgres 'Vanilla))
-- Tables remote relationships
| RMCreateRemoteRelationship !(AnyBackend RemoteRelationship)
| RMUpdateRemoteRelationship !(AnyBackend RemoteRelationship)
| RMDeleteRemoteRelationship !(DeleteRemoteRelationship ('Postgres 'Vanilla))
-- Postgres tables remote relationships
| RMPgCreateRemoteRelationship !(RemoteRelationship ('Postgres 'Vanilla))
| RMPgUpdateRemoteRelationship !(RemoteRelationship ('Postgres 'Vanilla))
| RMPgDeleteRemoteRelationship !(DeleteRemoteRelationship ('Postgres 'Vanilla))
-- Functions
| RMTrackFunction !(AnyBackend TrackFunctionV2)
| RMUntrackFunction !(AnyBackend UnTrackFunction)
-- Postgres tables permissions
| RMPgCreateInsertPermission !(CreatePerm InsPerm ('Postgres 'Vanilla))
| RMPgCreateSelectPermission !(CreatePerm SelPerm ('Postgres 'Vanilla))
| RMPgCreateUpdatePermission !(CreatePerm UpdPerm ('Postgres 'Vanilla))
| RMPgCreateDeletePermission !(CreatePerm DelPerm ('Postgres 'Vanilla))
-- Functions permissions
| RMCreateFunctionPermission !(AnyBackend CreateFunctionPermission)
| RMDropFunctionPermission !(AnyBackend DropFunctionPermission)
| RMPgDropInsertPermission !(DropPerm InsPerm ('Postgres 'Vanilla))
| RMPgDropSelectPermission !(DropPerm SelPerm ('Postgres 'Vanilla))
| RMPgDropUpdatePermission !(DropPerm UpdPerm ('Postgres 'Vanilla))
| RMPgDropDeletePermission !(DropPerm DelPerm ('Postgres 'Vanilla))
| RMPgSetPermissionComment !(SetPermComment ('Postgres 'Vanilla))
-- Computed fields (PG-specific)
| RMAddComputedField !(AddComputedField ('Postgres 'Vanilla))
| RMDropComputedField !(DropComputedField ('Postgres 'Vanilla))
-- Postgres tables event triggers
-- Tables event triggers (PG-specific)
| RMPgCreateEventTrigger !(CreateEventTriggerQuery ('Postgres 'Vanilla))
| RMPgDeleteEventTrigger !(DeleteEventTriggerQuery ('Postgres 'Vanilla))
| RMPgRedeliverEvent !(RedeliverEventQuery ('Postgres 'Vanilla))
| RMPgInvokeEventTrigger !(InvokeEventTriggerQuery ('Postgres 'Vanilla))
-- MSSQL sources
| RMMssqlAddSource !(AddSource 'MSSQL)
| RMMssqlDropSource !DropSource
| RMMssqlTrackTable !(TrackTableV2 'MSSQL)
| RMMssqlUntrackTable !(UntrackTable 'MSSQL)
| RMMssqlSetTableCustomization !(SetTableCustomization 'MSSQL)
| RMMssqlCreateObjectRelationship !(CreateObjRel 'MSSQL)
| RMMssqlCreateArrayRelationship !(CreateArrRel 'MSSQL)
| RMMssqlDropRelationship !(DropRel 'MSSQL)
| RMMssqlSetRelationshipComment !(SetRelComment 'MSSQL)
| RMMssqlRenameRelationship !(RenameRel 'MSSQL)
| RMMssqlCreateInsertPermission !(CreatePerm InsPerm 'MSSQL)
| RMMssqlCreateSelectPermission !(CreatePerm SelPerm 'MSSQL)
| RMMssqlCreateUpdatePermission !(CreatePerm UpdPerm 'MSSQL)
| RMMssqlCreateDeletePermission !(CreatePerm DelPerm 'MSSQL)
| RMMssqlDropInsertPermission !(DropPerm InsPerm 'MSSQL)
| RMMssqlDropSelectPermission !(DropPerm SelPerm 'MSSQL)
| RMMssqlDropUpdatePermission !(DropPerm UpdPerm 'MSSQL)
| RMMssqlDropDeletePermission !(DropPerm DelPerm 'MSSQL)
| RMMssqlSetPermissionComment !(SetPermComment 'MSSQL)
-- Citus functions
| RMCitusTrackFunction !(TrackFunctionV2 ('Postgres 'Citus))
| RMCitusUntrackFunction !(UnTrackFunction ('Postgres 'Citus))
-- Citus function permissions
| RMCitusCreateFunctionPermission !(CreateFunctionPermission ('Postgres 'Citus))
| RMCitusDropFunctionPermission !(DropFunctionPermission ('Postgres 'Citus))
-- Citus sources
| RMCitusAddSource !(AddSource ('Postgres 'Citus))
| RMCitusDropSource !DropSource
| RMCitusTrackTable !(TrackTableV2 ('Postgres 'Citus))
| RMCitusUntrackTable !(UntrackTable ('Postgres 'Citus))
| RMCitusSetTableCustomization !(SetTableCustomization ('Postgres 'Citus))
-- Citus relationship
| RMCitusCreateObjectRelationship !(CreateObjRel ('Postgres 'Citus))
| RMCitusCreateArrayRelationship !(CreateArrRel ('Postgres 'Citus))
| RMCitusDropRelationship !(DropRel ('Postgres 'Citus))
| RMCitusSetRelationshipComment !(SetRelComment ('Postgres 'Citus))
| RMCitusRenameRelationship !(RenameRel ('Postgres 'Citus))
-- Citus permissions
| RMCitusCreateInsertPermission !(CreatePerm InsPerm ('Postgres 'Citus))
| RMCitusCreateSelectPermission !(CreatePerm SelPerm ('Postgres 'Citus))
| RMCitusCreateUpdatePermission !(CreatePerm UpdPerm ('Postgres 'Citus))
| RMCitusCreateDeletePermission !(CreatePerm DelPerm ('Postgres 'Citus))
| RMCitusDropInsertPermission !(DropPerm InsPerm ('Postgres 'Citus))
| RMCitusDropSelectPermission !(DropPerm SelPerm ('Postgres 'Citus))
| RMCitusDropUpdatePermission !(DropPerm UpdPerm ('Postgres 'Citus))
| RMCitusDropDeletePermission !(DropPerm DelPerm ('Postgres 'Citus))
| RMCitusSetPermissionComment !(SetPermComment ('Postgres 'Citus))
-- BigQuery sources
| RMBigqueryAddSource !(AddSource 'BigQuery)
| RMBigqueryDropSource !DropSource
| RMBigqueryTrackTable !(TrackTableV2 'BigQuery)
| RMBigquerySetTableCustomization !(SetTableCustomization 'BigQuery)
| RMBigqueryUntrackTable !(UntrackTable 'BigQuery)
| RMBigqueryCreateObjectRelationship !(CreateObjRel 'BigQuery)
| RMBigqueryCreateArrayRelationship !(CreateArrRel 'BigQuery)
| RMBigqueryDropRelationship !(DropRel 'BigQuery)
| RMBigquerySetRelationshipComment !(SetRelComment 'BigQuery)
| RMBigqueryRenameRelationship !(RenameRel 'BigQuery)
| RMBigqueryCreateInsertPermission !(CreatePerm InsPerm 'BigQuery)
| RMBigqueryCreateSelectPermission !(CreatePerm SelPerm 'BigQuery)
| RMBigqueryCreateUpdatePermission !(CreatePerm UpdPerm 'BigQuery)
| RMBigqueryCreateDeletePermission !(CreatePerm DelPerm 'BigQuery)
| RMBigqueryDropInsertPermission !(DropPerm InsPerm 'BigQuery)
| RMBigqueryDropSelectPermission !(DropPerm SelPerm 'BigQuery)
| RMBigqueryDropUpdatePermission !(DropPerm UpdPerm 'BigQuery)
| RMBigqueryDropDeletePermission !(DropPerm DelPerm 'BigQuery)
| RMBigquerySetPermissionComment !(SetPermComment 'BigQuery)
| RMRenameSource !RenameSource
-- Inconsistent metadata
| RMGetInconsistentMetadata !GetInconsistentMetadata
| RMDropInconsistentMetadata !DropInconsistentMetadata
-- Remote schemas
| RMAddRemoteSchema !AddRemoteSchemaQuery
| RMUpdateRemoteSchema !AddRemoteSchemaQuery
| RMRemoveRemoteSchema !RemoteSchemaNameQuery
| RMReloadRemoteSchema !RemoteSchemaNameQuery
| RMAddRemoteSchema !AddRemoteSchemaQuery
| RMUpdateRemoteSchema !AddRemoteSchemaQuery
| RMRemoveRemoteSchema !RemoteSchemaNameQuery
| RMReloadRemoteSchema !RemoteSchemaNameQuery
| RMIntrospectRemoteSchema !RemoteSchemaNameQuery
-- remote-schema permissions
| RMAddRemoteSchemaPermissions !AddRemoteSchemaPermissions
-- Remote schemas permissions
| RMAddRemoteSchemaPermissions !AddRemoteSchemaPermissions
| RMDropRemoteSchemaPermissions !DropRemoteSchemaPermissions
-- scheduled triggers
| RMCreateCronTrigger !CreateCronTrigger
| RMDeleteCronTrigger !ScheduledTriggerName
-- Scheduled triggers
| RMCreateCronTrigger !CreateCronTrigger
| RMDeleteCronTrigger !ScheduledTriggerName
| RMCreateScheduledEvent !CreateScheduledEvent
| RMDeleteScheduledEvent !DeleteScheduledEvent
| RMGetScheduledEvents !GetScheduledEvents
| RMGetEventInvocations !GetEventInvocations
| RMGetScheduledEvents !GetScheduledEvents
| RMGetEventInvocations !GetEventInvocations
-- query collections, allow list related
| RMCreateQueryCollection !CreateCollection
| RMDropQueryCollection !DropCollection
| RMAddQueryToCollection !AddQueryToCollection
| RMDropQueryFromCollection !DropQueryFromCollection
| RMAddCollectionToAllowlist !CollectionReq
-- Actions
| RMCreateAction !CreateAction
| RMDropAction !DropAction
| RMUpdateAction !UpdateAction
| RMCreateActionPermission !CreateActionPermission
| RMDropActionPermission !DropActionPermission
-- Query collections, allow list related
| RMCreateQueryCollection !CreateCollection
| RMDropQueryCollection !DropCollection
| RMAddQueryToCollection !AddQueryToCollection
| RMDropQueryFromCollection !DropQueryFromCollection
| RMAddCollectionToAllowlist !CollectionReq
| RMDropCollectionFromAllowlist !CollectionReq
-- basic metadata management
| RMReplaceMetadata !ReplaceMetadata
| RMExportMetadata !ExportMetadata
| RMClearMetadata !ClearMetadata
| RMReloadMetadata !ReloadMetadata
-- actions
| RMCreateAction !CreateAction
| RMDropAction !DropAction
| RMUpdateAction !UpdateAction
| RMCreateActionPermission !CreateActionPermission
| RMDropActionPermission !DropActionPermission
-- Rest endpoints
| RMCreateRestEndpoint !CreateEndpoint
| RMDropRestEndpoint !DropEndpoint
| RMDropRestEndpoint !DropEndpoint
-- Custom types
| RMSetCustomTypes !CustomTypes
| RMDumpInternalState !DumpInternalState
| RMGetCatalogState !GetCatalogState
| RMSetCatalogState !SetCatalogState
-- 'ApiLimit' related
-- Api limits
| RMSetApiLimits !ApiLimit
| RMRemoveApiLimits
-- 'MetricsConfig' related
-- Metrics config
| RMSetMetricsConfig !MetricsConfig
| RMRemoveMetricsConfig
-- inherited roles
| RMAddInheritedRole !AddInheritedRole
-- Inherited roles
| RMAddInheritedRole !AddInheritedRole
| RMDropInheritedRole !DropInheritedRole
-- Metadata management
| RMReplaceMetadata !ReplaceMetadata
| RMExportMetadata !ExportMetadata
| RMClearMetadata !ClearMetadata
| RMReloadMetadata !ReloadMetadata
| RMGetInconsistentMetadata !GetInconsistentMetadata
| RMDropInconsistentMetadata !DropInconsistentMetadata
-- Introspection options
| RMSetGraphqlSchemaIntrospectionOptions !SetGraphqlIntrospectionOptions
-- bulk metadata queries
-- Debug
| RMDumpInternalState !DumpInternalState
| RMGetCatalogState !GetCatalogState
| RMSetCatalogState !SetCatalogState
-- Bulk metadata queries
| RMBulk [RQLMetadataRequest]
deriving (Eq)
instance FromJSON RQLMetadataV1 where
parseJSON = withObject "RQLMetadataV1" \o -> do
queryType <- o .: "type"
let
args :: forall a. FromJSON a => A.Parser a
args = o .: "args"
case queryType of
-- backend agnostic
"rename_source" -> RMRenameSource <$> args
"add_remote_schema" -> RMAddRemoteSchema <$> args
"update_remote_schema" -> RMUpdateRemoteSchema <$> args
"remove_remote_schema" -> RMRemoveRemoteSchema <$> args
"reload_remote_schema" -> RMReloadRemoteSchema <$> args
"introspect_remote_schema" -> RMIntrospectRemoteSchema <$> args
"add_remote_schema_permissions" -> RMAddRemoteSchemaPermissions <$> args
"drop_remote_schema_permissions" -> RMDropRemoteSchemaPermissions <$> args
"create_cron_trigger" -> RMCreateCronTrigger <$> args
"delete_cron_trigger" -> RMDeleteCronTrigger <$> args
"create_scheduled_event" -> RMCreateScheduledEvent <$> args
"delete_scheduled_event" -> RMDeleteScheduledEvent <$> args
"get_scheduled_events" -> RMGetScheduledEvents <$> args
"get_event_invocations" -> RMGetEventInvocations <$> args
"create_action" -> RMCreateAction <$> args
"drop_action" -> RMDropAction <$> args
"update_action" -> RMUpdateAction <$> args
"create_action_permission" -> RMCreateActionPermission <$> args
"drop_action_permission" -> RMDropActionPermission <$> args
"create_query_collection" -> RMCreateQueryCollection <$> args
"drop_query_collection" -> RMDropQueryCollection <$> args
"add_query_to_collection" -> RMAddQueryToCollection <$> args
"drop_query_from_collection" -> RMDropQueryFromCollection <$> args
"add_collection_to_allowlist" -> RMAddCollectionToAllowlist <$> args
"drop_collection_from_allowlist" -> RMDropCollectionFromAllowlist <$> args
"create_rest_endpoint" -> RMCreateRestEndpoint <$> args
"drop_rest_endpoint" -> RMDropRestEndpoint <$> args
"set_custom_types" -> RMSetCustomTypes <$> args
"set_api_limits" -> RMSetApiLimits <$> args
"remove_api_limits" -> pure RMRemoveApiLimits
"set_metrics_config" -> RMSetMetricsConfig <$> args
"remove_metrics_config" -> pure RMRemoveMetricsConfig
"add_inherited_role" -> RMAddInheritedRole <$> args
"drop_inherited_role" -> RMDropInheritedRole <$> args
"replace_metadata" -> RMReplaceMetadata <$> args
"export_metadata" -> RMExportMetadata <$> args
"clear_metadata" -> RMClearMetadata <$> args
"reload_metadata" -> RMReloadMetadata <$> args
"get_inconsistent_metadata" -> RMGetInconsistentMetadata <$> args
"drop_inconsistent_metadata" -> RMDropInconsistentMetadata <$> args
"dump_internal_state" -> RMDumpInternalState <$> args
"get_catalog_state" -> RMGetCatalogState <$> args
"set_catalog_state" -> RMSetCatalogState <$> args
"set_graphql_schema_introspection_options" -> RMSetGraphqlSchemaIntrospectionOptions <$> args
"bulk" -> RMBulk <$> args
-- backend specific
_ -> do
let (prefix, T.drop 1 -> cmd) = T.breakOn "_" queryType
backendType <- runAesonParser parseJSON (String prefix)
`onLeft` \_ -> fail (
"unknown metadata command \"" <> T.unpack queryType <>
"\"; \"" <> T.unpack prefix <> "\" was not recognized as a valid backend name"
)
dispatchAnyBackend @BackendAPI (liftTag backendType) \(_ :: BackendTag b) -> do
argValue <- args
command <- choice <$> sequenceA [p cmd argValue | p <- metadataV1CommandParsers @b]
onNothing command $ fail $
"unknown metadata command \"" <> T.unpack cmd <>
"\" for backend " <> T.unpack (T.toTxt backendType)
data RQLMetadataV2
= RMV2ReplaceMetadata !ReplaceMetadataV2
| RMV2ExportMetadata !ExportMetadata
deriving (Eq)
| RMV2ExportMetadata !ExportMetadata
deriving (Eq, Generic)
instance FromJSON RQLMetadataV2 where
parseJSON = genericParseJSON $
defaultOptions { constructorTagModifier = snakeCase . drop 4
, sumEncoding = TaggedObject "type" "args"
}
data RQLMetadataRequest
= RMV1 !RQLMetadataV1
@ -267,15 +287,6 @@ instance FromJSON RQLMetadataRequest where
VIVersion1 -> RMV1 <$> parseJSON val
VIVersion2 -> RMV2 <$> parseJSON val
instance ToJSON RQLMetadataRequest where
toJSON = \case
RMV1 q -> embedVersion VIVersion1 $ toJSON q
RMV2 q -> embedVersion VIVersion2 $ toJSON q
where
embedVersion version (Object o) =
Object $ o <> "version" .= version
-- never happens since JSON value of RQL queries are always objects
embedVersion _ _ = error "Unexpected: toJSON of RQLMetadtaV is not an object"
data RQLMetadata
= RQLMetadata
@ -289,26 +300,6 @@ instance FromJSON RQLMetadata where
_rqlMetadata <- parseJSON $ Object o
pure RQLMetadata{..}
instance ToJSON RQLMetadata where
toJSON RQLMetadata{..} =
embedResourceVersion $ toJSON _rqlMetadata
where
embedResourceVersion (Object o) =
Object $ o <> "resource_version" .= _rqlMetadataResourceVersion
-- never happens since JSON value of RQL queries are always objects
embedResourceVersion _ = error "Unexpected: toJSON of RQLMetadata is not an object"
$(deriveJSON
defaultOptions { constructorTagModifier = snakeCase . drop 2
, sumEncoding = TaggedObject "type" "args"
}
''RQLMetadataV1)
$(deriveJSON
defaultOptions { constructorTagModifier = snakeCase . drop 4
, sumEncoding = TaggedObject "type" "args"
}
''RQLMetadataV2)
runMetadataQuery
:: ( HasVersion
@ -400,7 +391,8 @@ runMetadataQueryM env currentResourceVersion = withPathK "args" . \case
RMV2 q -> runMetadataQueryV2M currentResourceVersion q
runMetadataQueryV1M
:: ( HasVersion
:: forall m
. ( HasVersion
, MonadIO m
, MonadBaseControl IO m
, CacheRWM m
@ -417,184 +409,114 @@ runMetadataQueryV1M
-> RQLMetadataV1
-> m EncJSON
runMetadataQueryV1M env currentResourceVersion = \case
RMPgAddSource q -> runAddSource q
RMRenameSource q -> runRenameSource q
RMPgDropSource q -> runDropSource q
RMAddSource q -> dispatch runAddSource q
RMDropSource q -> runDropSource q
RMRenameSource q -> runRenameSource q
RMPgTrackTable q -> runTrackTableV2Q q
RMPgUntrackTable q -> runUntrackTableQ q
RMPgSetTableIsEnum q -> runSetExistingTableIsEnumQ q
RMPgSetTableCustomization q -> runSetTableCustomization q
RMTrackTable q -> dispatch runTrackTableV2Q q
RMUntrackTable q -> dispatch runUntrackTableQ q
RMSetTableCustomization q -> dispatch runSetTableCustomization q
RMPgTrackFunction q -> runTrackFunctionV2 q
RMPgUntrackFunction q -> runUntrackFunc q
RMPgSetTableIsEnum q -> runSetExistingTableIsEnumQ q
RMPgCreateFunctionPermission q -> runCreateFunctionPermission q
RMPgDropFunctionPermission q -> runDropFunctionPermission q
RMCreateInsertPermission q -> dispatch runCreatePerm q
RMCreateSelectPermission q -> dispatch runCreatePerm q
RMCreateUpdatePermission q -> dispatch runCreatePerm q
RMCreateDeletePermission q -> dispatch runCreatePerm q
RMDropInsertPermission q -> dispatch runDropPerm q
RMDropSelectPermission q -> dispatch runDropPerm q
RMDropUpdatePermission q -> dispatch runDropPerm q
RMDropDeletePermission q -> dispatch runDropPerm q
RMSetPermissionComment q -> dispatch runSetPermComment q
RMPgCreateObjectRelationship q -> runCreateRelationship ObjRel q
RMPgCreateArrayRelationship q -> runCreateRelationship ArrRel q
RMPgDropRelationship q -> runDropRel q
RMPgSetRelationshipComment q -> runSetRelComment q
RMPgRenameRelationship q -> runRenameRel q
RMCreateObjectRelationship q -> dispatch (runCreateRelationship ObjRel . unCreateObjRel) q
RMCreateArrayRelationship q -> dispatch (runCreateRelationship ArrRel . unCreateArrRel) q
RMDropRelationship q -> dispatch runDropRel q
RMSetRelationshipComment q -> dispatch runSetRelComment q
RMRenameRelationship q -> dispatch runRenameRel q
RMPgAddComputedField q -> runAddComputedField q
RMPgDropComputedField q -> runDropComputedField q
RMCreateRemoteRelationship q -> dispatch runCreateRemoteRelationship q
RMUpdateRemoteRelationship q -> dispatch runUpdateRemoteRelationship q
RMDeleteRemoteRelationship q -> runDeleteRemoteRelationship q
RMPgCreateRemoteRelationship q -> runCreateRemoteRelationship q
RMPgUpdateRemoteRelationship q -> runUpdateRemoteRelationship q
RMPgDeleteRemoteRelationship q -> runDeleteRemoteRelationship q
RMTrackFunction q -> dispatch runTrackFunctionV2 q
RMUntrackFunction q -> dispatch runUntrackFunc q
RMPgCreateInsertPermission q -> runCreatePerm q
RMPgCreateSelectPermission q -> runCreatePerm q
RMPgCreateUpdatePermission q -> runCreatePerm q
RMPgCreateDeletePermission q -> runCreatePerm q
RMCreateFunctionPermission q -> dispatch runCreateFunctionPermission q
RMDropFunctionPermission q -> dispatch runDropFunctionPermission q
RMPgDropInsertPermission q -> runDropPerm q
RMPgDropSelectPermission q -> runDropPerm q
RMPgDropUpdatePermission q -> runDropPerm q
RMPgDropDeletePermission q -> runDropPerm q
RMPgSetPermissionComment q -> runSetPermComment q
RMAddComputedField q -> runAddComputedField q
RMDropComputedField q -> runDropComputedField q
RMPgCreateEventTrigger q -> runCreateEventTriggerQuery q
RMPgDeleteEventTrigger q -> runDeleteEventTriggerQuery q
RMPgRedeliverEvent q -> runRedeliverEvent q
RMPgInvokeEventTrigger q -> runInvokeEventTrigger q
RMPgCreateEventTrigger q -> runCreateEventTriggerQuery q
RMPgDeleteEventTrigger q -> runDeleteEventTriggerQuery q
RMPgRedeliverEvent q -> runRedeliverEvent q
RMPgInvokeEventTrigger q -> runInvokeEventTrigger q
RMBigqueryAddSource q -> runAddSource q
RMBigqueryDropSource q -> runDropSource q
RMBigqueryTrackTable q -> runTrackTableV2Q q
RMBigqueryUntrackTable q -> runUntrackTableQ q
RMBigquerySetTableCustomization q -> runSetTableCustomization q
RMAddRemoteSchema q -> runAddRemoteSchema env q
RMUpdateRemoteSchema q -> runUpdateRemoteSchema env q
RMRemoveRemoteSchema q -> runRemoveRemoteSchema q
RMReloadRemoteSchema q -> runReloadRemoteSchema q
RMIntrospectRemoteSchema q -> runIntrospectRemoteSchema q
RMBigqueryCreateObjectRelationship q -> runCreateRelationship ObjRel q
RMBigqueryCreateArrayRelationship q -> runCreateRelationship ArrRel q
RMBigqueryDropRelationship q -> runDropRel q
RMBigquerySetRelationshipComment q -> runSetRelComment q
RMBigqueryRenameRelationship q -> runRenameRel q
RMAddRemoteSchemaPermissions q -> runAddRemoteSchemaPermissions q
RMDropRemoteSchemaPermissions q -> runDropRemoteSchemaPermissions q
RMBigqueryCreateInsertPermission q -> runCreatePerm q
RMBigqueryCreateSelectPermission q -> runCreatePerm q
RMBigqueryCreateUpdatePermission q -> runCreatePerm q
RMBigqueryCreateDeletePermission q -> runCreatePerm q
RMCreateCronTrigger q -> runCreateCronTrigger q
RMDeleteCronTrigger q -> runDeleteCronTrigger q
RMCreateScheduledEvent q -> runCreateScheduledEvent q
RMDeleteScheduledEvent q -> runDeleteScheduledEvent q
RMGetScheduledEvents q -> runGetScheduledEvents q
RMGetEventInvocations q -> runGetEventInvocations q
RMBigqueryDropInsertPermission q -> runDropPerm q
RMBigqueryDropSelectPermission q -> runDropPerm q
RMBigqueryDropUpdatePermission q -> runDropPerm q
RMBigqueryDropDeletePermission q -> runDropPerm q
RMBigquerySetPermissionComment q -> runSetPermComment q
RMCreateAction q -> runCreateAction q
RMDropAction q -> runDropAction q
RMUpdateAction q -> runUpdateAction q
RMCreateActionPermission q -> runCreateActionPermission q
RMDropActionPermission q -> runDropActionPermission q
RMMssqlAddSource q -> runAddSource q
RMMssqlDropSource q -> runDropSource q
RMMssqlTrackTable q -> runTrackTableV2Q q
RMMssqlUntrackTable q -> runUntrackTableQ q
RMMssqlSetTableCustomization q -> runSetTableCustomization q
RMCreateQueryCollection q -> runCreateCollection q
RMDropQueryCollection q -> runDropCollection q
RMAddQueryToCollection q -> runAddQueryToCollection q
RMDropQueryFromCollection q -> runDropQueryFromCollection q
RMAddCollectionToAllowlist q -> runAddCollectionToAllowlist q
RMDropCollectionFromAllowlist q -> runDropCollectionFromAllowlist q
RMMssqlCreateObjectRelationship q -> runCreateRelationship ObjRel q
RMMssqlCreateArrayRelationship q -> runCreateRelationship ArrRel q
RMMssqlDropRelationship q -> runDropRel q
RMMssqlSetRelationshipComment q -> runSetRelComment q
RMMssqlRenameRelationship q -> runRenameRel q
RMCreateRestEndpoint q -> runCreateEndpoint q
RMDropRestEndpoint q -> runDropEndpoint q
RMMssqlCreateInsertPermission q -> runCreatePerm q
RMMssqlCreateSelectPermission q -> runCreatePerm q
RMMssqlCreateUpdatePermission q -> runCreatePerm q
RMMssqlCreateDeletePermission q -> runCreatePerm q
RMSetCustomTypes q -> runSetCustomTypes q
RMMssqlDropInsertPermission q -> runDropPerm q
RMMssqlDropSelectPermission q -> runDropPerm q
RMMssqlDropUpdatePermission q -> runDropPerm q
RMMssqlDropDeletePermission q -> runDropPerm q
RMMssqlSetPermissionComment q -> runSetPermComment q
RMSetApiLimits q -> runSetApiLimits q
RMRemoveApiLimits -> runRemoveApiLimits
RMCitusAddSource q -> runAddSource q
RMCitusDropSource q -> runDropSource q
RMCitusTrackTable q -> runTrackTableV2Q q
RMCitusUntrackTable q -> runUntrackTableQ q
RMCitusSetTableCustomization q -> runSetTableCustomization q
RMSetMetricsConfig q -> runSetMetricsConfig q
RMRemoveMetricsConfig -> runRemoveMetricsConfig
RMCitusTrackFunction q -> runTrackFunctionV2 q
RMCitusUntrackFunction q -> runUntrackFunc q
RMAddInheritedRole q -> runAddInheritedRole q
RMDropInheritedRole q -> runDropInheritedRole q
RMCitusCreateFunctionPermission q -> runCreateFunctionPermission q
RMCitusDropFunctionPermission q -> runDropFunctionPermission q
RMCitusCreateObjectRelationship q -> runCreateRelationship ObjRel q
RMCitusCreateArrayRelationship q -> runCreateRelationship ArrRel q
RMCitusDropRelationship q -> runDropRel q
RMCitusSetRelationshipComment q -> runSetRelComment q
RMCitusRenameRelationship q -> runRenameRel q
RMCitusCreateInsertPermission q -> runCreatePerm q
RMCitusCreateSelectPermission q -> runCreatePerm q
RMCitusCreateUpdatePermission q -> runCreatePerm q
RMCitusCreateDeletePermission q -> runCreatePerm q
RMCitusDropInsertPermission q -> runDropPerm q
RMCitusDropSelectPermission q -> runDropPerm q
RMCitusDropUpdatePermission q -> runDropPerm q
RMCitusDropDeletePermission q -> runDropPerm q
RMCitusSetPermissionComment q -> runSetPermComment q
RMGetInconsistentMetadata q -> runGetInconsistentMetadata q
RMDropInconsistentMetadata q -> runDropInconsistentMetadata q
RMAddRemoteSchema q -> runAddRemoteSchema env q
RMUpdateRemoteSchema q -> runUpdateRemoteSchema env q
RMRemoveRemoteSchema q -> runRemoveRemoteSchema q
RMReloadRemoteSchema q -> runReloadRemoteSchema q
RMIntrospectRemoteSchema q -> runIntrospectRemoteSchema q
RMAddRemoteSchemaPermissions q -> runAddRemoteSchemaPermissions q
RMDropRemoteSchemaPermissions q -> runDropRemoteSchemaPermissions q
RMCreateCronTrigger q -> runCreateCronTrigger q
RMDeleteCronTrigger q -> runDeleteCronTrigger q
RMCreateScheduledEvent q -> runCreateScheduledEvent q
RMDeleteScheduledEvent q -> runDeleteScheduledEvent q
RMGetScheduledEvents q -> runGetScheduledEvents q
RMGetEventInvocations q -> runGetEventInvocations q
RMCreateQueryCollection q -> runCreateCollection q
RMDropQueryCollection q -> runDropCollection q
RMAddQueryToCollection q -> runAddQueryToCollection q
RMDropQueryFromCollection q -> runDropQueryFromCollection q
RMAddCollectionToAllowlist q -> runAddCollectionToAllowlist q
RMDropCollectionFromAllowlist q -> runDropCollectionFromAllowlist q
RMReplaceMetadata q -> runReplaceMetadata q
RMExportMetadata q -> runExportMetadata q
RMClearMetadata q -> runClearMetadata q
RMReloadMetadata q -> runReloadMetadata q
RMCreateAction q -> runCreateAction q
RMDropAction q -> runDropAction q
RMUpdateAction q -> runUpdateAction q
RMCreateActionPermission q -> runCreateActionPermission q
RMDropActionPermission q -> runDropActionPermission q
RMCreateRestEndpoint q -> runCreateEndpoint q
RMDropRestEndpoint q -> runDropEndpoint q
RMSetCustomTypes q -> runSetCustomTypes q
RMDumpInternalState q -> runDumpInternalState q
RMGetCatalogState q -> runGetCatalogState q
RMSetCatalogState q -> runSetCatalogState q
RMSetApiLimits q -> runSetApiLimits q
RMRemoveApiLimits -> runRemoveApiLimits
RMSetMetricsConfig q -> runSetMetricsConfig q
RMRemoveMetricsConfig -> runRemoveMetricsConfig
RMAddInheritedRole q -> runAddInheritedRole q
RMDropInheritedRole q -> runDropInheritedRole q
RMReplaceMetadata q -> runReplaceMetadata q
RMExportMetadata q -> runExportMetadata q
RMClearMetadata q -> runClearMetadata q
RMReloadMetadata q -> runReloadMetadata q
RMGetInconsistentMetadata q -> runGetInconsistentMetadata q
RMDropInconsistentMetadata q -> runDropInconsistentMetadata q
RMSetGraphqlSchemaIntrospectionOptions q -> runSetGraphqlSchemaIntrospectionOptions q
RMDumpInternalState q -> runDumpInternalState q
RMGetCatalogState q -> runGetCatalogState q
RMSetCatalogState q -> runSetCatalogState q
RMBulk q -> encJFromList <$> indexedMapM (runMetadataQueryM env currentResourceVersion) q
where
dispatch
:: (forall b. BackendMetadata b => i b -> a)
-> AnyBackend i
-> a
dispatch f x = dispatchAnyBackend @BackendMetadata x f
runMetadataQueryV2M
:: ( MonadIO m

View File

@ -0,0 +1,149 @@
module Hasura.Server.API.Metadata where
import Hasura.RQL.DDL.Action
import Hasura.RQL.DDL.ComputedField
import Hasura.RQL.DDL.EventTrigger
import Hasura.RQL.DDL.Metadata
import Hasura.RQL.DDL.Permission
import Hasura.RQL.DDL.QueryCollection
import Hasura.RQL.DDL.Schema
import Hasura.RQL.Types
import Hasura.SQL.AnyBackend
data RQLMetadataV1
-- Sources
= RMAddSource !(AnyBackend AddSource)
| RMDropSource DropSource
| RMRenameSource !RenameSource
-- Tables
| RMTrackTable !(AnyBackend TrackTableV2)
| RMUntrackTable !(AnyBackend UntrackTable)
| RMSetTableCustomization !(AnyBackend SetTableCustomization)
-- Tables (PG-specific)
| RMPgSetTableIsEnum !SetTableIsEnum
-- Tables permissions
| RMCreateInsertPermission !(AnyBackend (CreatePerm InsPerm))
| RMCreateSelectPermission !(AnyBackend (CreatePerm SelPerm))
| RMCreateUpdatePermission !(AnyBackend (CreatePerm UpdPerm))
| RMCreateDeletePermission !(AnyBackend (CreatePerm DelPerm))
| RMDropInsertPermission !(AnyBackend (DropPerm InsPerm))
| RMDropSelectPermission !(AnyBackend (DropPerm SelPerm))
| RMDropUpdatePermission !(AnyBackend (DropPerm UpdPerm))
| RMDropDeletePermission !(AnyBackend (DropPerm DelPerm))
| RMSetPermissionComment !(AnyBackend SetPermComment)
-- Tables relationships
| RMCreateObjectRelationship !(AnyBackend CreateObjRel)
| RMCreateArrayRelationship !(AnyBackend CreateArrRel)
| RMDropRelationship !(AnyBackend DropRel)
| RMSetRelationshipComment !(AnyBackend SetRelComment)
| RMRenameRelationship !(AnyBackend RenameRel)
-- Tables remote relationships
| RMCreateRemoteRelationship !(AnyBackend RemoteRelationship)
| RMUpdateRemoteRelationship !(AnyBackend RemoteRelationship)
| RMDeleteRemoteRelationship !(DeleteRemoteRelationship ('Postgres 'Vanilla))
-- Functions
| RMTrackFunction !(AnyBackend TrackFunctionV2)
| RMUntrackFunction !(AnyBackend UnTrackFunction)
-- Functions permissions
| RMCreateFunctionPermission !(AnyBackend CreateFunctionPermission)
| RMDropFunctionPermission !(AnyBackend DropFunctionPermission)
-- Computed fields (PG-specific)
| RMAddComputedField !(AddComputedField ('Postgres 'Vanilla))
| RMDropComputedField !(DropComputedField ('Postgres 'Vanilla))
-- Tables event triggers (PG-specific)
| RMPgCreateEventTrigger !(CreateEventTriggerQuery ('Postgres 'Vanilla))
| RMPgDeleteEventTrigger !(DeleteEventTriggerQuery ('Postgres 'Vanilla))
| RMPgRedeliverEvent !(RedeliverEventQuery ('Postgres 'Vanilla))
| RMPgInvokeEventTrigger !(InvokeEventTriggerQuery ('Postgres 'Vanilla))
-- Remote schemas
| RMAddRemoteSchema !AddRemoteSchemaQuery
| RMUpdateRemoteSchema !AddRemoteSchemaQuery
| RMRemoveRemoteSchema !RemoteSchemaNameQuery
| RMReloadRemoteSchema !RemoteSchemaNameQuery
| RMIntrospectRemoteSchema !RemoteSchemaNameQuery
-- Remote schemas permissions
| RMAddRemoteSchemaPermissions !AddRemoteSchemaPermissions
| RMDropRemoteSchemaPermissions !DropRemoteSchemaPermissions
-- Scheduled triggers
| RMCreateCronTrigger !CreateCronTrigger
| RMDeleteCronTrigger !ScheduledTriggerName
| RMCreateScheduledEvent !CreateScheduledEvent
| RMDeleteScheduledEvent !DeleteScheduledEvent
| RMGetScheduledEvents !GetScheduledEvents
| RMGetEventInvocations !GetEventInvocations
-- Actions
| RMCreateAction !CreateAction
| RMDropAction !DropAction
| RMUpdateAction !UpdateAction
| RMCreateActionPermission !CreateActionPermission
| RMDropActionPermission !DropActionPermission
-- Query collections, allow list related
| RMCreateQueryCollection !CreateCollection
| RMDropQueryCollection !DropCollection
| RMAddQueryToCollection !AddQueryToCollection
| RMDropQueryFromCollection !DropQueryFromCollection
| RMAddCollectionToAllowlist !CollectionReq
| RMDropCollectionFromAllowlist !CollectionReq
-- Rest endpoints
| RMCreateRestEndpoint !CreateEndpoint
| RMDropRestEndpoint !DropEndpoint
-- Custom types
| RMSetCustomTypes !CustomTypes
-- Api limits
| RMSetApiLimits !ApiLimit
| RMRemoveApiLimits
-- Metrics config
| RMSetMetricsConfig !MetricsConfig
| RMRemoveMetricsConfig
-- Inherited roles
| RMAddInheritedRole !AddInheritedRole
| RMDropInheritedRole !DropInheritedRole
-- Metadata management
| RMReplaceMetadata !ReplaceMetadata
| RMExportMetadata !ExportMetadata
| RMClearMetadata !ClearMetadata
| RMReloadMetadata !ReloadMetadata
| RMGetInconsistentMetadata !GetInconsistentMetadata
| RMDropInconsistentMetadata !DropInconsistentMetadata
-- Introspection options
| RMSetGraphqlSchemaIntrospectionOptions !SetGraphqlIntrospectionOptions
-- Debug
| RMDumpInternalState !DumpInternalState
| RMGetCatalogState !GetCatalogState
| RMSetCatalogState !SetCatalogState
-- Bulk metadata queries
| RMBulk [RQLMetadataRequest]
data RQLMetadataV2
= RMV2ReplaceMetadata !ReplaceMetadataV2
| RMV2ExportMetadata !ExportMetadata
data RQLMetadataRequest
= RMV1 !RQLMetadataV1
| RMV2 !RQLMetadataV2

View File

@ -6,7 +6,6 @@ module Hasura.Server.API.PGDump
import Control.Exception (IOException, try)
import Data.Aeson
import Data.Aeson.TH
import Data.Char (isSpace)
import Data.Text.Conversions
import Hasura.Prelude
@ -29,8 +28,6 @@ data PGDumpReqBody =
, prbCleanOutput :: !Bool
} deriving (Show, Eq)
$(deriveToJSON hasuraJSON ''PGDumpReqBody)
instance FromJSON PGDumpReqBody where
parseJSON = withObject "Object" $ \o ->
PGDumpReqBody
@ -38,6 +35,7 @@ instance FromJSON PGDumpReqBody where
<*> o .: "opts"
<*> o .:? "clean_output" .!= False
execPGDump
:: (MonadError RTE.QErr m, MonadIO m)
=> PGDumpReqBody

View File

@ -5,7 +5,6 @@ module Hasura.Server.API.Query where
import Hasura.Prelude
import qualified Data.Environment as Env
import qualified Data.HashMap.Strict as HM
import qualified Database.PG.Query as Q
import qualified Network.HTTP.Client as HTTP
@ -163,23 +162,13 @@ instance FromJSON RQLQuery where
VIVersion1 -> RQV1 <$> parseJSON val
VIVersion2 -> RQV2 <$> parseJSON val
instance ToJSON RQLQuery where
toJSON = \case
RQV1 q -> embedVersion VIVersion1 $ toJSON q
RQV2 q -> embedVersion VIVersion2 $ toJSON q
where
embedVersion version (Object o) =
Object $ HM.insert "version" (toJSON version) o
-- never happens since JSON value of RQL queries are always objects
embedVersion _ _ = error "Unexpected: toJSON of RQL queries are not objects"
$(deriveJSON
$(deriveFromJSON
defaultOptions { constructorTagModifier = snakeCase . drop 2
, sumEncoding = TaggedObject "type" "args"
}
''RQLQueryV1)
$(deriveJSON
$(deriveFromJSON
defaultOptions { constructorTagModifier = snakeCase . drop 4
, sumEncoding = TaggedObject "type" "args"
, tagSingleConstructors = True
@ -383,8 +372,8 @@ runQueryM env rq = withPathK "args" $ case rq of
RQTrackFunction q -> runTrackFunc q
RQUntrackFunction q -> runUntrackFunc q
RQCreateObjectRelationship q -> runCreateRelationship ObjRel q
RQCreateArrayRelationship q -> runCreateRelationship ArrRel 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

View File

@ -48,12 +48,13 @@ data RQLQuery
| RQBulk ![RQLQuery]
deriving (Show)
$(deriveJSON
$(deriveFromJSON
defaultOptions { constructorTagModifier = snakeCase . drop 2
, sumEncoding = TaggedObject "type" "args"
}
''RQLQuery)
runQuery
:: ( HasVersion
, MonadIO m