2020-04-24 10:55:51 +03:00
|
|
|
-- | Types and classes related to configuration when the server is initialised
|
2021-11-04 19:08:33 +03:00
|
|
|
module Hasura.Server.Init.Config
|
2022-08-01 20:12:40 +03:00
|
|
|
( -- * HGEOptions
|
2022-07-01 06:39:39 +03:00
|
|
|
HGEOptionsRaw (..),
|
2022-07-22 02:35:50 +03:00
|
|
|
horDatabaseUrl,
|
|
|
|
horMetadataDbUrl,
|
|
|
|
horCommand,
|
2022-08-01 20:12:40 +03:00
|
|
|
|
|
|
|
-- * HGEOptionsRaw
|
|
|
|
HGEOptions (..),
|
|
|
|
hoCommand,
|
|
|
|
|
|
|
|
-- * PostgresConnInfo
|
2021-11-04 19:08:33 +03:00
|
|
|
PostgresConnInfo (..),
|
2022-07-17 05:04:04 +03:00
|
|
|
pciDatabaseConn,
|
|
|
|
pciRetries,
|
2022-08-01 20:12:40 +03:00
|
|
|
|
|
|
|
-- * PostgresRawConnInfo
|
2022-08-01 22:35:13 +03:00
|
|
|
PostgresConnInfoRaw (..),
|
2022-07-17 05:04:04 +03:00
|
|
|
_PGConnDatabaseUrl,
|
|
|
|
_PGConnDetails,
|
2022-07-26 10:32:16 +03:00
|
|
|
mkUrlConnInfo,
|
2022-08-01 20:12:40 +03:00
|
|
|
|
|
|
|
-- * PostgresRawConnDetails
|
2022-08-01 22:35:13 +03:00
|
|
|
PostgresConnDetailsRaw (..),
|
2022-08-01 20:12:40 +03:00
|
|
|
|
|
|
|
-- * HGECommand
|
|
|
|
HGECommand (..),
|
|
|
|
_HCServe,
|
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
-- * ServeOptionsRaw
|
|
|
|
ServeOptionsRaw (..),
|
2022-08-01 20:12:40 +03:00
|
|
|
API (..),
|
|
|
|
KeepAliveDelay (..),
|
|
|
|
OptionalInterval (..),
|
2022-08-01 22:35:13 +03:00
|
|
|
AuthHookRaw,
|
|
|
|
ConnParamsRaw (..),
|
2021-11-04 19:08:33 +03:00
|
|
|
ResponseInternalErrorsConfig (..),
|
|
|
|
WSConnectionInitTimeout (..),
|
|
|
|
defaultKeepAliveDelay,
|
|
|
|
defaultWSConnectionInitTimeout,
|
|
|
|
msToOptionalInterval,
|
|
|
|
rawConnDetailsToUrl,
|
|
|
|
rawConnDetailsToUrlText,
|
|
|
|
shouldIncludeInternal,
|
2022-08-01 20:12:40 +03:00
|
|
|
|
|
|
|
-- * ServeOptions
|
|
|
|
ServeOptions (..),
|
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
-- * Downgrade Options
|
2022-08-01 20:12:40 +03:00
|
|
|
DowngradeOptions (..),
|
2021-11-04 19:08:33 +03:00
|
|
|
)
|
|
|
|
where
|
2020-04-24 10:55:51 +03:00
|
|
|
|
2022-07-01 06:39:39 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
import Control.Lens (Lens', Prism')
|
|
|
|
import Control.Lens qualified as Lens
|
|
|
|
import Data.Aeson (FromJSON, ToJSON)
|
|
|
|
import Data.Aeson qualified as Aeson
|
|
|
|
import Data.Text qualified as Text
|
|
|
|
import Data.Time qualified as Time
|
|
|
|
import Data.URL.Template qualified as Template
|
2021-09-24 01:56:37 +03:00
|
|
|
import Database.PG.Query qualified as Q
|
2022-08-01 20:12:40 +03:00
|
|
|
import Hasura.GraphQL.Execute.Subscription.Options qualified as Subscription.Options
|
2022-07-15 11:54:27 +03:00
|
|
|
import Hasura.GraphQL.Schema.NamingCase (NamingCase)
|
2022-07-14 20:57:28 +03:00
|
|
|
import Hasura.GraphQL.Schema.Options qualified as Options
|
2022-08-01 20:12:40 +03:00
|
|
|
import Hasura.Logging qualified as Logging
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Prelude
|
2022-08-01 20:12:40 +03:00
|
|
|
import Hasura.RQL.Types.Common qualified as Common
|
|
|
|
import Hasura.Server.Auth qualified as Auth
|
|
|
|
import Hasura.Server.Cors qualified as Cors
|
|
|
|
import Hasura.Server.Logging qualified as Server.Logging
|
|
|
|
import Hasura.Server.Types qualified as Types
|
|
|
|
import Hasura.Session qualified as Session
|
|
|
|
import Network.Wai.Handler.Warp qualified as Warp
|
|
|
|
import Network.WebSockets qualified as WebSockets
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-07-01 06:39:39 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
-- | Raw HGE Options from the arg parser and the env.
|
|
|
|
data HGEOptionsRaw impl = HGEOptionsRaw
|
2022-08-01 22:35:13 +03:00
|
|
|
{ _horDatabaseUrl :: PostgresConnInfo (Maybe PostgresConnInfoRaw),
|
2022-08-01 20:12:40 +03:00
|
|
|
_horMetadataDbUrl :: Maybe String,
|
|
|
|
_horCommand :: HGECommand impl
|
2021-09-24 01:56:37 +03:00
|
|
|
}
|
2020-04-24 10:55:51 +03:00
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
horDatabaseUrl :: Lens' (HGEOptionsRaw impl) (PostgresConnInfo (Maybe PostgresConnInfoRaw))
|
2022-08-01 20:12:40 +03:00
|
|
|
horDatabaseUrl = Lens.lens _horDatabaseUrl $ \hdu a -> hdu {_horDatabaseUrl = a}
|
2020-04-24 10:55:51 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
horMetadataDbUrl :: Lens' (HGEOptionsRaw impl) (Maybe String)
|
|
|
|
horMetadataDbUrl = Lens.lens _horMetadataDbUrl $ \hdu a -> hdu {_horMetadataDbUrl = a}
|
|
|
|
|
|
|
|
horCommand :: Lens' (HGEOptionsRaw impl) (HGECommand impl)
|
|
|
|
horCommand = Lens.lens _horCommand $ \hdu a -> hdu {_horCommand = a}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | The final processed HGE options.
|
|
|
|
data HGEOptions impl = HGEOptions
|
|
|
|
{ _hoDatabaseUrl :: PostgresConnInfo (Maybe Common.UrlConf),
|
|
|
|
_hoMetadataDbUrl :: Maybe String,
|
|
|
|
_hoCommand :: HGECommand impl
|
|
|
|
}
|
|
|
|
|
|
|
|
hoCommand :: Lens' (HGEOptions impl) (HGECommand impl)
|
|
|
|
hoCommand = Lens.lens _hoCommand $ \hdu a -> hdu {_hoCommand = a}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | Postgres connection info tupled with a retry count.
|
|
|
|
--
|
|
|
|
-- In practice, the @a@ here is one of the following:
|
2022-08-01 22:35:13 +03:00
|
|
|
-- 1. 'Maybe PostgresConnInfoRaw'
|
2022-08-01 20:12:40 +03:00
|
|
|
-- 2. 'Maybe UrlConf'
|
|
|
|
-- 3. 'Maybe Text'
|
|
|
|
-- 4. 'Maybe DatabaseUrl' where 'DatabaseUrl' is an alias for 'Text'
|
|
|
|
--
|
2022-08-01 22:35:13 +03:00
|
|
|
-- If it contains a 'Maybe PostgresConnInfoRaw' then you have not yet
|
2022-08-01 20:12:40 +03:00
|
|
|
-- processed your arg parser results.
|
|
|
|
data PostgresConnInfo a = PostgresConnInfo
|
|
|
|
{ _pciDatabaseConn :: a,
|
|
|
|
_pciRetries :: Maybe Int
|
|
|
|
}
|
|
|
|
deriving (Show, Eq, Functor, Foldable, Traversable)
|
|
|
|
|
|
|
|
pciDatabaseConn :: Lens' (PostgresConnInfo a) a
|
|
|
|
pciDatabaseConn = Lens.lens _pciDatabaseConn $ \pci a -> pci {_pciDatabaseConn = a}
|
|
|
|
|
|
|
|
pciRetries :: Lens' (PostgresConnInfo a) (Maybe Int)
|
|
|
|
pciRetries = Lens.lens _pciRetries $ \pci mi -> pci {_pciRetries = mi}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | Postgres Connection info can come in the form of a templated URI
|
|
|
|
-- string or structured data.
|
2022-08-01 22:35:13 +03:00
|
|
|
data PostgresConnInfoRaw
|
2022-08-01 20:12:40 +03:00
|
|
|
= PGConnDatabaseUrl Template.URLTemplate
|
2022-08-01 22:35:13 +03:00
|
|
|
| PGConnDetails PostgresConnDetailsRaw
|
2021-03-31 13:39:01 +03:00
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
mkUrlConnInfo :: String -> PostgresConnInfoRaw
|
2022-08-01 20:12:40 +03:00
|
|
|
mkUrlConnInfo = PGConnDatabaseUrl . Template.mkPlainURLTemplate . Text.pack
|
2021-03-31 13:39:01 +03:00
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
_PGConnDatabaseUrl :: Prism' PostgresConnInfoRaw Template.URLTemplate
|
2022-08-01 20:12:40 +03:00
|
|
|
_PGConnDatabaseUrl = Lens.prism' PGConnDatabaseUrl $ \case
|
|
|
|
PGConnDatabaseUrl template -> Just template
|
|
|
|
PGConnDetails _ -> Nothing
|
2021-03-31 13:39:01 +03:00
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
_PGConnDetails :: Prism' PostgresConnInfoRaw PostgresConnDetailsRaw
|
2022-08-01 20:12:40 +03:00
|
|
|
_PGConnDetails = Lens.prism' PGConnDetails $ \case
|
|
|
|
PGConnDatabaseUrl _ -> Nothing
|
|
|
|
PGConnDetails prcd -> Just prcd
|
2021-03-31 13:39:01 +03:00
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
rawConnDetailsToUrl :: PostgresConnDetailsRaw -> Template.URLTemplate
|
2022-08-01 20:12:40 +03:00
|
|
|
rawConnDetailsToUrl =
|
|
|
|
Template.mkPlainURLTemplate . rawConnDetailsToUrlText
|
2021-08-24 19:25:12 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
--------------------------------------------------------------------------------
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
-- | Structured Postgres connection information as provided by the arg
|
|
|
|
-- parser or env vars.
|
2022-08-01 22:35:13 +03:00
|
|
|
data PostgresConnDetailsRaw = PostgresConnDetailsRaw
|
2022-08-01 20:12:40 +03:00
|
|
|
{ connHost :: String,
|
|
|
|
connPort :: Int,
|
|
|
|
connUser :: String,
|
|
|
|
connPassword :: String,
|
|
|
|
connDatabase :: String,
|
|
|
|
connOptions :: Maybe String
|
|
|
|
}
|
|
|
|
deriving (Eq, Read, Show)
|
2021-08-24 19:25:12 +03:00
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
instance FromJSON PostgresConnDetailsRaw where
|
|
|
|
parseJSON = Aeson.withObject "PostgresConnDetailsRaw" \o -> do
|
2022-08-01 20:12:40 +03:00
|
|
|
connHost <- o Aeson..: "host"
|
|
|
|
connPort <- o Aeson..: "port"
|
|
|
|
connUser <- o Aeson..: "user"
|
|
|
|
connPassword <- o Aeson..: "password"
|
|
|
|
connDatabase <- o Aeson..: "database"
|
|
|
|
connOptions <- o Aeson..:? "options"
|
2022-08-01 22:35:13 +03:00
|
|
|
pure $ PostgresConnDetailsRaw {..}
|
2022-08-01 20:12:40 +03:00
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
instance ToJSON PostgresConnDetailsRaw where
|
|
|
|
toJSON PostgresConnDetailsRaw {..} =
|
2022-08-01 20:12:40 +03:00
|
|
|
Aeson.object $
|
|
|
|
[ "host" Aeson..= connHost,
|
|
|
|
"port" Aeson..= connPort,
|
|
|
|
"user" Aeson..= connUser,
|
|
|
|
"password" Aeson..= connPassword,
|
|
|
|
"database" Aeson..= connDatabase
|
|
|
|
]
|
|
|
|
<> catMaybes [fmap ("options" Aeson..=) connOptions]
|
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
rawConnDetailsToUrlText :: PostgresConnDetailsRaw -> Text
|
|
|
|
rawConnDetailsToUrlText PostgresConnDetailsRaw {..} =
|
2022-08-01 20:12:40 +03:00
|
|
|
Text.pack $
|
|
|
|
"postgresql://" <> connUser
|
|
|
|
<> ":"
|
|
|
|
<> connPassword
|
|
|
|
<> "@"
|
|
|
|
<> connHost
|
|
|
|
<> ":"
|
|
|
|
<> show connPort
|
|
|
|
<> "/"
|
|
|
|
<> connDatabase
|
|
|
|
<> maybe "" ("?options=" <>) connOptions
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | The HGE Arg parser Command choices.
|
|
|
|
--
|
2022-08-01 22:35:13 +03:00
|
|
|
-- This is polymorphic so that we can pack either 'ServeOptionsRaw' or
|
|
|
|
-- 'ProServeOptionsRaw' in it.
|
2022-08-01 20:12:40 +03:00
|
|
|
data HGECommand a
|
|
|
|
= HCServe a
|
|
|
|
| HCExport
|
|
|
|
| HCClean
|
|
|
|
| HCVersion
|
|
|
|
| HCDowngrade !DowngradeOptions
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
|
|
|
_HCServe :: Prism' (HGECommand a) a
|
|
|
|
_HCServe = Lens.prism' HCServe \case
|
|
|
|
HCServe a -> Just a
|
|
|
|
_ -> Nothing
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2021-08-24 19:25:12 +03:00
|
|
|
|
2022-07-01 06:39:39 +03:00
|
|
|
-- | The Serve Command options accumulated from the arg parser and env.
|
2022-08-01 22:35:13 +03:00
|
|
|
data ServeOptionsRaw impl = ServeOptionsRaw
|
2022-02-03 19:13:50 +03:00
|
|
|
{ rsoPort :: Maybe Int,
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoHost :: Maybe Warp.HostPreference,
|
2022-08-01 22:35:13 +03:00
|
|
|
rsoConnParams :: ConnParamsRaw,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoTxIso :: Maybe Q.TxIsolation,
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoAdminSecret :: Maybe Auth.AdminSecretHash,
|
2022-08-01 22:35:13 +03:00
|
|
|
rsoAuthHook :: AuthHookRaw,
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoJwtSecret :: Maybe Auth.JWTConfig,
|
|
|
|
rsoUnAuthRole :: Maybe Session.RoleName,
|
|
|
|
rsoCorsConfig :: Maybe Cors.CorsConfig,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoEnableConsole :: Bool,
|
|
|
|
rsoConsoleAssetsDir :: Maybe Text,
|
|
|
|
rsoEnableTelemetry :: Maybe Bool,
|
|
|
|
rsoWsReadCookie :: Bool,
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoStringifyNum :: Options.StringifyNumbers,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoDangerousBooleanCollapse :: Maybe Bool,
|
|
|
|
rsoEnabledAPIs :: Maybe [API],
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoMxRefetchInt :: Maybe Subscription.Options.RefetchInterval,
|
|
|
|
rsoMxBatchSize :: Maybe Subscription.Options.BatchSize,
|
|
|
|
-- We have different config options for livequery and streaming subscriptions
|
|
|
|
rsoStreamingMxRefetchInt :: Maybe Subscription.Options.RefetchInterval,
|
|
|
|
rsoStreamingMxBatchSize :: Maybe Subscription.Options.BatchSize,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoEnableAllowlist :: Bool,
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoEnabledLogTypes :: Maybe [Logging.EngineLogType impl],
|
|
|
|
rsoLogLevel :: Maybe Logging.LogLevel,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoDevMode :: Bool,
|
|
|
|
rsoAdminInternalErrors :: Maybe Bool,
|
|
|
|
rsoEventsHttpPoolSize :: Maybe Int,
|
|
|
|
rsoEventsFetchInterval :: Maybe Milliseconds,
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoAsyncActionsFetchInterval :: Maybe OptionalInterval,
|
|
|
|
rsoEnableRemoteSchemaPermissions :: Options.RemoteSchemaPermissions,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoWebSocketCompression :: Bool,
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoWebSocketKeepAlive :: Maybe KeepAliveDelay,
|
|
|
|
rsoInferFunctionPermissions :: Maybe Options.InferFunctionPermissions,
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoEnableMaintenanceMode :: Types.MaintenanceMode (),
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoSchemaPollInterval :: Maybe OptionalInterval,
|
2022-08-01 20:12:40 +03:00
|
|
|
-- See Note [Experimental features] at bottom of module
|
|
|
|
rsoExperimentalFeatures :: Maybe [Types.ExperimentalFeature],
|
|
|
|
rsoEventsFetchBatchSize :: Maybe Common.NonNegativeInt,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoGracefulShutdownTimeout :: Maybe Seconds,
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoWebSocketConnectionInitTimeout :: Maybe WSConnectionInitTimeout,
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoEnableMetadataQueryLoggingEnv :: Server.Logging.MetadataQueryLoggingMode,
|
2022-05-26 14:54:30 +03:00
|
|
|
-- | stores global default naming convention
|
|
|
|
rsoDefaultNamingConvention :: Maybe NamingCase
|
2020-04-24 10:55:51 +03:00
|
|
|
}
|
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
data API
|
|
|
|
= METADATA
|
|
|
|
| GRAPHQL
|
|
|
|
| PGDUMP
|
|
|
|
| DEVELOPER
|
|
|
|
| CONFIG
|
|
|
|
| METRICS
|
|
|
|
deriving (Show, Eq, Read, Generic)
|
2022-07-01 06:39:39 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
instance FromJSON API where
|
|
|
|
parseJSON = Aeson.withText "API" \case
|
|
|
|
"metadata" -> pure METADATA
|
|
|
|
"graphql" -> pure GRAPHQL
|
|
|
|
"pgdump" -> pure PGDUMP
|
|
|
|
"developer" -> pure DEVELOPER
|
|
|
|
"config" -> pure CONFIG
|
|
|
|
"metrics" -> pure METRICS
|
|
|
|
x -> fail $ "unexpected string '" <> show x <> "'."
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
instance ToJSON API where
|
|
|
|
toJSON = \case
|
|
|
|
METADATA -> Aeson.String "metadata"
|
|
|
|
GRAPHQL -> Aeson.String "graphql"
|
|
|
|
PGDUMP -> Aeson.String "pgdump"
|
|
|
|
DEVELOPER -> Aeson.String "developer"
|
|
|
|
CONFIG -> Aeson.String "config"
|
|
|
|
METRICS -> Aeson.String "metrics"
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
instance Hashable API
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
-- TODO(SOLOMON): Monomorphize
|
2022-08-01 22:35:13 +03:00
|
|
|
type AuthHookRaw = Auth.AuthHookG (Maybe Text) (Maybe Auth.AuthHookType)
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
-- | Sleep time interval for recurring activities such as (@'asyncActionsProcessor')
|
|
|
|
-- Presently @'msToOptionalInterval' interprets `0` as Skip.
|
|
|
|
data OptionalInterval
|
|
|
|
= -- | No polling
|
|
|
|
Skip
|
|
|
|
| -- | Interval time
|
|
|
|
Interval !Milliseconds
|
|
|
|
deriving (Show, Eq)
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
msToOptionalInterval :: Milliseconds -> OptionalInterval
|
|
|
|
msToOptionalInterval = \case
|
|
|
|
0 -> Skip
|
|
|
|
s -> Interval s
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
instance FromJSON OptionalInterval where
|
|
|
|
parseJSON v = msToOptionalInterval <$> Aeson.parseJSON v
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
instance ToJSON OptionalInterval where
|
|
|
|
toJSON = \case
|
|
|
|
Skip -> Aeson.toJSON @Milliseconds 0
|
|
|
|
Interval s -> Aeson.toJSON s
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
-- | The Raw configuration data from the Arg and Env parsers needed to
|
|
|
|
-- construct a 'Q.ConnParams'
|
2022-08-01 22:35:13 +03:00
|
|
|
data ConnParamsRaw = ConnParamsRaw
|
2022-08-01 20:12:40 +03:00
|
|
|
{ rcpStripes :: Maybe Int,
|
|
|
|
rcpConns :: Maybe Int,
|
|
|
|
rcpIdleTime :: Maybe Int,
|
|
|
|
-- | Time from connection creation after which to destroy a connection and
|
|
|
|
-- choose a different/new one.
|
|
|
|
rcpConnLifetime :: Maybe Time.NominalDiffTime,
|
|
|
|
rcpAllowPrepare :: Maybe Bool,
|
|
|
|
-- | See @HASURA_GRAPHQL_PG_POOL_TIMEOUT@
|
|
|
|
rcpPoolTimeout :: Maybe Time.NominalDiffTime
|
|
|
|
}
|
2020-04-24 10:55:51 +03:00
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
newtype KeepAliveDelay = KeepAliveDelay {unKeepAliveDelay :: Seconds}
|
2021-08-24 19:25:12 +03:00
|
|
|
deriving (Eq, Show)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-07-30 04:04:27 +03:00
|
|
|
instance FromJSON KeepAliveDelay where
|
2022-08-01 20:12:40 +03:00
|
|
|
parseJSON = Aeson.withObject "KeepAliveDelay" \o -> do
|
|
|
|
unKeepAliveDelay <- o Aeson..: "keep_alive_delay"
|
2022-07-30 04:04:27 +03:00
|
|
|
pure $ KeepAliveDelay {..}
|
|
|
|
|
|
|
|
instance ToJSON KeepAliveDelay where
|
|
|
|
toJSON KeepAliveDelay {..} =
|
2022-08-01 20:12:40 +03:00
|
|
|
Aeson.object ["keep_alive_delay" Aeson..= unKeepAliveDelay]
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2021-08-24 19:25:12 +03:00
|
|
|
defaultKeepAliveDelay :: KeepAliveDelay
|
|
|
|
defaultKeepAliveDelay = KeepAliveDelay $ fromIntegral (5 :: Int)
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
newtype WSConnectionInitTimeout = WSConnectionInitTimeout {unWSConnectionInitTimeout :: Seconds}
|
2021-08-24 19:25:12 +03:00
|
|
|
deriving (Eq, Show)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-07-30 04:04:27 +03:00
|
|
|
instance FromJSON WSConnectionInitTimeout where
|
2022-08-01 20:12:40 +03:00
|
|
|
parseJSON = Aeson.withObject "WSConnectionInitTimeout" \o -> do
|
|
|
|
unWSConnectionInitTimeout <- o Aeson..: "w_s_connection_init_timeout"
|
2022-07-30 04:04:27 +03:00
|
|
|
pure $ WSConnectionInitTimeout {..}
|
2022-07-29 03:45:51 +03:00
|
|
|
|
2022-07-30 04:04:27 +03:00
|
|
|
instance ToJSON WSConnectionInitTimeout where
|
|
|
|
toJSON WSConnectionInitTimeout {..} =
|
2022-08-01 20:12:40 +03:00
|
|
|
Aeson.object ["w_s_connection_init_timeout" Aeson..= unWSConnectionInitTimeout]
|
2021-08-24 19:25:12 +03:00
|
|
|
|
|
|
|
defaultWSConnectionInitTimeout :: WSConnectionInitTimeout
|
|
|
|
defaultWSConnectionInitTimeout = WSConnectionInitTimeout $ fromIntegral (3 :: Int)
|
2020-11-12 12:25:48 +03:00
|
|
|
|
2022-07-01 06:39:39 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | The final Serve Command options accummulated from the Arg Parser
|
|
|
|
-- and the Environment, fully processed and ready to apply when
|
|
|
|
-- running the server.
|
2021-09-24 01:56:37 +03:00
|
|
|
data ServeOptions impl = ServeOptions
|
2022-02-03 19:13:50 +03:00
|
|
|
{ soPort :: Int,
|
2022-08-01 20:12:40 +03:00
|
|
|
soHost :: Warp.HostPreference,
|
2022-02-03 19:13:50 +03:00
|
|
|
soConnParams :: Q.ConnParams,
|
|
|
|
soTxIso :: Q.TxIsolation,
|
2022-08-01 20:12:40 +03:00
|
|
|
soAdminSecret :: HashSet Auth.AdminSecretHash,
|
|
|
|
soAuthHook :: Maybe Auth.AuthHook,
|
|
|
|
soJwtSecret :: [Auth.JWTConfig],
|
|
|
|
soUnAuthRole :: Maybe Session.RoleName,
|
|
|
|
soCorsConfig :: Cors.CorsConfig,
|
2022-02-03 19:13:50 +03:00
|
|
|
soEnableConsole :: Bool,
|
|
|
|
soConsoleAssetsDir :: Maybe Text,
|
|
|
|
soEnableTelemetry :: Bool,
|
2022-07-14 20:57:28 +03:00
|
|
|
soStringifyNum :: Options.StringifyNumbers,
|
2022-02-03 19:13:50 +03:00
|
|
|
soDangerousBooleanCollapse :: Bool,
|
2022-08-01 20:12:40 +03:00
|
|
|
soEnabledAPIs :: HashSet API,
|
|
|
|
soLiveQueryOpts :: Subscription.Options.LiveQueriesOptions,
|
|
|
|
soStreamingQueryOpts :: Subscription.Options.StreamQueriesOptions,
|
2022-02-03 19:13:50 +03:00
|
|
|
soEnableAllowlist :: Bool,
|
2022-08-01 20:12:40 +03:00
|
|
|
soEnabledLogTypes :: HashSet (Logging.EngineLogType impl),
|
|
|
|
soLogLevel :: Logging.LogLevel,
|
2022-02-03 19:13:50 +03:00
|
|
|
soResponseInternalErrorsConfig :: ResponseInternalErrorsConfig,
|
|
|
|
soEventsHttpPoolSize :: Maybe Int,
|
|
|
|
soEventsFetchInterval :: Maybe Milliseconds,
|
|
|
|
soAsyncActionsFetchInterval :: OptionalInterval,
|
2022-07-14 20:57:28 +03:00
|
|
|
soEnableRemoteSchemaPermissions :: Options.RemoteSchemaPermissions,
|
2022-08-01 20:12:40 +03:00
|
|
|
soConnectionOptions :: WebSockets.ConnectionOptions,
|
2022-07-15 11:54:27 +03:00
|
|
|
soWebSocketKeepAlive :: KeepAliveDelay,
|
2022-07-14 20:57:28 +03:00
|
|
|
soInferFunctionPermissions :: Options.InferFunctionPermissions,
|
2022-08-01 20:12:40 +03:00
|
|
|
soEnableMaintenanceMode :: Types.MaintenanceMode (),
|
2022-02-03 19:13:50 +03:00
|
|
|
soSchemaPollInterval :: OptionalInterval,
|
2022-08-01 20:12:40 +03:00
|
|
|
soExperimentalFeatures :: HashSet Types.ExperimentalFeature,
|
|
|
|
soEventsFetchBatchSize :: Common.NonNegativeInt,
|
2022-02-03 19:13:50 +03:00
|
|
|
soDevMode :: Bool,
|
|
|
|
soGracefulShutdownTimeout :: Seconds,
|
2022-07-15 11:54:27 +03:00
|
|
|
soWebSocketConnectionInitTimeout :: WSConnectionInitTimeout,
|
2022-08-01 20:12:40 +03:00
|
|
|
soEventingMode :: Types.EventingMode,
|
|
|
|
soReadOnlyMode :: Types.ReadOnlyMode,
|
|
|
|
soEnableMetadataQueryLogging :: Server.Logging.MetadataQueryLoggingMode,
|
2022-05-26 14:54:30 +03:00
|
|
|
soDefaultNamingConvention :: Maybe NamingCase
|
2020-04-24 10:55:51 +03:00
|
|
|
}
|
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
-- | @'ResponseInternalErrorsConfig' represents the encoding of the internal
|
|
|
|
-- errors in the response to the client.
|
|
|
|
-- See the github comment https://github.com/hasura/graphql-engine/issues/4031#issuecomment-609747705 for more details.
|
|
|
|
data ResponseInternalErrorsConfig
|
|
|
|
= InternalErrorsAllRequests
|
|
|
|
| InternalErrorsAdminOnly
|
|
|
|
| InternalErrorsDisabled
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
|
|
|
shouldIncludeInternal :: Session.RoleName -> ResponseInternalErrorsConfig -> Bool
|
|
|
|
shouldIncludeInternal role = \case
|
|
|
|
InternalErrorsAllRequests -> True
|
|
|
|
InternalErrorsAdminOnly -> role == Session.adminRoleName
|
|
|
|
InternalErrorsDisabled -> False
|
|
|
|
|
2022-07-30 04:04:27 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-07-01 06:39:39 +03:00
|
|
|
-- | The Downgrade Command options. These are only sourced from the
|
|
|
|
-- Arg Parser and are used directly in 'Hasura.Server.Migrate'.
|
2021-09-24 01:56:37 +03:00
|
|
|
data DowngradeOptions = DowngradeOptions
|
|
|
|
{ dgoTargetVersion :: !Text,
|
|
|
|
dgoDryRun :: !Bool
|
|
|
|
}
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2022-07-30 04:04:27 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
{- Note: [Experimental features]
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2022-07-22 02:35:50 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
The graphql-engine accepts a list of experimental features that can be
|
|
|
|
enabled at the startup. Experimental features are a way to introduce
|
|
|
|
new, but not stable features to our users in a manner in which they have
|
|
|
|
the choice to enable or disable a certain feature(s).
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
The objective of an experimental feature should be that when the feature is disabled,
|
|
|
|
the graphql-engine should work the same way as it worked before adding the said feature.
|
2022-07-26 03:42:05 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
The experimental feature's flag is `--experimental-features` and the corresponding
|
|
|
|
environment variable is `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` which expects a comma-seperated
|
|
|
|
value.
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
When an experimental feature is stable enough i.e. it's stable through multiple non-beta releases
|
|
|
|
then we make the feature not experimental i.e. it will always be enabled. Note that when we do this
|
|
|
|
we still have to support parsing of the experimental feature because users of the previous version
|
|
|
|
will have it enabled and when they upgrade an error should not be thrown at the startup. For example:
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
The inherited roles was an experimental feature when introduced and it was enabled by
|
|
|
|
setting `--experimental-features` to `inherited_roles` and then it was decided to make the inherited roles
|
|
|
|
a stable feature, so it was removed as an experimental feature but the code was modified such that
|
|
|
|
`--experimental-features inherited_roles` to not throw an error.
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2022-08-01 20:12:40 +03:00
|
|
|
-}
|