mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
Refactor/move namingcase default into arg merging
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5289 GitOrigin-RevId: 39c5a5b839534dc5416d62ca20c5051ae4d8ef57
This commit is contained in:
parent
16bde2ef34
commit
7842bc34ee
@ -305,7 +305,7 @@ serveOptions =
|
||||
soEventingMode = EventingEnabled,
|
||||
soReadOnlyMode = ReadOnlyModeDisabled,
|
||||
soEnableMetadataQueryLogging = MetadataQueryLoggingDisabled,
|
||||
soDefaultNamingConvention = Nothing,
|
||||
soDefaultNamingConvention = Init._default Init.defaultNamingConventionOption,
|
||||
soExtensionsSchema = ExtensionsSchema "public",
|
||||
soMetadataDefaults = emptyMetadataDefaults
|
||||
}
|
||||
|
@ -778,7 +778,8 @@ buildSchemaCacheRule logger env = proc (metadataNoDefaults, invalidationKeys, st
|
||||
Just (sourceConfig, source) -> do
|
||||
let metadataInvalidationKey = Inc.selectD #_ikMetadata invalidationKeys
|
||||
(tableInputs, _, _) = unzip3 $ map mkTableInputs $ OMap.elems $ _smTables sourceMetadata
|
||||
!namingConv = if isNamingConventionEnabled then getNamingConvention (_smCustomization sourceMetadata) defaultNC else HasuraCase
|
||||
scNamingConvention = _scNamingConvention $ _smCustomization sourceMetadata
|
||||
!namingConv = if isNamingConventionEnabled then fromMaybe defaultNC scNamingConvention else HasuraCase
|
||||
tablesCoreInfo <-
|
||||
buildTableCache
|
||||
-<
|
||||
|
@ -19,7 +19,6 @@ module Hasura.RQL.Types.SourceCustomization
|
||||
applyTypeNameCaseCust,
|
||||
applyFieldNameCaseIdentifier,
|
||||
applyTypeNameCaseIdentifier,
|
||||
getNamingConvention,
|
||||
getNamingCase,
|
||||
getTextFieldName,
|
||||
getTextTypeName,
|
||||
@ -252,9 +251,6 @@ emptySourceCustomization = SourceCustomization Nothing Nothing Nothing
|
||||
getSourceTypeCustomization :: SourceCustomization -> SourceTypeCustomization
|
||||
getSourceTypeCustomization = fromMaybe emptySourceTypeCustomization . _scTypeNames
|
||||
|
||||
getNamingConvention :: SourceCustomization -> Maybe NamingCase -> NamingCase
|
||||
getNamingConvention sc defaultNC = fromMaybe HasuraCase $ _scNamingConvention sc <|> defaultNC
|
||||
|
||||
-- | Source customization as it appears in the SchemaCache.
|
||||
data ResolvedSourceCustomization = ResolvedSourceCustomization
|
||||
{ _rscRootFields :: MkRootFieldName,
|
||||
@ -281,10 +277,11 @@ getNamingCase ::
|
||||
(MonadError QErr m) =>
|
||||
SourceCustomization ->
|
||||
SupportedNamingCase ->
|
||||
Maybe NamingCase ->
|
||||
NamingCase ->
|
||||
m NamingCase
|
||||
getNamingCase sc namingConventionSupport defaultNC = do
|
||||
let namingConv = getNamingConvention sc defaultNC
|
||||
-- Use the 'NamingCase' from 'SourceCustomization' or a provided default.
|
||||
let namingConv = fromMaybe defaultNC (_scNamingConvention sc)
|
||||
-- The console currently constructs a graphql query based on table name and
|
||||
-- schema name to fetch the data from the database (other than postgres).
|
||||
-- Now, when we set @GraphqlCase@ for other (than postgres) databases, this
|
||||
|
@ -43,7 +43,7 @@ data ServerConfig = ServerConfig
|
||||
scfgConsoleAssetsDir :: !(Maybe Text),
|
||||
scfgExperimentalFeatures :: !(Set.HashSet ExperimentalFeature),
|
||||
scfgIsPrometheusMetricsEnabled :: !Bool,
|
||||
scfgDefaultNamingConvention :: !(Maybe NamingCase)
|
||||
scfgDefaultNamingConvention :: !NamingCase
|
||||
}
|
||||
deriving (Show, Eq)
|
||||
|
||||
@ -59,7 +59,7 @@ runGetConfig ::
|
||||
Maybe Text ->
|
||||
Set.HashSet ExperimentalFeature ->
|
||||
Set.HashSet API ->
|
||||
Maybe NamingCase ->
|
||||
NamingCase ->
|
||||
ServerConfig
|
||||
runGetConfig
|
||||
functionPermsCtx
|
||||
|
@ -135,7 +135,7 @@ data ServerCtx = ServerCtx
|
||||
scLoggingSettings :: !LoggingSettings,
|
||||
scEventingMode :: !EventingMode,
|
||||
scEnableReadOnlyMode :: !ReadOnlyMode,
|
||||
scDefaultNamingConvention :: !(Maybe NamingCase),
|
||||
scDefaultNamingConvention :: !NamingCase,
|
||||
scServerMetrics :: !ServerMetrics,
|
||||
scMetadataDefaults :: !MetadataDefaults,
|
||||
scEnabledLogTypes :: HashSet (L.EngineLogType L.Hasura),
|
||||
|
@ -204,7 +204,7 @@ mkServeOptions ServeOptionsRaw {..} = do
|
||||
soEnableMetadataQueryLogging <- case rsoEnableMetadataQueryLoggingEnv of
|
||||
Server.Logging.MetadataQueryLoggingDisabled -> withOptionDefault Nothing enableMetadataQueryLoggingOption
|
||||
metadataQueryLoggingEnabled -> pure metadataQueryLoggingEnabled
|
||||
soDefaultNamingConvention <- withOption rsoDefaultNamingConvention defaultNamingConventionOption
|
||||
soDefaultNamingConvention <- withOptionDefault rsoDefaultNamingConvention defaultNamingConventionOption
|
||||
soMetadataDefaults <- withOptionDefault rsoMetadataDefaults metadataDefaultsOption
|
||||
soExtensionsSchema <- withOptionDefault rsoExtensionsSchema metadataDBExtensionsSchemaOption
|
||||
|
||||
|
@ -73,7 +73,7 @@ import Database.PG.Query qualified as Query
|
||||
import Hasura.Backends.Postgres.Connection.MonadTx qualified as MonadTx
|
||||
import Hasura.Cache.Bounded qualified as Bounded
|
||||
import Hasura.GraphQL.Execute.Subscription.Options qualified as Subscription.Options
|
||||
import Hasura.GraphQL.Schema.NamingCase (NamingCase)
|
||||
import Hasura.GraphQL.Schema.NamingCase qualified as NC
|
||||
import Hasura.GraphQL.Schema.Options qualified as Options
|
||||
import Hasura.Logging qualified as Logging
|
||||
import Hasura.Prelude
|
||||
@ -1061,7 +1061,7 @@ enableMetadataQueryLoggingOption =
|
||||
|
||||
-- TODO(SOLOMON): The defaulting behavior for this occurs inside the Engine. In
|
||||
-- an isolated PR we should move that defaulting in the parsing stage.
|
||||
parseDefaultNamingConvention :: Opt.Parser (Maybe NamingCase)
|
||||
parseDefaultNamingConvention :: Opt.Parser (Maybe NC.NamingCase)
|
||||
parseDefaultNamingConvention =
|
||||
Opt.optional $
|
||||
Opt.option
|
||||
@ -1070,14 +1070,10 @@ parseDefaultNamingConvention =
|
||||
<> Opt.help (Config._helpMessage defaultNamingConventionOption)
|
||||
)
|
||||
|
||||
-- NOTE: This should be 'Config.Option NC.NamingCase' with a default
|
||||
-- of 'NC.HasuraCase' but 'ServeOptions' expects a 'Maybe
|
||||
-- NC.NamingCase' and HGE handles the defaulting explicitly. This
|
||||
-- should be changed in a subsequent PR.
|
||||
defaultNamingConventionOption :: Config.Option ()
|
||||
defaultNamingConventionOption :: Config.Option NC.NamingCase
|
||||
defaultNamingConventionOption =
|
||||
Config.Option
|
||||
{ Config._default = (),
|
||||
{ Config._default = NC.HasuraCase,
|
||||
Config._envVar = "HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION",
|
||||
Config._helpMessage =
|
||||
"Default naming convention for the auto generated graphql names. Possible values are"
|
||||
|
@ -474,7 +474,7 @@ data ServeOptions impl = ServeOptions
|
||||
-- | See note '$readOnlyMode'
|
||||
soReadOnlyMode :: Server.Types.ReadOnlyMode,
|
||||
soEnableMetadataQueryLogging :: Server.Logging.MetadataQueryLoggingMode,
|
||||
soDefaultNamingConvention :: Maybe NamingCase,
|
||||
soDefaultNamingConvention :: NamingCase,
|
||||
soExtensionsSchema :: MonadTx.ExtensionsSchema,
|
||||
soMetadataDefaults :: MetadataDefaults
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ data ServerConfigCtx = ServerConfigCtx
|
||||
_sccEventingMode :: EventingMode,
|
||||
_sccReadOnlyMode :: ReadOnlyMode,
|
||||
-- | stores global default naming convention
|
||||
_sccDefaultNamingConvention :: Maybe NamingCase,
|
||||
_sccDefaultNamingConvention :: NamingCase,
|
||||
_sccMetadataDefaults :: MetadataDefaults,
|
||||
_sccCheckFeatureFlag :: FeatureFlag -> IO Bool
|
||||
}
|
||||
|
@ -1388,6 +1388,17 @@ mkServeOptionsSpec =
|
||||
fmap (UUT.soEnableMetadataQueryLogging) result `Hspec.shouldBe` Right Logging.MetadataQueryLoggingEnabled
|
||||
|
||||
Hspec.describe "soDefaultNamingConvention" $ do
|
||||
Hspec.it "Default = HasuraCase" $ do
|
||||
let -- Given
|
||||
rawServeOptions = emptyServeOptionsRaw
|
||||
-- When
|
||||
-- When
|
||||
env = []
|
||||
-- Then
|
||||
result = UUT.runWithEnv env (UUT.mkServeOptions @Hasura rawServeOptions)
|
||||
|
||||
fmap (UUT.soDefaultNamingConvention) result `Hspec.shouldBe` Right NamingCase.HasuraCase
|
||||
|
||||
Hspec.it "Env > Nothing" $ do
|
||||
let -- Given
|
||||
rawServeOptions = emptyServeOptionsRaw
|
||||
@ -1397,7 +1408,7 @@ mkServeOptionsSpec =
|
||||
-- Then
|
||||
result = UUT.runWithEnv env (UUT.mkServeOptions @Hasura rawServeOptions)
|
||||
|
||||
fmap (UUT.soDefaultNamingConvention) result `Hspec.shouldBe` Right (Just NamingCase.GraphqlCase)
|
||||
fmap (UUT.soDefaultNamingConvention) result `Hspec.shouldBe` Right NamingCase.GraphqlCase
|
||||
|
||||
Hspec.it "Arg > Env" $ do
|
||||
let -- Given
|
||||
@ -1407,7 +1418,7 @@ mkServeOptionsSpec =
|
||||
-- Then
|
||||
result = UUT.runWithEnv env (UUT.mkServeOptions @Hasura rawServeOptions)
|
||||
|
||||
fmap (UUT.soDefaultNamingConvention) result `Hspec.shouldBe` Right (Just NamingCase.GraphqlCase)
|
||||
fmap (UUT.soDefaultNamingConvention) result `Hspec.shouldBe` Right NamingCase.GraphqlCase
|
||||
|
||||
Hspec.describe "soExtensionsSchema" $ do
|
||||
Hspec.it "Default == 'public' " $ do
|
||||
|
@ -87,7 +87,7 @@ main = do
|
||||
mempty
|
||||
EventingEnabled
|
||||
readOnlyMode
|
||||
Nothing -- We are not testing the naming convention here, so defaulting to hasura-default
|
||||
(_default defaultNamingConventionOption)
|
||||
emptyMetadataDefaults
|
||||
(FF.checkFeatureFlag mempty)
|
||||
cacheBuildParams = CacheBuildParams httpManager (mkPgSourceResolver print) mkMSSQLSourceResolver serverConfigCtx
|
||||
|
Loading…
Reference in New Issue
Block a user