2022-08-17 04:07:44 +03:00
|
|
|
{-# LANGUAGE ViewPatterns #-}
|
|
|
|
|
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-05 03:28:49 +03:00
|
|
|
( -- * Option
|
|
|
|
Option (..),
|
|
|
|
optionPP,
|
|
|
|
|
|
|
|
-- * HGEOptionsRaw
|
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
|
|
|
|
2022-08-05 03:28:49 +03:00
|
|
|
-- * HGEOptions
|
2022-08-01 20:12:40 +03:00
|
|
|
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 (..),
|
2023-02-07 08:58:24 +03:00
|
|
|
ConsoleStatus (..),
|
|
|
|
isConsoleEnabled,
|
2023-02-28 12:09:31 +03:00
|
|
|
AdminInternalErrorsStatus (..),
|
|
|
|
isAdminInternalErrorsEnabled,
|
2023-02-08 07:13:10 +03:00
|
|
|
isWebSocketCompressionEnabled,
|
2023-02-08 06:35:19 +03:00
|
|
|
AllowListStatus (..),
|
|
|
|
isAllowListEnabled,
|
2023-02-08 05:57:08 +03:00
|
|
|
DevModeStatus (..),
|
|
|
|
isDevModeEnabled,
|
2023-02-08 04:46:21 +03:00
|
|
|
TelemetryStatus (..),
|
|
|
|
isTelemetryEnabled,
|
2023-02-08 03:56:22 +03:00
|
|
|
WsReadCookieStatus (..),
|
|
|
|
isWsReadCookieEnabled,
|
2022-08-17 04:07:44 +03:00
|
|
|
Port,
|
|
|
|
_getPort,
|
|
|
|
mkPort,
|
|
|
|
unsafePort,
|
2022-08-01 20:12:40 +03:00
|
|
|
API (..),
|
|
|
|
KeepAliveDelay (..),
|
|
|
|
OptionalInterval (..),
|
2022-08-04 05:24:35 +03:00
|
|
|
AuthHookRaw (..),
|
2022-08-01 22:35:13 +03:00
|
|
|
ConnParamsRaw (..),
|
2021-11-04 19:08:33 +03:00
|
|
|
ResponseInternalErrorsConfig (..),
|
|
|
|
WSConnectionInitTimeout (..),
|
|
|
|
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 (..),
|
2022-08-04 06:21:55 +03:00
|
|
|
-- $experimentalFeatures
|
|
|
|
-- $readOnlyMode
|
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
|
2022-08-05 03:28:49 +03:00
|
|
|
import Data.Aeson (FromJSON, ToJSON, (.:), (.:?), (.=))
|
2022-08-01 20:12:40 +03:00
|
|
|
import Data.Aeson qualified as Aeson
|
2022-08-17 04:07:44 +03:00
|
|
|
import Data.Scientific qualified as Scientific
|
2022-08-01 20:12:40 +03:00
|
|
|
import Data.Text qualified as Text
|
2022-08-17 04:07:44 +03:00
|
|
|
import Data.Time qualified as Time
|
2022-08-01 20:12:40 +03:00
|
|
|
import Data.URL.Template qualified as Template
|
2022-08-17 04:07:44 +03:00
|
|
|
import Database.PG.Query qualified as Query
|
|
|
|
import Hasura.Backends.Postgres.Connection.MonadTx qualified as MonadTx
|
|
|
|
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-08-17 04:07:44 +03:00
|
|
|
import Hasura.Logging qualified as Logging
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Prelude
|
2022-08-17 04:07:44 +03:00
|
|
|
import Hasura.RQL.Types.Common qualified as Common
|
2022-10-20 15:45:31 +03:00
|
|
|
import Hasura.RQL.Types.Metadata (MetadataDefaults)
|
2023-04-24 11:50:29 +03:00
|
|
|
import Hasura.RQL.Types.Roles (RoleName, adminRoleName)
|
2023-04-24 18:17:15 +03:00
|
|
|
import Hasura.RQL.Types.Schema.Options qualified as Schema.Options
|
2022-08-17 04:07:44 +03:00
|
|
|
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 Server.Types
|
2022-08-01 20:12:40 +03:00
|
|
|
import Network.Wai.Handler.Warp qualified as Warp
|
2022-08-17 04:07:44 +03:00
|
|
|
import Network.WebSockets qualified as WebSockets
|
2022-09-21 21:01:48 +03:00
|
|
|
import Refined (NonNegative, Positive, Refined, unrefine)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2022-07-01 06:39:39 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-08-05 03:28:49 +03:00
|
|
|
-- | The collected default value, env var, and help message for an
|
|
|
|
-- option. If there should be no default value then use 'Option ()'.
|
|
|
|
data Option def = Option
|
|
|
|
{ _default :: def,
|
|
|
|
_envVar :: String,
|
|
|
|
_helpMessage :: String
|
|
|
|
}
|
2023-02-07 08:58:24 +03:00
|
|
|
deriving (Functor)
|
2022-08-05 03:28:49 +03:00
|
|
|
|
|
|
|
-- | Helper function for pretty printing @Option a@.
|
|
|
|
optionPP :: Option a -> (String, String)
|
|
|
|
optionPP = _envVar &&& _helpMessage
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
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
|
2022-08-17 04:07:44 +03:00
|
|
|
{ _hoDatabaseUrl :: PostgresConnInfo (Maybe Common.UrlConf),
|
2022-08-01 20:12:40 +03:00
|
|
|
_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}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-08-17 04:07:44 +03:00
|
|
|
-- | Postgres Connection info 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-17 04:07:44 +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-17 04:07:44 +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-05 03:28:49 +03:00
|
|
|
connHost <- o .: "host"
|
|
|
|
connPort <- o .: "port"
|
|
|
|
connUser <- o .: "user"
|
|
|
|
connPassword <- o .: "password"
|
|
|
|
connDatabase <- o .: "database"
|
|
|
|
connOptions <- o .:? "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 $
|
2022-08-05 03:28:49 +03:00
|
|
|
[ "host" .= connHost,
|
|
|
|
"port" .= connPort,
|
|
|
|
"user" .= connUser,
|
|
|
|
"password" .= connPassword,
|
|
|
|
"database" .= connDatabase
|
2022-08-01 20:12:40 +03:00
|
|
|
]
|
2022-08-05 03:28:49 +03:00
|
|
|
<> catMaybes [fmap ("options" .=) connOptions]
|
2022-08-01 20:12:40 +03:00
|
|
|
|
2022-08-01 22:35:13 +03:00
|
|
|
rawConnDetailsToUrlText :: PostgresConnDetailsRaw -> Text
|
|
|
|
rawConnDetailsToUrlText PostgresConnDetailsRaw {..} =
|
2022-08-01 20:12:40 +03:00
|
|
|
Text.pack $
|
2022-11-02 23:53:23 +03:00
|
|
|
"postgresql://"
|
|
|
|
<> connUser
|
2022-08-01 20:12:40 +03:00
|
|
|
<> ":"
|
|
|
|
<> 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-08-17 04:07:44 +03:00
|
|
|
-- | The Serve Command options accumulated from the Arg and Env parsers.
|
2022-08-05 03:28:49 +03:00
|
|
|
--
|
2022-08-17 04:07:44 +03:00
|
|
|
-- NOTE: A 'Nothing' value indicates the absence of a particular
|
|
|
|
-- flag. Hence types such as 'Maybe (HashSet X)' or 'Maybe Bool'.
|
2022-08-01 22:35:13 +03:00
|
|
|
data ServeOptionsRaw impl = ServeOptionsRaw
|
2022-08-17 04:07:44 +03:00
|
|
|
{ rsoPort :: Maybe Port,
|
2022-08-01 20:12:40 +03:00
|
|
|
rsoHost :: Maybe Warp.HostPreference,
|
2022-08-01 22:35:13 +03:00
|
|
|
rsoConnParams :: ConnParamsRaw,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoTxIso :: Maybe Query.TxIsolation,
|
|
|
|
rsoAdminSecret :: Maybe Auth.AdminSecretHash,
|
2022-08-01 22:35:13 +03:00
|
|
|
rsoAuthHook :: AuthHookRaw,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoJwtSecret :: Maybe Auth.JWTConfig,
|
2023-04-24 11:50:29 +03:00
|
|
|
rsoUnAuthRole :: Maybe RoleName,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoCorsConfig :: Maybe Cors.CorsConfig,
|
2023-02-07 08:58:24 +03:00
|
|
|
rsoConsoleStatus :: ConsoleStatus,
|
2022-02-03 19:13:50 +03:00
|
|
|
rsoConsoleAssetsDir :: Maybe Text,
|
2022-09-27 17:50:32 +03:00
|
|
|
rsoConsoleSentryDsn :: Maybe Text,
|
2023-02-08 04:46:21 +03:00
|
|
|
rsoEnableTelemetry :: Maybe TelemetryStatus,
|
2023-02-08 03:56:22 +03:00
|
|
|
rsoWsReadCookie :: WsReadCookieStatus,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoStringifyNum :: Schema.Options.StringifyNumbers,
|
2022-08-26 07:37:35 +03:00
|
|
|
rsoDangerousBooleanCollapse :: Maybe Schema.Options.DangerouslyCollapseBooleans,
|
2022-08-05 03:28:49 +03:00
|
|
|
rsoEnabledAPIs :: Maybe (HashSet API),
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoMxRefetchInt :: Maybe Subscription.Options.RefetchInterval,
|
|
|
|
rsoMxBatchSize :: Maybe Subscription.Options.BatchSize,
|
2022-08-01 20:12:40 +03:00
|
|
|
-- We have different config options for livequery and streaming subscriptions
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoStreamingMxRefetchInt :: Maybe Subscription.Options.RefetchInterval,
|
|
|
|
rsoStreamingMxBatchSize :: Maybe Subscription.Options.BatchSize,
|
2023-02-08 06:35:19 +03:00
|
|
|
rsoEnableAllowList :: AllowListStatus,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoEnabledLogTypes :: Maybe (HashSet (Logging.EngineLogType impl)),
|
|
|
|
rsoLogLevel :: Maybe Logging.LogLevel,
|
2023-02-08 05:57:08 +03:00
|
|
|
rsoDevMode :: DevModeStatus,
|
2023-02-28 12:09:31 +03:00
|
|
|
rsoAdminInternalErrors :: Maybe AdminInternalErrorsStatus,
|
2022-09-21 21:01:48 +03:00
|
|
|
rsoEventsHttpPoolSize :: Maybe (Refined Positive Int),
|
|
|
|
rsoEventsFetchInterval :: Maybe (Refined NonNegative Milliseconds),
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoAsyncActionsFetchInterval :: Maybe OptionalInterval,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoEnableRemoteSchemaPermissions :: Schema.Options.RemoteSchemaPermissions,
|
2023-02-08 07:13:10 +03:00
|
|
|
rsoWebSocketCompression :: WebSockets.CompressionOptions,
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoWebSocketKeepAlive :: Maybe KeepAliveDelay,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoInferFunctionPermissions :: Maybe Schema.Options.InferFunctionPermissions,
|
|
|
|
rsoEnableMaintenanceMode :: Server.Types.MaintenanceMode (),
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoSchemaPollInterval :: Maybe OptionalInterval,
|
2022-08-04 06:21:55 +03:00
|
|
|
-- | See Note '$experimentalFeatures' at bottom of module
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoExperimentalFeatures :: Maybe (HashSet Server.Types.ExperimentalFeature),
|
2022-09-21 21:01:48 +03:00
|
|
|
rsoEventsFetchBatchSize :: Maybe (Refined NonNegative Int),
|
|
|
|
rsoGracefulShutdownTimeout :: Maybe (Refined NonNegative Seconds),
|
2022-07-29 03:45:51 +03:00
|
|
|
rsoWebSocketConnectionInitTimeout :: Maybe WSConnectionInitTimeout,
|
2022-08-17 04:07:44 +03:00
|
|
|
rsoEnableMetadataQueryLoggingEnv :: Server.Logging.MetadataQueryLoggingMode,
|
2022-05-26 14:54:30 +03:00
|
|
|
-- | stores global default naming convention
|
2022-08-09 14:42:12 +03:00
|
|
|
rsoDefaultNamingConvention :: Maybe NamingCase,
|
2022-10-20 15:45:31 +03:00
|
|
|
rsoExtensionsSchema :: Maybe MonadTx.ExtensionsSchema,
|
2023-03-15 11:14:20 +03:00
|
|
|
rsoMetadataDefaults :: Maybe MetadataDefaults,
|
|
|
|
rsoApolloFederationStatus :: Maybe Server.Types.ApolloFederationStatus
|
2020-04-24 10:55:51 +03:00
|
|
|
}
|
|
|
|
|
2023-02-07 08:58:24 +03:00
|
|
|
-- | Whether or not to serve Console assets.
|
|
|
|
data ConsoleStatus = ConsoleEnabled | ConsoleDisabled
|
|
|
|
deriving stock (Show, Eq, Ord, Generic)
|
|
|
|
|
|
|
|
instance NFData ConsoleStatus
|
|
|
|
|
|
|
|
instance Hashable ConsoleStatus
|
|
|
|
|
|
|
|
isConsoleEnabled :: ConsoleStatus -> Bool
|
|
|
|
isConsoleEnabled = \case
|
|
|
|
ConsoleEnabled -> True
|
|
|
|
ConsoleDisabled -> False
|
|
|
|
|
|
|
|
instance FromJSON ConsoleStatus where
|
|
|
|
parseJSON = fmap (bool ConsoleDisabled ConsoleEnabled) . Aeson.parseJSON
|
|
|
|
|
|
|
|
instance ToJSON ConsoleStatus where
|
|
|
|
toJSON = Aeson.toJSON . isConsoleEnabled
|
|
|
|
|
2023-02-28 12:09:31 +03:00
|
|
|
-- | Whether or not internal errors will be sent in response to admin.
|
|
|
|
data AdminInternalErrorsStatus = AdminInternalErrorsEnabled | AdminInternalErrorsDisabled
|
|
|
|
deriving stock (Show, Eq, Ord, Generic)
|
|
|
|
|
|
|
|
instance NFData AdminInternalErrorsStatus
|
|
|
|
|
|
|
|
instance Hashable AdminInternalErrorsStatus
|
|
|
|
|
|
|
|
isAdminInternalErrorsEnabled :: AdminInternalErrorsStatus -> Bool
|
|
|
|
isAdminInternalErrorsEnabled = \case
|
|
|
|
AdminInternalErrorsEnabled -> True
|
|
|
|
AdminInternalErrorsDisabled -> False
|
|
|
|
|
|
|
|
instance FromJSON AdminInternalErrorsStatus where
|
|
|
|
parseJSON = fmap (bool AdminInternalErrorsDisabled AdminInternalErrorsEnabled) . Aeson.parseJSON
|
|
|
|
|
|
|
|
instance ToJSON AdminInternalErrorsStatus where
|
|
|
|
toJSON = Aeson.toJSON . isAdminInternalErrorsEnabled
|
|
|
|
|
2023-02-08 07:13:10 +03:00
|
|
|
isWebSocketCompressionEnabled :: WebSockets.CompressionOptions -> Bool
|
|
|
|
isWebSocketCompressionEnabled = \case
|
|
|
|
WebSockets.PermessageDeflateCompression _ -> True
|
|
|
|
WebSockets.NoCompression -> False
|
|
|
|
|
2023-02-08 06:35:19 +03:00
|
|
|
-- | A representation of whether or not to enable the GraphQL Query AllowList.
|
|
|
|
--
|
|
|
|
-- See: https://hasura.io/docs/latest/security/allow-list/#enable-allow-list
|
|
|
|
data AllowListStatus = AllowListEnabled | AllowListDisabled
|
|
|
|
deriving stock (Show, Eq, Ord, Generic)
|
|
|
|
|
|
|
|
instance NFData AllowListStatus
|
|
|
|
|
|
|
|
instance Hashable AllowListStatus
|
|
|
|
|
|
|
|
isAllowListEnabled :: AllowListStatus -> Bool
|
|
|
|
isAllowListEnabled = \case
|
|
|
|
AllowListEnabled -> True
|
|
|
|
AllowListDisabled -> False
|
|
|
|
|
|
|
|
instance FromJSON AllowListStatus where
|
|
|
|
parseJSON = fmap (bool AllowListDisabled AllowListEnabled) . Aeson.parseJSON
|
|
|
|
|
|
|
|
instance ToJSON AllowListStatus where
|
|
|
|
toJSON = Aeson.toJSON . isAllowListEnabled
|
|
|
|
|
2023-02-08 05:57:08 +03:00
|
|
|
-- | A representation of whether or not to enable Hasura Dev Mode.
|
|
|
|
--
|
|
|
|
-- See: https://hasura.io/docs/latest/deployment/graphql-engine-flags/config-examples/#dev-mode
|
|
|
|
data DevModeStatus = DevModeEnabled | DevModeDisabled
|
|
|
|
deriving stock (Show, Eq, Ord, Generic)
|
|
|
|
|
|
|
|
instance NFData DevModeStatus
|
|
|
|
|
|
|
|
instance Hashable DevModeStatus
|
|
|
|
|
|
|
|
isDevModeEnabled :: DevModeStatus -> Bool
|
|
|
|
isDevModeEnabled = \case
|
|
|
|
DevModeEnabled -> True
|
|
|
|
DevModeDisabled -> False
|
|
|
|
|
|
|
|
instance FromJSON DevModeStatus where
|
|
|
|
parseJSON = fmap (bool DevModeDisabled DevModeEnabled) . Aeson.parseJSON
|
|
|
|
|
|
|
|
instance ToJSON DevModeStatus where
|
|
|
|
toJSON = Aeson.toJSON . isDevModeEnabled
|
|
|
|
|
2023-02-08 04:46:21 +03:00
|
|
|
-- | A representation of whether or not to enable telemetry that is isomorphic to 'Bool'.
|
|
|
|
data TelemetryStatus = TelemetryEnabled | TelemetryDisabled
|
|
|
|
deriving stock (Show, Eq, Ord, Generic)
|
|
|
|
|
|
|
|
instance NFData TelemetryStatus
|
|
|
|
|
|
|
|
instance Hashable TelemetryStatus
|
|
|
|
|
|
|
|
isTelemetryEnabled :: TelemetryStatus -> Bool
|
|
|
|
isTelemetryEnabled = \case
|
|
|
|
TelemetryEnabled -> True
|
|
|
|
TelemetryDisabled -> False
|
|
|
|
|
|
|
|
instance FromJSON TelemetryStatus where
|
|
|
|
parseJSON = fmap (bool TelemetryDisabled TelemetryEnabled) . Aeson.parseJSON
|
|
|
|
|
|
|
|
instance ToJSON TelemetryStatus where
|
|
|
|
toJSON = Aeson.toJSON . isTelemetryEnabled
|
|
|
|
|
2023-02-08 03:56:22 +03:00
|
|
|
-- | A representation of whether or not to read the websocket cookie
|
|
|
|
-- on initial handshake that is isomorphic to 'Bool'. See
|
|
|
|
-- 'wsReadCookieOption' for more details.
|
|
|
|
data WsReadCookieStatus = WsReadCookieEnabled | WsReadCookieDisabled
|
|
|
|
deriving stock (Show, Eq, Generic)
|
|
|
|
|
|
|
|
instance NFData WsReadCookieStatus
|
|
|
|
|
|
|
|
instance Hashable WsReadCookieStatus
|
|
|
|
|
|
|
|
isWsReadCookieEnabled :: WsReadCookieStatus -> Bool
|
|
|
|
isWsReadCookieEnabled = \case
|
|
|
|
WsReadCookieEnabled -> True
|
|
|
|
WsReadCookieDisabled -> False
|
|
|
|
|
|
|
|
instance FromJSON WsReadCookieStatus where
|
|
|
|
parseJSON = fmap (bool WsReadCookieDisabled WsReadCookieEnabled) . Aeson.parseJSON
|
|
|
|
|
|
|
|
instance ToJSON WsReadCookieStatus where
|
|
|
|
toJSON = Aeson.toJSON . isWsReadCookieEnabled
|
|
|
|
|
2022-08-17 04:07:44 +03:00
|
|
|
-- | An 'Int' representing a Port number in the range 0 to 65536.
|
|
|
|
newtype Port = Port {_getPort :: Int}
|
|
|
|
deriving stock (Show, Eq, Ord, Generic)
|
server: delete the `Cacheable` type class in favor of `Eq`
What is the `Cacheable` type class about?
```haskell
class Eq a => Cacheable a where
unchanged :: Accesses -> a -> a -> Bool
default unchanged :: (Generic a, GCacheable (Rep a)) => Accesses -> a -> a -> Bool
unchanged accesses a b = gunchanged (from a) (from b) accesses
```
Its only method is an alternative to `(==)`. The added value of `unchanged` (and the additional `Accesses` argument) arises _only_ for one type, namely `Dependency`. Indeed, the `Cacheable (Dependency a)` instance is non-trivial, whereas every other `Cacheable` instance is completely boilerplate (and indeed either generated from `Generic`, or simply `unchanged _ = (==)`). The `Cacheable (Dependency a)` instance is the only one where the `Accesses` argument is not just passed onwards.
The only callsite of the `unchanged` method is in the `ArrowCache (Rule m)` method. That is to say that the `Cacheable` type class is used to decide when we can re-use parts of the schema cache between Metadata operations.
So what is the `Cacheable (Dependency a)` instance about? Normally, the output of a `Rule m a b` is re-used when the new input (of type `a`) is equal to the old one. But sometimes, that's too coarse: it might be that a certain `Rule m a b` only depends on a small part of its input of type `a`. A `Dependency` allows us to spell out what parts of `a` are being depended on, and these parts are recorded as values of types `Access a` in the state `Accesses`.
If the input `a` changes, but not in a way that touches the recorded `Accesses`, then the output `b` of that rule can be re-used without recomputing.
So now you understand _why_ we're passing `Accesses` to the `unchanged` method: `unchanged` is an equality check in disguise that just needs some additional context.
But we don't need to pass `Accesses` as a function argument. We can use the `reflection` package to pass it as type-level context. So the core of this PR is that we change the instance declaration from
```haskell
instance (Cacheable a) => Cacheable (Dependency a) where
```
to
```haskell
instance (Given Accesses, Eq a) => Eq (Dependency a) where
```
and use `(==)` instead of `unchanged`.
If you haven't seen `reflection` before: it's like a `MonadReader`, but it doesn't require a `Monad`.
In order to pass the current `Accesses` value, instead of simply passing the `Accesses` as a function argument, we need to instantiate the `Given Accesses` context. We use the `give` method from the `reflection` package for that.
```haskell
give :: forall r. Accesses -> (Given Accesses => r) -> r
unchanged :: (Given Accesses => Eq a) => Accesses -> a -> a -> Bool
unchanged accesses a b = give accesses (a == b)
```
With these three components in place, we can delete the `Cacheable` type class entirely.
The remainder of this PR is just to remove the `Cacheable` type class and its instances.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6877
GitOrigin-RevId: 7125f5e11d856e7672ab810a23d5bf5ad176e77f
2022-11-21 19:33:56 +03:00
|
|
|
deriving newtype (ToJSON, NFData, Hashable)
|
2022-08-17 04:07:44 +03:00
|
|
|
|
|
|
|
mkPort :: Int -> Maybe Port
|
|
|
|
mkPort x = case x >= 0 && x < 65536 of
|
|
|
|
True -> Just $ Port x
|
|
|
|
False -> Nothing
|
|
|
|
|
|
|
|
unsafePort :: Int -> Port
|
|
|
|
unsafePort = Port
|
|
|
|
|
|
|
|
instance FromJSON Port where
|
|
|
|
parseJSON = Aeson.withScientific "Int" $ \t -> do
|
|
|
|
case t > 0 && t < 65536 of
|
|
|
|
True -> maybe (fail "integer passed is out of bounds") (pure . Port) $ Scientific.toBoundedInteger t
|
|
|
|
False -> fail "integer passed is out of bounds"
|
|
|
|
|
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-04 05:24:35 +03:00
|
|
|
data AuthHookRaw = AuthHookRaw
|
|
|
|
{ ahrUrl :: Maybe Text,
|
2023-03-14 21:27:21 +03:00
|
|
|
ahrType :: Maybe Auth.AuthHookType,
|
|
|
|
ahrSendRequestBody :: Maybe Bool
|
2022-08-04 05:24:35 +03:00
|
|
|
}
|
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')
|
2022-08-17 04:07:44 +03:00
|
|
|
-- Presently 'msToOptionalInterval' interprets `0` as Skip.
|
2022-08-01 20:12:40 +03:00
|
|
|
data OptionalInterval
|
|
|
|
= -- | No polling
|
|
|
|
Skip
|
|
|
|
| -- | Interval time
|
2022-09-21 21:01:48 +03:00
|
|
|
Interval (Refined NonNegative Milliseconds)
|
2022-08-01 20:12:40 +03:00
|
|
|
deriving (Show, Eq)
|
2022-07-15 11:54:27 +03:00
|
|
|
|
2022-09-21 21:01:48 +03:00
|
|
|
msToOptionalInterval :: Refined NonNegative Milliseconds -> OptionalInterval
|
2022-08-01 20:12:40 +03:00
|
|
|
msToOptionalInterval = \case
|
2022-09-21 21:01:48 +03:00
|
|
|
(unrefine -> 0) -> Skip
|
2022-08-01 20:12:40 +03:00
|
|
|
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
|
2022-08-17 04:07:44 +03:00
|
|
|
-- construct a 'ConnParams'
|
2022-08-01 22:35:13 +03:00
|
|
|
data ConnParamsRaw = ConnParamsRaw
|
2022-08-17 04:07:44 +03:00
|
|
|
{ -- NOTE: Should any of these types be 'PositiveInt'?
|
2022-09-21 21:01:48 +03:00
|
|
|
rcpStripes :: Maybe (Refined NonNegative Int),
|
|
|
|
rcpConns :: Maybe (Refined NonNegative Int),
|
|
|
|
rcpIdleTime :: Maybe (Refined NonNegative Int),
|
2022-08-01 20:12:40 +03:00
|
|
|
-- | Time from connection creation after which to destroy a connection and
|
|
|
|
-- choose a different/new one.
|
2022-09-21 21:01:48 +03:00
|
|
|
rcpConnLifetime :: Maybe (Refined NonNegative Time.NominalDiffTime),
|
2022-08-01 20:12:40 +03:00
|
|
|
rcpAllowPrepare :: Maybe Bool,
|
|
|
|
-- | See @HASURA_GRAPHQL_PG_POOL_TIMEOUT@
|
2022-09-21 21:01:48 +03:00
|
|
|
rcpPoolTimeout :: Maybe (Refined NonNegative Time.NominalDiffTime)
|
2022-08-01 20:12:40 +03:00
|
|
|
}
|
2020-04-24 10:55:51 +03:00
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2022-09-21 21:01:48 +03:00
|
|
|
newtype KeepAliveDelay = KeepAliveDelay {unKeepAliveDelay :: Refined NonNegative 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
|
2022-08-05 03:28:49 +03:00
|
|
|
unKeepAliveDelay <- o .: "keep_alive_delay"
|
2022-07-30 04:04:27 +03:00
|
|
|
pure $ KeepAliveDelay {..}
|
|
|
|
|
|
|
|
instance ToJSON KeepAliveDelay where
|
|
|
|
toJSON KeepAliveDelay {..} =
|
2022-08-05 03:28:49 +03:00
|
|
|
Aeson.object ["keep_alive_delay" .= unKeepAliveDelay]
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2022-08-05 03:28:49 +03:00
|
|
|
--------------------------------------------------------------------------------
|
2021-08-24 19:25:12 +03:00
|
|
|
|
2022-08-17 04:07:44 +03:00
|
|
|
-- | The timeout duration in 'Seconds' for a WebSocket connection.
|
2022-09-21 21:01:48 +03:00
|
|
|
newtype WSConnectionInitTimeout = WSConnectionInitTimeout {unWSConnectionInitTimeout :: Refined NonNegative Seconds}
|
2022-08-17 04:07:44 +03:00
|
|
|
deriving newtype (Show, Eq, Ord)
|
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
|
2022-08-05 03:28:49 +03:00
|
|
|
unWSConnectionInitTimeout <- o .: "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-05 03:28:49 +03:00
|
|
|
Aeson.object ["w_s_connection_init_timeout" .= unWSConnectionInitTimeout]
|
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-08-17 04:07:44 +03:00
|
|
|
{ soPort :: Port,
|
|
|
|
soHost :: Warp.HostPreference,
|
|
|
|
soConnParams :: Query.ConnParams,
|
|
|
|
soTxIso :: Query.TxIsolation,
|
|
|
|
soAdminSecret :: HashSet Auth.AdminSecretHash,
|
|
|
|
soAuthHook :: Maybe Auth.AuthHook,
|
|
|
|
soJwtSecret :: [Auth.JWTConfig],
|
2023-04-24 11:50:29 +03:00
|
|
|
soUnAuthRole :: Maybe RoleName,
|
2022-08-17 04:07:44 +03:00
|
|
|
soCorsConfig :: Cors.CorsConfig,
|
2023-02-07 08:58:24 +03:00
|
|
|
soConsoleStatus :: ConsoleStatus,
|
2022-02-03 19:13:50 +03:00
|
|
|
soConsoleAssetsDir :: Maybe Text,
|
2022-09-27 17:50:32 +03:00
|
|
|
soConsoleSentryDsn :: Maybe Text,
|
2023-02-08 04:46:21 +03:00
|
|
|
soEnableTelemetry :: TelemetryStatus,
|
2022-08-17 04:07:44 +03:00
|
|
|
soStringifyNum :: Schema.Options.StringifyNumbers,
|
2022-08-26 07:37:35 +03:00
|
|
|
soDangerousBooleanCollapse :: Schema.Options.DangerouslyCollapseBooleans,
|
2022-08-01 20:12:40 +03:00
|
|
|
soEnabledAPIs :: HashSet API,
|
2022-08-17 04:07:44 +03:00
|
|
|
soLiveQueryOpts :: Subscription.Options.LiveQueriesOptions,
|
|
|
|
soStreamingQueryOpts :: Subscription.Options.StreamQueriesOptions,
|
2023-02-08 06:35:19 +03:00
|
|
|
soEnableAllowList :: AllowListStatus,
|
2022-08-17 04:07:44 +03:00
|
|
|
soEnabledLogTypes :: HashSet (Logging.EngineLogType impl),
|
|
|
|
soLogLevel :: Logging.LogLevel,
|
2022-09-21 21:01:48 +03:00
|
|
|
soEventsHttpPoolSize :: Refined Positive Int,
|
|
|
|
soEventsFetchInterval :: Refined NonNegative Milliseconds,
|
2022-02-03 19:13:50 +03:00
|
|
|
soAsyncActionsFetchInterval :: OptionalInterval,
|
2022-08-17 04:07:44 +03:00
|
|
|
soEnableRemoteSchemaPermissions :: Schema.Options.RemoteSchemaPermissions,
|
|
|
|
soConnectionOptions :: WebSockets.ConnectionOptions,
|
2022-07-15 11:54:27 +03:00
|
|
|
soWebSocketKeepAlive :: KeepAliveDelay,
|
2022-08-17 04:07:44 +03:00
|
|
|
soInferFunctionPermissions :: Schema.Options.InferFunctionPermissions,
|
|
|
|
soEnableMaintenanceMode :: Server.Types.MaintenanceMode (),
|
2022-02-03 19:13:50 +03:00
|
|
|
soSchemaPollInterval :: OptionalInterval,
|
2022-08-04 06:21:55 +03:00
|
|
|
-- | See note '$experimentalFeatures'
|
2022-08-17 04:07:44 +03:00
|
|
|
soExperimentalFeatures :: HashSet Server.Types.ExperimentalFeature,
|
2022-09-21 21:01:48 +03:00
|
|
|
soEventsFetchBatchSize :: Refined NonNegative Int,
|
2023-02-08 05:57:08 +03:00
|
|
|
soDevMode :: DevModeStatus,
|
2023-02-28 12:09:31 +03:00
|
|
|
soAdminInternalErrors :: AdminInternalErrorsStatus,
|
2022-09-21 21:01:48 +03:00
|
|
|
soGracefulShutdownTimeout :: Refined NonNegative Seconds,
|
2022-07-15 11:54:27 +03:00
|
|
|
soWebSocketConnectionInitTimeout :: WSConnectionInitTimeout,
|
2022-08-17 04:07:44 +03:00
|
|
|
soEventingMode :: Server.Types.EventingMode,
|
2022-08-04 06:21:55 +03:00
|
|
|
-- | See note '$readOnlyMode'
|
2022-08-17 04:07:44 +03:00
|
|
|
soReadOnlyMode :: Server.Types.ReadOnlyMode,
|
|
|
|
soEnableMetadataQueryLogging :: Server.Logging.MetadataQueryLoggingMode,
|
2023-01-30 07:59:30 +03:00
|
|
|
soDefaultNamingConvention :: NamingCase,
|
2022-10-20 15:45:31 +03:00
|
|
|
soExtensionsSchema :: MonadTx.ExtensionsSchema,
|
2023-03-15 11:14:20 +03:00
|
|
|
soMetadataDefaults :: MetadataDefaults,
|
|
|
|
soApolloFederationStatus :: Server.Types.ApolloFederationStatus
|
2020-04-24 10:55:51 +03:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:28:49 +03:00
|
|
|
-- | 'ResponseInternalErrorsConfig' represents the encoding of the
|
|
|
|
-- internal errors in the response to the client.
|
|
|
|
--
|
|
|
|
-- For more details, see this github comment:
|
|
|
|
-- https://github.com/hasura/graphql-engine/issues/4031#issuecomment-609747705
|
2022-08-01 20:12:40 +03:00
|
|
|
data ResponseInternalErrorsConfig
|
|
|
|
= InternalErrorsAllRequests
|
|
|
|
| InternalErrorsAdminOnly
|
|
|
|
| InternalErrorsDisabled
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2023-04-24 11:50:29 +03:00
|
|
|
shouldIncludeInternal :: RoleName -> ResponseInternalErrorsConfig -> Bool
|
2022-08-01 20:12:40 +03:00
|
|
|
shouldIncludeInternal role = \case
|
|
|
|
InternalErrorsAllRequests -> True
|
2023-04-24 11:50:29 +03:00
|
|
|
InternalErrorsAdminOnly -> role == adminRoleName
|
2022-08-01 20:12:40 +03:00
|
|
|
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
|
2022-08-04 06:21:55 +03:00
|
|
|
{ dgoTargetVersion :: Text,
|
|
|
|
dgoDryRun :: Bool
|
2021-09-24 01:56:37 +03:00
|
|
|
}
|
|
|
|
deriving (Show, Eq)
|
|
|
|
|
2022-07-30 04:04:27 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-08-04 06:21:55 +03:00
|
|
|
-- $experimentalFeatures
|
|
|
|
-- Note Experimental features:
|
|
|
|
--
|
|
|
|
-- 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).
|
|
|
|
--
|
|
|
|
-- 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.
|
|
|
|
--
|
|
|
|
-- The experimental feature's flag is `--experimental-features` and the corresponding
|
|
|
|
-- environment variable is `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` which expects a comma-seperated
|
|
|
|
-- value.
|
|
|
|
--
|
|
|
|
-- 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:
|
|
|
|
--
|
|
|
|
-- 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-04 06:21:55 +03:00
|
|
|
--------------------------------------------------------------------------------
|
2022-07-30 04:04:27 +03:00
|
|
|
|
2022-08-04 06:21:55 +03:00
|
|
|
-- $readOnlyMode
|
|
|
|
-- Note ReadOnly Mode:
|
|
|
|
--
|
|
|
|
-- This mode starts the server in a (database) read-only mode. That is, only
|
|
|
|
-- read-only queries are allowed on users' database sources, and write
|
|
|
|
-- queries throw a runtime error. The use-case is for failsafe operations.
|
|
|
|
-- Metadata APIs are also disabled.
|
|
|
|
--
|
|
|
|
-- Following is the precise behaviour -
|
|
|
|
-- 1. For any GraphQL API (relay/hasura; http/websocket) - disable execution of
|
|
|
|
-- mutations
|
|
|
|
-- 2. Metadata API is disabled
|
|
|
|
-- 3. /v2/query API - insert, delete, update, run_sql are disabled
|
|
|
|
-- 4. /v1/query API - insert, delete, update, run_sql are disabled
|
|
|
|
-- 5. No source catalog migrations are run
|
|
|
|
-- 6. During build schema cache phase, building event triggers are disabled (as
|
|
|
|
-- they create corresponding database triggers)
|