mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
fix: Introduce naming-convention-sep-2023 feature flag
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10200 GitOrigin-RevId: 02654837c3b98a7cbfb89cf98a1d7b5287fed1b4
This commit is contained in:
parent
014d362d7c
commit
b522a0f650
@ -25,7 +25,8 @@ spec =
|
||||
withHge
|
||||
( emptyHgeConfig
|
||||
{ hgeConfigEnvironmentVars =
|
||||
[ ("HASURA_GRAPHQL_EXPERIMENTAL_FEATURES", "naming_convention")
|
||||
[ ("HASURA_GRAPHQL_EXPERIMENTAL_FEATURES", "naming_convention"),
|
||||
("HASURA_FF_NAMING_CONVENTION_SEP_2023", "True")
|
||||
]
|
||||
}
|
||||
)
|
||||
|
@ -54,6 +54,7 @@ import Hasura.RQL.Types.Metadata (SourceMetadata (..), _cfmDefinition)
|
||||
import Hasura.RQL.Types.NamingCase
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization
|
||||
import Hasura.Server.Init.FeatureFlag qualified as FF
|
||||
import Hasura.Server.Migrate.Internal
|
||||
import Hasura.Server.Migrate.Version qualified as Version
|
||||
import Hasura.Table.Cache
|
||||
@ -163,12 +164,14 @@ resolveDatabaseMetadata ::
|
||||
FetchFunctionMetadata pgKind,
|
||||
FetchTableMetadata pgKind,
|
||||
MonadIO m,
|
||||
MonadBaseControl IO m
|
||||
MonadBaseControl IO m,
|
||||
FF.HasFeatureFlagChecker m
|
||||
) =>
|
||||
SourceMetadata ('Postgres pgKind) ->
|
||||
SourceConfig ('Postgres pgKind) ->
|
||||
m (Either QErr (DBObjectsIntrospection ('Postgres pgKind)))
|
||||
resolveDatabaseMetadata sourceMetadata sourceConfig =
|
||||
resolveDatabaseMetadata sourceMetadata sourceConfig = do
|
||||
enableNamingConventionSep2023 <- FF.checkFlag FF.namingConventionSep2023
|
||||
runExceptT $ _pecRunTx (_pscExecCtx sourceConfig) (PGExecCtxInfo (Tx PG.ReadOnly Nothing) InternalRawQuery) do
|
||||
tablesMeta <- fetchTableMetadata $ HashMap.keysSet $ InsOrdHashMap.toHashMap $ _smTables sourceMetadata
|
||||
let allFunctions =
|
||||
@ -178,7 +181,9 @@ resolveDatabaseMetadata sourceMetadata sourceConfig =
|
||||
functionsMeta <- fetchFunctionMetadata @pgKind allFunctions
|
||||
pgScalars <- fetchPgScalars
|
||||
let customization = _smCustomization sourceMetadata
|
||||
tCase = fromMaybe HasuraCase $ _scNamingConvention customization
|
||||
tCase
|
||||
| enableNamingConventionSep2023 = fromMaybe HasuraCase $ _scNamingConvention customization
|
||||
| otherwise = HasuraCase
|
||||
scalarsMap = HashMap.fromList do
|
||||
scalar <- Set.toList pgScalars
|
||||
name <- afold @(Either QErr) $ mkScalarTypeName tCase scalar
|
||||
|
@ -85,6 +85,7 @@ import Hasura.RQL.Types.Schema.Options qualified as Options
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization
|
||||
import Hasura.SQL.Types
|
||||
import Hasura.Server.Init.FeatureFlag qualified as FF
|
||||
import Hasura.Table.Cache (TableInfo (..), UpdPermInfo (..))
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
import Language.GraphQL.Draft.Syntax.QQ qualified as G
|
||||
@ -423,9 +424,12 @@ columnParser ::
|
||||
SchemaT r m (Parser 'Both n (IR.ValueWithOrigin (ColumnValue ('Postgres pgKind))))
|
||||
columnParser columnType nullability = case columnType of
|
||||
ColumnScalar scalarType -> memoizeOn 'columnParser (scalarType, nullability) do
|
||||
enableNamingConventionSep2023 <- FF.checkFlag FF.namingConventionSep2023
|
||||
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
||||
let customization = _siCustomization sourceInfo
|
||||
tCase = _rscNamingConvention customization
|
||||
tCase
|
||||
| enableNamingConventionSep2023 = _rscNamingConvention customization
|
||||
| otherwise = HasuraCase
|
||||
-- We convert the value to JSON and use the FromJSON instance. This avoids
|
||||
-- having two separate ways of parsing a value in the codebase, which
|
||||
-- could lead to inconsistencies.
|
||||
@ -906,6 +910,11 @@ comparisonExps = memoize 'comparisonExps \columnType -> do
|
||||
|
||||
castExp :: ColumnType ('Postgres pgKind) -> NamingCase -> SchemaT r m (Maybe (Parser 'Input n (CastExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind)))))
|
||||
castExp sourceType tCase = do
|
||||
enableNamingConventionSep2023 <- FF.checkFlag FF.namingConventionSep2023
|
||||
let tCaseSep2023
|
||||
| enableNamingConventionSep2023 = tCase
|
||||
| otherwise = HasuraCase
|
||||
|
||||
let maybeScalars = case sourceType of
|
||||
ColumnScalar PGGeography -> Just (PGGeography, PGGeometry)
|
||||
ColumnScalar PGGeometry -> Just (PGGeometry, PGGeography)
|
||||
@ -913,8 +922,8 @@ comparisonExps = memoize 'comparisonExps \columnType -> do
|
||||
_ -> Nothing
|
||||
|
||||
forM maybeScalars $ \(sourceScalar, targetScalar) -> do
|
||||
scalarTypeName <- C.fromAutogeneratedName <$> mkScalarTypeName tCase sourceScalar
|
||||
targetName <- mkScalarTypeName tCase targetScalar
|
||||
scalarTypeName <- C.fromAutogeneratedName <$> mkScalarTypeName tCaseSep2023 sourceScalar
|
||||
targetName <- mkScalarTypeName tCaseSep2023 targetScalar
|
||||
targetOpExps <- comparisonExps $ ColumnScalar targetScalar
|
||||
let field = P.fieldOptional targetName Nothing $ (targetScalar,) <$> targetOpExps
|
||||
sourceName = applyTypeNameCaseIdentifier tCase (scalarTypeName <> (C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["cast", "exp"])))
|
||||
|
@ -39,6 +39,7 @@ import Hasura.RQL.Types.BackendType
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization
|
||||
import Hasura.Server.Init.FeatureFlag qualified as FF
|
||||
import Hasura.Table.Cache
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
@ -143,6 +144,7 @@ conflictConstraint ::
|
||||
TableInfo ('Postgres pgKind) ->
|
||||
SchemaT r m (Parser 'Both n (UniqueConstraint ('Postgres pgKind)))
|
||||
conflictConstraint constraints tableInfo = do
|
||||
enableNamingConventionSep2023 <- FF.checkFlag FF.namingConventionSep2023
|
||||
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
||||
let sourceName = _siName sourceInfo
|
||||
tableName = tableInfoName tableInfo
|
||||
@ -157,7 +159,7 @@ conflictConstraint constraints tableInfo = do
|
||||
name <- textToName $ toTxt $ _cName
|
||||
pure
|
||||
( P.Definition
|
||||
(applyFieldNameCaseCust tCase name)
|
||||
((if enableNamingConventionSep2023 then applyFieldNameCaseCust tCase else id) name)
|
||||
(Just $ "unique or primary key constraint on columns " <> coerce (showPGCols (HS.toList cCols)))
|
||||
Nothing
|
||||
[]
|
||||
|
@ -48,6 +48,7 @@ import Hasura.RQL.Types.Schema.Options qualified as Options
|
||||
import Hasura.RQL.Types.SchemaCache hiding (askTableInfo)
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization
|
||||
import Hasura.Server.Init.FeatureFlag qualified as FF
|
||||
import Hasura.Table.Cache
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
@ -317,8 +318,11 @@ functionArgs ::
|
||||
SchemaT r m (InputFieldsParser n (FunctionArgsExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))
|
||||
functionArgs functionTrackedAs (toList -> inputArgs) = do
|
||||
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
||||
enableNamingConventionSep2023 <- FF.checkFlag FF.namingConventionSep2023
|
||||
let customization = _siCustomization sourceInfo
|
||||
tCase = _rscNamingConvention customization
|
||||
tCase
|
||||
| enableNamingConventionSep2023 = _rscNamingConvention customization
|
||||
| otherwise = HasuraCase
|
||||
mkTypename = runMkTypename $ _rscTypeNames customization
|
||||
-- First, we iterate through the original sql arguments in order, to find the
|
||||
-- corresponding graphql names. At the same time, we create the input field
|
||||
@ -350,7 +354,7 @@ functionArgs functionTrackedAs (toList -> inputArgs) = do
|
||||
tableGQLName <- getTableIdentifierName @('Postgres pgKind) tableInfo
|
||||
pure $ mkFunctionArgsTypeName computedFieldGQLName tableGQLName
|
||||
FTACustomFunction (CustomFunctionNames {cfnArgsName}) ->
|
||||
pure $ C.fromAutogeneratedName cfnArgsName
|
||||
pure $ (if enableNamingConventionSep2023 then C.fromAutogeneratedName else C.fromCustomName) cfnArgsName
|
||||
let fieldName = Name._args
|
||||
fieldDesc =
|
||||
case functionTrackedAs of
|
||||
|
@ -6,6 +6,8 @@ module Hasura.Server.Init.FeatureFlag
|
||||
CheckFeatureFlag (..),
|
||||
ceCheckFeatureFlag,
|
||||
HasFeatureFlagChecker (..),
|
||||
-- Feature flags
|
||||
namingConventionSep2023,
|
||||
)
|
||||
where
|
||||
|
||||
@ -66,7 +68,8 @@ instance Semigroup CheckFeatureFlag where
|
||||
-- | This is the list of feature flags that exist in the CE version
|
||||
ceFeatureFlags :: [(FeatureFlag, Text)]
|
||||
ceFeatureFlags =
|
||||
[ (testFlag, "Testing feature flag integration")
|
||||
[ (testFlag, "Testing feature flag integration"),
|
||||
(namingConventionSep2023, "The changes to the naming-convention feature that were added in September 2023")
|
||||
]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -88,3 +91,7 @@ instance (HasFeatureFlagChecker m) => HasFeatureFlagChecker (StateT s m) where
|
||||
-- | Testing feature flag integration
|
||||
testFlag :: FeatureFlag
|
||||
testFlag = FeatureFlag {ffIdentifier = "test-flag"}
|
||||
|
||||
-- | Feature flag enabling the changes to the naming-convention feature that were added in September 2023.
|
||||
namingConventionSep2023 :: FeatureFlag
|
||||
namingConventionSep2023 = FeatureFlag {ffIdentifier = "naming-convention-sep-2023"}
|
||||
|
Loading…
Reference in New Issue
Block a user