mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-10-04 22:07:40 +03:00
Feat: No feature flags for Native Queries and Stored Procedures
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9541 GitOrigin-RevId: 81a33de3a35405c6e45cb5bad160ad00871745eb
This commit is contained in:
parent
0dea43add9
commit
5d76f9cabf
@ -97,7 +97,6 @@ services:
|
||||
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
|
||||
HASURA_GRAPHQL_EXPERIMENTAL_FEATURES: 'naming_convention'
|
||||
HASURA_GRAPHQL_ADMIN_SECRET: 'moocow'
|
||||
HASURA_FF_NATIVE_QUERY_INTERFACE: 'True'
|
||||
# HASURA_GRAPHQL_EE_LICENSE_KEY: ''
|
||||
data-connector-agent:
|
||||
container_name: 'super-connector'
|
||||
|
@ -1,11 +1,12 @@
|
||||
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
|
||||
|
||||
-- Native Queries is a pro-only feature now, this ensures that this continues
|
||||
-- to be the case
|
||||
-- Native Queries is a pro-only feature now for anything but Postgres.
|
||||
-- This test ensures that this continues to be the case.
|
||||
module Test.Queries.NativeQueriesSpec (spec) where
|
||||
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Backend.Sqlserver qualified as Sqlserver
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Schema qualified as Schema
|
||||
import Harness.Test.BackendType qualified as BackendType
|
||||
@ -16,18 +17,20 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
-- ** Preamble
|
||||
|
||||
featureFlagForNativeQueries :: String
|
||||
featureFlagForNativeQueries = "HASURA_FF_NATIVE_QUERY_INTERFACE"
|
||||
|
||||
spec :: SpecWith GlobalTestEnvironment
|
||||
spec =
|
||||
Fixture.hgeWithEnv [(featureFlagForNativeQueries, "True")]
|
||||
Fixture.hgeWithEnv []
|
||||
$ Fixture.runClean -- re-run fixture setup on every test
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Sqlserver.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Sqlserver.setupTablesAction schema testEnvironment
|
||||
]
|
||||
}
|
||||
]
|
||||
)
|
||||
@ -57,17 +60,22 @@ tests = do
|
||||
(Schema.nativeQuery "hello_world_function" (const query) "hello_world_return_type")
|
||||
|
||||
describe "Testing Native Queries" $ do
|
||||
it "We cannot even set up a Logical Model in OSS" $ \testEnvironment -> do
|
||||
it "We cannot even set up a Logical Model in non-pg OSS" $ \testEnvironment -> do
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ getBackendTypeConfig testEnvironment
|
||||
backendName = BackendType.backendTypeString backendTypeMetadata
|
||||
source = BackendType.backendSourceName backendTypeMetadata
|
||||
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnvironment
|
||||
(Schema.trackLogicalModelCommand source backendTypeMetadata helloWorldLogicalModel)
|
||||
|
||||
-- we expect this to fail
|
||||
-- we expect this to work only on Postgres
|
||||
let expectedStatus
|
||||
| backendName == "pg" = 200
|
||||
| otherwise = 400
|
||||
|
||||
void
|
||||
$ GraphqlEngine.postMetadataWithStatus
|
||||
400
|
||||
expectedStatus
|
||||
testEnvironment
|
||||
(Schema.trackNativeQueryCommand source backendTypeMetadata helloWorldNativeQuery)
|
||||
|
@ -16,12 +16,9 @@ import Test.Hspec (SpecWith, describe, it)
|
||||
|
||||
-- ** Preamble
|
||||
|
||||
featureFlagForStoredProcedures :: String
|
||||
featureFlagForStoredProcedures = "HASURA_FF_STORED_PROCEDURES"
|
||||
|
||||
spec :: SpecWith GlobalTestEnvironment
|
||||
spec =
|
||||
Fixture.hgeWithEnv [(featureFlagForStoredProcedures, "True")]
|
||||
Fixture.hgeWithEnv []
|
||||
$ Fixture.runClean -- re-run fixture setup on every test
|
||||
( NE.fromList
|
||||
[ (Fixture.fixture $ Fixture.Backend Sqlserver.backendTypeMetadata)
|
||||
|
@ -38,6 +38,7 @@ import Hasura.Incremental qualified as Inc
|
||||
import Hasura.Logging qualified as L
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.DDL.Schema.Cache.Config
|
||||
import Hasura.RQL.Types.BackendType
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Metadata
|
||||
import Hasura.RQL.Types.NamingCase
|
||||
@ -329,7 +330,10 @@ buildCacheStaticConfig AppEnv {..} =
|
||||
_cscEventingMode = appEnvEventingMode,
|
||||
_cscReadOnlyMode = appEnvEnableReadOnlyMode,
|
||||
_cscLogger = _lsLogger appEnvLoggers,
|
||||
_cscAreNativeQueriesEnabled = False,
|
||||
-- Native Queries are always enabled for Postgres in the OSS edition.
|
||||
_cscAreNativeQueriesEnabled = \case
|
||||
Postgres Vanilla -> True
|
||||
_ -> False,
|
||||
_cscAreStoredProceduresEnabled = False
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,6 @@ import Hasura.RQL.Types.Metadata.Object
|
||||
import Hasura.RQL.Types.Relationships.Local (RelDef, RelManualNativeQueryConfig)
|
||||
import Hasura.RQL.Types.SchemaCache.Build
|
||||
import Hasura.SQL.AnyBackend qualified as AB
|
||||
import Hasura.Server.Init.FeatureFlag (HasFeatureFlagChecker (..))
|
||||
import Hasura.Server.Init.FeatureFlag qualified as FF
|
||||
|
||||
-- | Default implementation of the 'track_native_query' request payload.
|
||||
data TrackNativeQuery (b :: BackendType) = TrackNativeQuery
|
||||
@ -146,14 +144,11 @@ runGetNativeQuery ::
|
||||
forall b m.
|
||||
( BackendMetadata b,
|
||||
MetadataM m,
|
||||
HasFeatureFlagChecker m,
|
||||
MonadError QErr m
|
||||
) =>
|
||||
GetNativeQuery b ->
|
||||
m EncJSON
|
||||
runGetNativeQuery q = do
|
||||
throwIfFeatureDisabled
|
||||
|
||||
maybe
|
||||
( throw400 NotFound
|
||||
$ "Source '"
|
||||
@ -180,8 +175,7 @@ runTrackNativeQuery ::
|
||||
( BackendMetadata b,
|
||||
MonadError QErr m,
|
||||
CacheRWM m,
|
||||
MetadataM m,
|
||||
HasFeatureFlagChecker m
|
||||
MetadataM m
|
||||
) =>
|
||||
TrackNativeQuery b ->
|
||||
m EncJSON
|
||||
@ -197,14 +191,11 @@ execTrackNativeQuery ::
|
||||
forall b m.
|
||||
( BackendMetadata b,
|
||||
MonadError QErr m,
|
||||
MetadataM m,
|
||||
HasFeatureFlagChecker m
|
||||
MetadataM m
|
||||
) =>
|
||||
TrackNativeQuery b ->
|
||||
m (MetadataObjId, MetadataModifier)
|
||||
execTrackNativeQuery trackNativeQueryRequest = do
|
||||
throwIfFeatureDisabled
|
||||
|
||||
sourceMetadata <-
|
||||
maybe
|
||||
( throw400 NotFound
|
||||
@ -310,12 +301,6 @@ dropNativeQueryInMetadata source rootFieldName = do
|
||||
. smNativeQueries
|
||||
%~ InsOrdHashMap.delete rootFieldName
|
||||
|
||||
-- | check feature flag is enabled before carrying out any actions
|
||||
throwIfFeatureDisabled :: (HasFeatureFlagChecker m, MonadError QErr m) => m ()
|
||||
throwIfFeatureDisabled = do
|
||||
enableNativeQueries <- checkFlag FF.nativeQueryInterface
|
||||
unless enableNativeQueries (throw500 "NativeQueries is disabled!")
|
||||
|
||||
-- | Check whether a native query with the given root field name exists for
|
||||
-- the given source.
|
||||
assertNativeQueryExists :: forall b m. (Backend b, MetadataM m, MonadError QErr m) => SourceName -> NativeQueryName -> m ()
|
||||
|
@ -965,7 +965,7 @@ buildSchemaCacheRule logger env mSchemaRegistryContext = proc (MetadataWithResou
|
||||
}
|
||||
|
||||
withRecordInconsistencyM metadataObject $ do
|
||||
unless (_cscAreNativeQueriesEnabled cacheStaticConfig)
|
||||
unless (_cscAreNativeQueriesEnabled cacheStaticConfig (reify $ backendTag @b))
|
||||
$ throw400 InvalidConfiguration "The Native Queries feature is disabled"
|
||||
|
||||
logicalModel <-
|
||||
|
@ -10,6 +10,7 @@ where
|
||||
|
||||
import Hasura.Logging (Hasura, Logger)
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.BackendType
|
||||
import Hasura.RQL.Types.Common (SQLGenCtx)
|
||||
import Hasura.RQL.Types.Metadata (MetadataDefaults)
|
||||
import Hasura.RQL.Types.NamingCase (NamingCase)
|
||||
@ -35,7 +36,7 @@ data CacheStaticConfig = CacheStaticConfig
|
||||
_cscLogger :: Logger Hasura,
|
||||
-- | Native queries can be enabled or disabled on the fly via a feature
|
||||
-- flag, however we only recognise a change on a restart
|
||||
_cscAreNativeQueriesEnabled :: Bool,
|
||||
_cscAreNativeQueriesEnabled :: BackendType -> Bool,
|
||||
-- | Stored procedures can be enabled or disabled on the fly via a feature
|
||||
-- flag, however we only recognise a change on a restart
|
||||
_cscAreStoredProceduresEnabled :: Bool
|
||||
|
@ -9,8 +9,6 @@ module Hasura.Server.Init.FeatureFlag
|
||||
FeatureFlags (..),
|
||||
HasFeatureFlagChecker (..),
|
||||
featureFlags,
|
||||
nativeQueryInterface,
|
||||
storedProceduresFlag,
|
||||
)
|
||||
where
|
||||
|
||||
@ -55,9 +53,7 @@ featureFlags :: FeatureFlags
|
||||
featureFlags =
|
||||
FeatureFlags
|
||||
$ HashMap.fromList
|
||||
[ ("test-flag", testFlag),
|
||||
("native-query-interface", nativeQueryInterface),
|
||||
("stored-procedures", storedProceduresFlag)
|
||||
[ ("test-flag", testFlag)
|
||||
]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -84,21 +80,3 @@ testFlag =
|
||||
ffDescription = "Testing feature flag integration",
|
||||
ffEnvVar = "HASURA_FF_TEST_FLAG"
|
||||
}
|
||||
|
||||
nativeQueryInterface :: FeatureFlag
|
||||
nativeQueryInterface =
|
||||
FeatureFlag
|
||||
{ ffIdentifier = Identifier "native-query-interface",
|
||||
ffDefaultValue = False,
|
||||
ffDescription = "Expose custom views, permissions and advanced SQL functionality via custom queries",
|
||||
ffEnvVar = "HASURA_FF_NATIVE_QUERY_INTERFACE"
|
||||
}
|
||||
|
||||
storedProceduresFlag :: FeatureFlag
|
||||
storedProceduresFlag =
|
||||
FeatureFlag
|
||||
{ ffIdentifier = Identifier "stored-procedures",
|
||||
ffDefaultValue = False,
|
||||
ffDescription = "Expose stored procedures support",
|
||||
ffEnvVar = "HASURA_FF_STORED_PROCEDURES"
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ import Hasura.RQL.Types.Metadata.Backend
|
||||
import Hasura.RQL.Types.Metadata.Object
|
||||
import Hasura.RQL.Types.SchemaCache.Build
|
||||
import Hasura.SQL.AnyBackend qualified as AB
|
||||
import Hasura.Server.Init.FeatureFlag (HasFeatureFlagChecker (..))
|
||||
import Hasura.Server.Init.FeatureFlag qualified as FF
|
||||
import Hasura.StoredProcedure.Metadata (ArgumentName, StoredProcedureMetadata (..))
|
||||
import Hasura.StoredProcedure.Types
|
||||
|
||||
@ -113,15 +111,11 @@ instance (Backend b) => ToJSON (GetStoredProcedure b) where
|
||||
runGetStoredProcedure ::
|
||||
forall b m.
|
||||
( BackendMetadata b,
|
||||
MetadataM m,
|
||||
HasFeatureFlagChecker m,
|
||||
MonadError QErr m
|
||||
MetadataM m
|
||||
) =>
|
||||
GetStoredProcedure b ->
|
||||
m EncJSON
|
||||
runGetStoredProcedure q = do
|
||||
throwIfFeatureDisabled
|
||||
|
||||
metadata <- getMetadata
|
||||
|
||||
let storedProcedure :: Maybe (StoredProcedures b)
|
||||
@ -137,14 +131,11 @@ runTrackStoredProcedure ::
|
||||
( BackendMetadata b,
|
||||
MonadError QErr m,
|
||||
CacheRWM m,
|
||||
MetadataM m,
|
||||
HasFeatureFlagChecker m
|
||||
MetadataM m
|
||||
) =>
|
||||
TrackStoredProcedure b ->
|
||||
m EncJSON
|
||||
runTrackStoredProcedure TrackStoredProcedure {..} = do
|
||||
throwIfFeatureDisabled
|
||||
|
||||
sourceMetadata <-
|
||||
maybe
|
||||
( throw400 NotFound
|
||||
@ -247,12 +238,6 @@ dropStoredProcedureInMetadata source rootFieldName = do
|
||||
. smStoredProcedures
|
||||
%~ InsOrdHashMap.delete rootFieldName
|
||||
|
||||
-- | check feature flag is enabled before carrying out any actions
|
||||
throwIfFeatureDisabled :: (HasFeatureFlagChecker m, MonadError QErr m) => m ()
|
||||
throwIfFeatureDisabled = do
|
||||
enableStoredProcedures <- checkFlag FF.storedProceduresFlag
|
||||
unless enableStoredProcedures (throw500 "Stored Procedures are disabled!")
|
||||
|
||||
-- | Check whether a stored procedure exists for the given source.
|
||||
assertStoredProcedureExists ::
|
||||
forall b m.
|
||||
|
@ -115,7 +115,7 @@ main = do
|
||||
EventingEnabled
|
||||
readOnlyMode
|
||||
logger
|
||||
False
|
||||
(const False)
|
||||
False
|
||||
dynamicConfig =
|
||||
CacheDynamicConfig
|
||||
|
Loading…
Reference in New Issue
Block a user