2022-07-15 11:54:27 +03:00
-- | The Arg Parser for the 'serve' subcommand.
module Hasura.Server.Init.Arg.Command.Serve
2022-08-05 03:28:49 +03:00
( -- * Parser
serveCommandParser ,
-- * Options
servePortOption ,
serveHostOption ,
pgStripesOption ,
pgConnsOption ,
pgTimeoutOption ,
pgConnLifetimeOption ,
pgUsePreparedStatementsOption ,
pgPoolTimeoutOption ,
txIsolationOption ,
adminSecretOption ,
accessKeyOption ,
authHookOption ,
authHookModeOption ,
jwtSecretOption ,
unAuthRoleOption ,
corsDomainOption ,
disableCorsOption ,
enableConsoleOption ,
consoleAssetsDirOption ,
enableTelemetryOption ,
wsReadCookieOption ,
stringifyNumOption ,
dangerousBooleanCollapseOption ,
enabledAPIsOption ,
mxRefetchDelayOption ,
mxBatchSizeOption ,
streamingMxRefetchDelayOption ,
streamingMxBatchSizeOption ,
enableAllowlistOption ,
enabledLogsOption ,
logLevelOption ,
graphqlDevModeOption ,
graphqlAdminInternalErrorsOption ,
graphqlEventsHttpPoolSizeOption ,
graphqlEventsFetchIntervalOption ,
asyncActionsFetchIntervalOption ,
enableRemoteSchemaPermsOption ,
webSocketCompressionOption ,
webSocketKeepAliveOption ,
inferFunctionPermsOption ,
enableMaintenanceModeOption ,
schemaPollIntervalOption ,
experimentalFeaturesOption ,
eventsFetchBatchSizeOption ,
gracefulShutdownOption ,
webSocketConnectionInitTimeoutOption ,
enableMetadataQueryLoggingOption ,
defaultNamingConventionOption ,
2022-08-09 14:42:12 +03:00
metadataDBExtensionsSchemaOption ,
2022-08-05 03:28:49 +03:00
-- * Pretty Printer
serveCmdFooter ,
2022-07-15 11:54:27 +03:00
)
where
--------------------------------------------------------------------------------
import Data.HashSet qualified as Set
import Data.Text qualified as T
import Data.Time qualified as Time
import Database.PG.Query qualified as Query
2022-08-09 14:42:12 +03:00
import Hasura.Backends.Postgres.Connection.MonadTx ( ExtensionsSchema ( .. ) )
2022-07-15 11:54:27 +03:00
import Hasura.Cache.Bounded qualified as Cache
2022-08-05 03:28:49 +03:00
import Hasura.GraphQL.Execute.Subscription.Options ( RefetchInterval )
2022-07-15 11:54:27 +03:00
import Hasura.GraphQL.Execute.Subscription.Options qualified as ESO
import Hasura.GraphQL.Schema.NamingCase qualified as NC
2022-07-29 03:45:51 +03:00
import Hasura.GraphQL.Schema.Options qualified as Options
2022-07-15 11:54:27 +03:00
import Hasura.Logging qualified as L
import Hasura.Prelude
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.Init.Arg.PrettyPrinter qualified as PP
import Hasura.Server.Init.Config qualified as Config
import Hasura.Server.Init.Env qualified as Env
2022-07-29 03:45:51 +03:00
import Hasura.Server.Logging qualified as Logging
2022-07-15 11:54:27 +03:00
import Hasura.Server.Types qualified as Types
import Hasura.Session qualified as Session
import Network.Wai.Handler.Warp qualified as Warp
import Options.Applicative qualified as Opt
import Witch qualified
--------------------------------------------------------------------------------
-- Serve Command
2022-08-01 22:35:13 +03:00
serveCommandParser :: L . EnabledLogTypes impl => Opt . Parser ( Config . ServeOptionsRaw impl )
2022-07-15 11:54:27 +03:00
serveCommandParser =
2022-08-01 22:35:13 +03:00
Config . ServeOptionsRaw
2022-07-15 11:54:27 +03:00
<$> parseServerPort
<*> parseServerHost
<*> parseConnParams
<*> parseTxIsolation
<*> ( parseAdminSecret <|> parseAccessKey )
<*> parseAuthHook
<*> parseJwtSecret
<*> parseUnAuthRole
<*> parseCorsConfig
<*> parseEnableConsole
<*> parseConsoleAssetsDir
<*> parseEnableTelemetry
<*> parseWsReadCookie
<*> parseStringifyNum
<*> parseDangerousBooleanCollapse
<*> parseEnabledAPIs
<*> parseMxRefetchDelay
<*> parseMxBatchSize
<*> parseStreamingMxRefetchDelay
<*> parseStreamingMxBatchSize
<*> parseEnableAllowlist
<*> parseEnabledLogs
<*> parseLogLevel
<* parsePlanCacheSize -- parsed (for backwards compatibility reasons) but ignored
<*> parseGraphqlDevMode
<*> parseGraphqlAdminInternalErrors
<*> parseGraphqlEventsHttpPoolSize
<*> parseGraphqlEventsFetchInterval
<*> parseGraphqlAsyncActionsFetchInterval
<*> parseEnableRemoteSchemaPerms
<*> parseWebSocketCompression
<*> parseWebSocketKeepAlive
<*> parseInferFunctionPerms
<*> parseEnableMaintenanceMode
<*> parseSchemaPollInterval
<*> parseExperimentalFeatures
<*> parseEventsFetchBatchSize
<*> parseGracefulShutdownTimeout
<*> parseWebSocketConnectionInitTimeout
<*> parseEnableMetadataQueryLogging
<*> parseDefaultNamingConvention
2022-08-09 14:42:12 +03:00
<*> parseExtensionsSchema
2022-07-15 11:54:27 +03:00
--------------------------------------------------------------------------------
-- Serve Options
-- TODO(SOLOMON): Review, currently accepts negative integers
parseServerPort :: Opt . Parser ( Maybe Int )
parseServerPort =
Opt . optional $
Opt . option
Opt . auto
( Opt . long " server-port "
<> Opt . metavar " <PORT> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage servePortOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
servePortOption :: Config . Option Int
servePortOption =
Config . Option
{ _default = 8080 ,
_envVar = " HASURA_GRAPHQL_SERVER_PORT " ,
_helpMessage = " Port on which graphql-engine should be served (default: 8080) "
}
2022-07-15 11:54:27 +03:00
parseServerHost :: Opt . Parser ( Maybe Warp . HostPreference )
parseServerHost =
Opt . optional $
Opt . strOption
( Opt . long " server-host "
<> Opt . metavar " <HOST> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage serveHostOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
serveHostOption :: Config . Option Warp . HostPreference
serveHostOption =
Config . Option
{ _default = " * " ,
_envVar = " HASURA_GRAPHQL_SERVER_HOST " ,
_helpMessage = " Host on which graphql-engine will listen (default: *) "
}
2022-07-15 11:54:27 +03:00
2022-08-01 22:35:13 +03:00
parseConnParams :: Opt . Parser Config . ConnParamsRaw
2022-07-15 11:54:27 +03:00
parseConnParams =
2022-08-05 03:28:49 +03:00
Config . ConnParamsRaw <$> pgStripes <*> pgConns <*> pgTimeout <*> pgConnLifetime <*> pgUsePreparedStatements <*> pgPoolTimeout
2022-07-15 11:54:27 +03:00
where
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-08-05 03:28:49 +03:00
pgStripes :: Opt . Parser ( Maybe Int )
2022-07-15 11:54:27 +03:00
pgStripes =
Opt . optional $
Opt . option
Opt . auto
( Opt . long " stripes "
<> Opt . short 's'
<> Opt . metavar " <NO OF STRIPES> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage pgStripesOption )
2022-07-15 11:54:27 +03:00
)
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-08-05 03:28:49 +03:00
pgConns :: Opt . Parser ( Maybe Int )
2022-07-15 11:54:27 +03:00
pgConns =
Opt . optional $
Opt . option
Opt . auto
( Opt . long " connections "
<> Opt . short 'c'
<> Opt . metavar " <NO OF CONNS> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage pgConnsOption )
2022-07-15 11:54:27 +03:00
)
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-08-05 03:28:49 +03:00
pgTimeout :: Opt . Parser ( Maybe Int )
pgTimeout =
2022-07-15 11:54:27 +03:00
Opt . optional $
Opt . option
Opt . auto
( Opt . long " timeout "
<> Opt . metavar " <SECONDS> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage pgTimeoutOption )
2022-07-15 11:54:27 +03:00
)
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-08-05 03:28:49 +03:00
pgConnLifetime :: Opt . Parser ( Maybe Time . NominalDiffTime )
2022-07-15 11:54:27 +03:00
pgConnLifetime =
fmap ( fmap ( realToFrac :: Int -> Time . NominalDiffTime ) ) $
Opt . optional $
Opt . option
Opt . auto
( Opt . long " conn-lifetime "
<> Opt . metavar " <SECONDS> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage pgConnLifetimeOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
pgUsePreparedStatements :: Opt . Parser ( Maybe Bool )
pgUsePreparedStatements =
2022-07-15 11:54:27 +03:00
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " use-prepared-statements "
<> Opt . metavar " <true|false> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage pgUsePreparedStatementsOption )
2022-07-15 11:54:27 +03:00
)
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-08-05 03:28:49 +03:00
pgPoolTimeout :: Opt . Parser ( Maybe Time . NominalDiffTime )
2022-07-15 11:54:27 +03:00
pgPoolTimeout =
fmap ( fmap ( realToFrac :: Int -> Time . NominalDiffTime ) ) $
Opt . optional $
Opt . option
Opt . auto
( Opt . long " pool-timeout "
<> Opt . metavar " <SECONDS> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage pgPoolTimeoutOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
pgStripesOption :: Config . Option Int
pgStripesOption =
Config . Option
{ _default = 1 ,
_envVar = " HASURA_GRAPHQL_PG_STRIPES " ,
_helpMessage =
" Number of stripes (distinct sub-pools) to maintain with Postgres (default: 1). "
<> " New connections will be taken from a particular stripe pseudo-randomly. "
}
pgConnsOption :: Config . Option Int
pgConnsOption =
Config . Option
{ _default = 50 ,
_envVar = " HASURA_GRAPHQL_PG_CONNECTIONS " ,
_helpMessage =
" Maximum number of Postgres connections that can be opened per stripe (default: 50). "
<> " When the maximum is reached we will block until a new connection becomes available, "
<> " even if there is capacity in other stripes. "
}
pgTimeoutOption :: Config . Option Int
pgTimeoutOption =
Config . Option
{ _default = 180 ,
_envVar = " HASURA_GRAPHQL_PG_TIMEOUT " ,
_helpMessage = " Each connection's idle time before it is closed (default: 180 sec) "
}
pgConnLifetimeOption :: Config . Option Time . NominalDiffTime
pgConnLifetimeOption =
Config . Option
{ _default = 600 ,
_envVar = " HASURA_GRAPHQL_PG_CONN_LIFETIME " ,
_helpMessage =
" Time from connection creation after which the connection should be destroyed and a new one "
<> " created. A value of 0 indicates we should never destroy an active connection. If 0 is "
<> " passed, memory from large query results may not be reclaimed. (default: 600 sec) "
}
pgUsePreparedStatementsOption :: Config . Option Bool
pgUsePreparedStatementsOption =
Config . Option
{ _default = True ,
_envVar = " HASURA_GRAPHQL_USE_PREPARED_STATEMENTS " ,
_helpMessage = " Use prepared statements for queries (default: true) "
}
pgPoolTimeoutOption :: Config . Option ()
pgPoolTimeoutOption =
Config . Option
{ _default = () ,
_envVar = " HASURA_GRAPHQL_PG_POOL_TIMEOUT " ,
_helpMessage = " How long to wait when acquiring a Postgres connection, in seconds (default: forever). "
}
2022-07-15 11:54:27 +03:00
parseTxIsolation :: Opt . Parser ( Maybe Query . TxIsolation )
parseTxIsolation =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " tx-iso "
<> Opt . short 'i'
<> Opt . metavar " <TXISO> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage txIsolationOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
txIsolationOption :: Config . Option Query . TxIsolation
txIsolationOption =
Config . Option
{ Config . _default = Query . ReadCommitted ,
Config . _envVar = " HASURA_GRAPHQL_TX_ISOLATION " ,
Config . _helpMessage = " transaction isolation. read-committed / repeatable-read / serializable (default: read-commited) "
}
2022-07-15 11:54:27 +03:00
parseAdminSecret :: Opt . Parser ( Maybe Auth . AdminSecretHash )
parseAdminSecret =
Opt . optional $
Auth . hashAdminSecret
<$> Opt . strOption
( Opt . long " admin-secret "
<> Opt . metavar " ADMIN SECRET KEY "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage adminSecretOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
adminSecretOption :: Config . Option ()
adminSecretOption =
Config . Option
{ Config . _default = () ,
Config . _envVar = " HASURA_GRAPHQL_ADMIN_SECRET " ,
Config . _helpMessage = " Admin Secret key, required to access this instance "
}
2022-07-15 11:54:27 +03:00
parseAccessKey :: Opt . Parser ( Maybe Auth . AdminSecretHash )
parseAccessKey =
Opt . optional $
Auth . hashAdminSecret
<$> Opt . strOption
( Opt . long " access-key "
<> Opt . metavar " ADMIN SECRET KEY (DEPRECATED: USE --admin-secret) "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage accessKeyOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
accessKeyOption :: Config . Option ()
accessKeyOption =
Config . Option
{ Config . _default = () ,
Config . _envVar = " HASURA_GRAPHQL_ACCESS_KEY " ,
Config . _helpMessage = " Admin secret key, required to access this instance (deprecated: use HASURA_GRAPHQL_ADMIN_SECRET instead) "
}
2022-07-15 11:54:27 +03:00
2022-08-01 22:35:13 +03:00
parseAuthHook :: Opt . Parser Config . AuthHookRaw
2022-07-15 11:54:27 +03:00
parseAuthHook =
2022-08-04 05:24:35 +03:00
Config . AuthHookRaw <$> url <*> urlType
2022-07-15 11:54:27 +03:00
where
url =
Opt . optional $
Opt . strOption
( Opt . long " auth-hook "
<> Opt . metavar " <WEB HOOK URL> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage authHookOption )
2022-07-15 11:54:27 +03:00
)
urlType =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " auth-hook-mode "
<> Opt . metavar " <GET|POST> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage authHookModeOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
authHookOption :: Config . Option ()
authHookOption =
Config . Option
{ Config . _default = () ,
Config . _envVar = " HASURA_GRAPHQL_AUTH_HOOK " ,
Config . _helpMessage = " URL of the authorization webhook required to authorize requests "
}
authHookModeOption :: Config . Option Auth . AuthHookType
authHookModeOption =
Config . Option
{ Config . _default = Auth . AHTGet ,
Config . _envVar = " HASURA_GRAPHQL_AUTH_HOOK_MODE " ,
Config . _helpMessage = " HTTP method to use for authorization webhook (default: GET) "
}
2022-07-15 11:54:27 +03:00
parseJwtSecret :: Opt . Parser ( Maybe Auth . JWTConfig )
parseJwtSecret =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " jwt-secret "
<> Opt . metavar " <JSON CONFIG> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage jwtSecretOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
jwtSecretOption :: Config . Option ()
jwtSecretOption =
Config . Option
{ Config . _default = () ,
Config . _envVar = " HASURA_GRAPHQL_JWT_SECRET " ,
Config . _helpMessage =
" The JSON containing type and the JWK used for verifying. e.g: "
<> " `{ \ " type \ " : \ " HS256 \ " , \ " key \ " : \ " <your-hmac-shared-secret> \ " , \ " claims_namespace \ " : \ " <optional-custom-claims-key-name> \ " }`, "
<> " `{ \ " type \ " : \ " RS256 \ " , \ " key \ " : \ " <your-PEM-RSA-public-key> \ " , \ " claims_namespace \ " : \ " <optional-custom-claims-key-name> \ " }` "
}
2022-07-15 11:54:27 +03:00
parseUnAuthRole :: Opt . Parser ( Maybe Session . RoleName )
parseUnAuthRole =
fmap mkRoleName $
Opt . optional $
Opt . strOption
( Opt . long " unauthorized-role "
<> Opt . metavar " <ROLE> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage unAuthRoleOption )
2022-07-15 11:54:27 +03:00
)
where
mkRoleName mText = mText >>= Session . mkRoleName
2022-08-05 03:28:49 +03:00
unAuthRoleOption :: Config . Option ()
unAuthRoleOption =
Config . Option
{ Config . _default = () ,
Config . _envVar = " HASURA_GRAPHQL_UNAUTHORIZED_ROLE " ,
Config . _helpMessage =
" Unauthorized role, used when admin-secret is not sent in admin-secret only mode "
++ " or \ " Authorization \ " header is absent in JWT mode "
}
2022-07-15 11:54:27 +03:00
parseCorsConfig :: Opt . Parser ( Maybe Cors . CorsConfig )
parseCorsConfig = mapCC <$> disableCors <*> corsDomain
where
corsDomain =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " cors-domain "
<> Opt . metavar " <DOMAINS> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage corsDomainOption )
2022-07-15 11:54:27 +03:00
)
disableCors =
Opt . switch
( Opt . long " disable-cors "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage disableCorsOption )
2022-07-15 11:54:27 +03:00
)
mapCC isDisabled domains =
bool domains ( Just $ Cors . CCDisabled False ) isDisabled
2022-08-05 03:28:49 +03:00
corsDomainOption :: Config . Option Cors . CorsConfig
corsDomainOption =
Config . Option
{ Config . _default = Cors . CCAllowAll ,
Config . _envVar = " HASURA_GRAPHQL_CORS_DOMAIN " ,
Config . _helpMessage =
" CSV of list of domains, excluding scheme (http/https) and including port, "
++ " to allow CORS for. Wildcard domains are allowed. See docs for details. "
}
disableCorsOption :: Config . Option Bool
disableCorsOption =
Config . Option
{ Config . _default = False ,
Config . _envVar = " HASURA_GRAPHQL_DISABLE_CORS " ,
Config . _helpMessage = " Disable CORS. Do not send any CORS headers on any request "
}
2022-07-15 11:54:27 +03:00
parseEnableConsole :: Opt . Parser Bool
parseEnableConsole =
Opt . switch
( Opt . long " enable-console "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage enableConsoleOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
enableConsoleOption :: Config . Option Bool
enableConsoleOption =
Config . Option
{ Config . _default = False ,
Config . _envVar = " HASURA_GRAPHQL_ENABLE_CONSOLE " ,
Config . _helpMessage = " Enable API Console (default: false) "
}
2022-07-15 11:54:27 +03:00
parseConsoleAssetsDir :: Opt . Parser ( Maybe Text )
parseConsoleAssetsDir =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " console-assets-dir "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage consoleAssetsDirOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
consoleAssetsDirOption :: Config . Option ()
consoleAssetsDirOption =
Config . Option
{ Config . _default = () ,
Config . _envVar = " HASURA_GRAPHQL_CONSOLE_ASSETS_DIR " ,
Config . _helpMessage =
" A directory from which static assets required for console is served at "
++ " '/console/assets' path. Can be set to '/srv/console-assets' on the "
++ " default docker image to disable loading assets from CDN. "
}
2022-07-15 11:54:27 +03:00
-- NOTE: Should this be an 'Opt.flag'?
parseEnableTelemetry :: Opt . Parser ( Maybe Bool )
parseEnableTelemetry =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " enable-telemetry "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage enableTelemetryOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
enableTelemetryOption :: Config . Option Bool
enableTelemetryOption =
Config . Option
{ _default = True ,
_envVar = " HASURA_GRAPHQL_ENABLE_TELEMETRY " ,
-- TODO (from master): better description
_helpMessage = " Enable anonymous telemetry (default: true) "
}
2022-07-15 11:54:27 +03:00
parseWsReadCookie :: Opt . Parser Bool
parseWsReadCookie =
Opt . switch
( Opt . long " ws-read-cookie "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage wsReadCookieOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
wsReadCookieOption :: Config . Option Bool
wsReadCookieOption =
Config . Option
{ Config . _default = False ,
Config . _envVar = " HASURA_GRAPHQL_WS_READ_COOKIE " ,
Config . _helpMessage =
" Read cookie on WebSocket initial handshake, even when CORS is disabled. "
++ " This can be a potential security flaw! Please make sure you know "
++ " what you're doing. "
++ " This configuration is only applicable when CORS is disabled. "
}
2022-07-15 11:54:27 +03:00
2022-07-29 03:45:51 +03:00
parseStringifyNum :: Opt . Parser Options . StringifyNumbers
2022-07-15 11:54:27 +03:00
parseStringifyNum =
2022-07-29 03:45:51 +03:00
fmap ( bool Options . Don'tStringifyNumbers Options . StringifyNumbers ) $
Opt . switch
( Opt . long " stringify-numeric-types "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage stringifyNumOption )
2022-07-29 03:45:51 +03:00
)
2022-07-15 11:54:27 +03:00
2022-08-05 03:28:49 +03:00
stringifyNumOption :: Config . Option Options . StringifyNumbers
stringifyNumOption =
Config . Option
{ Config . _default = Options . Don'tStringifyNumbers ,
Config . _envVar = " HASURA_GRAPHQL_STRINGIFY_NUMERIC_TYPES " ,
Config . _helpMessage = " Stringify numeric types (default: false) "
}
2022-07-15 11:54:27 +03:00
parseDangerousBooleanCollapse :: Opt . Parser ( Maybe Bool )
parseDangerousBooleanCollapse =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " v1-boolean-null-collapse "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage dangerousBooleanCollapseOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
dangerousBooleanCollapseOption :: Config . Option Bool
dangerousBooleanCollapseOption =
Config . Option
{ Config . _default = False ,
Config . _envVar = " HASURA_GRAPHQL_V1_BOOLEAN_NULL_COLLAPSE " ,
Config . _helpMessage =
" Emulate V1's behaviour re. boolean expression, where an explicit 'null' "
<> " value will be interpreted to mean that the field should be ignored "
<> " [DEPRECATED, WILL BE REMOVED SOON] (default: false) "
}
parseEnabledAPIs :: Opt . Parser ( Maybe ( HashSet Config . API ) )
2022-07-15 11:54:27 +03:00
parseEnabledAPIs =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " enabled-apis "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage enabledAPIsOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
enabledAPIsOption :: Config . Option ( HashSet Config . API )
enabledAPIsOption =
Config . Option
{ Config . _default = Set . fromList [ Config . METADATA , Config . GRAPHQL , Config . PGDUMP , Config . CONFIG ] ,
Config . _envVar = " HASURA_GRAPHQL_ENABLED_APIS " ,
Config . _helpMessage = " Comma separated list of enabled APIs. (default: metadata,graphql,pgdump,config) "
}
2022-07-15 11:54:27 +03:00
parseMxRefetchDelay :: Opt . Parser ( Maybe ESO . RefetchInterval )
parseMxRefetchDelay =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " live-queries-multiplexed-refetch-interval "
<> Opt . metavar " <INTERVAL(ms)> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _envVar mxRefetchDelayOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
mxRefetchDelayOption :: Config . Option RefetchInterval
mxRefetchDelayOption =
Config . Option
{ Config . _default = ESO . RefetchInterval 1 ,
Config . _envVar = " HASURA_GRAPHQL_LIVE_QUERIES_MULTIPLEXED_REFETCH_INTERVAL " ,
Config . _helpMessage =
" results will only be sent once in this interval (in milliseconds) for "
<> " live queries which can be multiplexed. Default: 1000 (1sec) "
}
2022-07-15 11:54:27 +03:00
parseMxBatchSize :: Opt . Parser ( Maybe ESO . BatchSize )
parseMxBatchSize =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " live-queries-multiplexed-batch-size "
<> Opt . metavar " BATCH_SIZE "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage mxBatchSizeOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
mxBatchSizeOption :: Config . Option ESO . BatchSize
mxBatchSizeOption =
Config . Option
{ _default = ESO . BatchSize 100 ,
_envVar = " HASURA_GRAPHQL_LIVE_QUERIES_MULTIPLEXED_BATCH_SIZE " ,
_helpMessage =
" multiplexed live queries are split into batches of the specified "
<> " size. Default 100. "
}
2022-07-15 11:54:27 +03:00
parseStreamingMxRefetchDelay :: Opt . Parser ( Maybe ESO . RefetchInterval )
parseStreamingMxRefetchDelay =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " streaming-queries-multiplexed-refetch-interval "
<> Opt . metavar " <INTERVAL(ms)> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage streamingMxRefetchDelayOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
streamingMxRefetchDelayOption :: Config . Option ESO . RefetchInterval
streamingMxRefetchDelayOption =
Config . Option
{ Config . _default = ESO . RefetchInterval 1 ,
Config . _envVar = " HASURA_GRAPHQL_STREAMING_QUERIES_MULTIPLEXED_REFETCH_INTERVAL " ,
Config . _helpMessage =
" results will only be sent once in this interval (in milliseconds) for "
<> " streaming queries which can be multiplexed. Default: 1000 (1sec) "
}
2022-07-15 11:54:27 +03:00
parseStreamingMxBatchSize :: Opt . Parser ( Maybe ESO . BatchSize )
parseStreamingMxBatchSize =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " streaming-queries-multiplexed-batch-size "
<> Opt . metavar " BATCH_SIZE "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage streamingMxBatchSizeOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
streamingMxBatchSizeOption :: Config . Option ESO . BatchSize
streamingMxBatchSizeOption =
Config . Option
{ Config . _default = ESO . BatchSize 100 ,
Config . _envVar = " HASURA_GRAPHQL_STREAMING_QUERIES_MULTIPLEXED_BATCH_SIZE " ,
Config . _helpMessage =
" multiplexed live queries are split into batches of the specified "
<> " size. Default 100. "
}
2022-07-15 11:54:27 +03:00
parseEnableAllowlist :: Opt . Parser Bool
parseEnableAllowlist =
Opt . switch
( Opt . long " enable-allowlist "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage enableAllowlistOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
enableAllowlistOption :: Config . Option Bool
enableAllowlistOption =
Config . Option
{ Config . _default = False ,
Config . _envVar = " HASURA_GRAPHQL_ENABLE_ALLOWLIST " ,
Config . _helpMessage = " Only accept allowed GraphQL queries "
}
2022-07-15 11:54:27 +03:00
2022-08-05 03:28:49 +03:00
parseEnabledLogs :: forall impl . L . EnabledLogTypes impl => Opt . Parser ( Maybe ( HashSet ( L . EngineLogType impl ) ) )
2022-07-15 11:54:27 +03:00
parseEnabledLogs =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " enabled-log-types "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage ( enabledLogsOption @ impl ) )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
enabledLogsOption :: L . EnabledLogTypes impl => Config . Option ( HashSet ( L . EngineLogType impl ) )
enabledLogsOption =
Config . Option
{ Config . _default = L . defaultEnabledLogTypes ,
Config . _envVar = " HASURA_GRAPHQL_ENABLED_LOG_TYPES " ,
Config . _helpMessage =
" Comma separated list of enabled log types "
<> " (default: "
<> defaultLogTypes
<> " ) "
<> " (all: "
<> allAllowedLogTypes
<> " ) "
}
2022-07-15 11:54:27 +03:00
where
defaultLogTypes = T . unpack . T . intercalate " , " $ Witch . into @ Text <$> Set . toList L . defaultEnabledEngineLogTypes
allAllowedLogTypes = T . unpack . T . intercalate " , " $ Witch . into @ Text <$> L . userAllowedLogTypes
parseLogLevel :: Opt . Parser ( Maybe L . LogLevel )
parseLogLevel =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " log-level "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage logLevelOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
logLevelOption :: Config . Option L . LogLevel
logLevelOption =
Config . Option
{ Config . _default = L . LevelInfo ,
Config . _envVar = " HASURA_GRAPHQL_LOG_LEVEL " ,
Config . _helpMessage = " Server log level (default: info) (all: error, warn, info, debug) "
}
2022-07-15 11:54:27 +03:00
parsePlanCacheSize :: Opt . Parser ( Maybe Cache . CacheSize )
parsePlanCacheSize =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " query-plan-cache-size "
<> Opt . help
( " [DEPRECATED: value ignored.] The maximum number of query plans "
<> " that can be cached, allowed values: 0-65535, "
<> " 0 disables the cache. Default 4000 "
)
)
parseGraphqlDevMode :: Opt . Parser Bool
parseGraphqlDevMode =
Opt . switch
( Opt . long " dev-mode "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage graphqlDevModeOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
graphqlDevModeOption :: Config . Option Bool
graphqlDevModeOption =
Config . Option
{ Config . _default = False ,
Config . _envVar = " HASURA_GRAPHQL_DEV_MODE " ,
Config . _helpMessage = " Set dev mode for GraphQL requests; include 'internal' key in the errors extensions (if required) of the response "
}
2022-07-15 11:54:27 +03:00
parseGraphqlAdminInternalErrors :: Opt . Parser ( Maybe Bool )
parseGraphqlAdminInternalErrors =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " admin-internal-errors "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage graphqlAdminInternalErrorsOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
graphqlAdminInternalErrorsOption :: Config . Option Bool
graphqlAdminInternalErrorsOption =
Config . Option
{ -- Default to `true` to enable backwards compatibility
Config . _default = True ,
Config . _envVar = " HASURA_GRAPHQL_ADMIN_INTERNAL_ERRORS " ,
Config . _helpMessage = " Enables including 'internal' information in an error response for requests made by an 'admin' (default: true) "
}
2022-07-15 11:54:27 +03:00
-- TODO(SOLOMON): Review, currently accepts negative integers
parseGraphqlEventsHttpPoolSize :: Opt . Parser ( Maybe Int )
parseGraphqlEventsHttpPoolSize =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " events-http-pool-size "
2022-08-05 03:28:49 +03:00
<> Opt . metavar ( Config . _envVar graphqlEventsHttpPoolSizeOption )
<> Opt . help ( Config . _helpMessage graphqlEventsHttpPoolSizeOption )
2022-07-15 11:54:27 +03:00
)
2022-08-10 22:17:05 +03:00
graphqlEventsHttpPoolSizeOption :: Config . Option Int
2022-08-05 03:28:49 +03:00
graphqlEventsHttpPoolSizeOption =
Config . Option
2022-08-10 22:17:05 +03:00
{ Config . _default = 100 ,
2022-08-05 03:28:49 +03:00
Config . _envVar = " HASURA_GRAPHQL_EVENTS_HTTP_POOL_SIZE " ,
Config . _helpMessage = " Max event processing threads (default: 100) "
}
2022-07-15 11:54:27 +03:00
-- TODO(SOLOMON): Review, currently accepts negative integers
parseGraphqlEventsFetchInterval :: Opt . Parser ( Maybe Milliseconds )
parseGraphqlEventsFetchInterval =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " events-fetch-interval "
2022-08-05 03:28:49 +03:00
<> Opt . metavar ( Config . _envVar graphqlEventsFetchIntervalOption )
<> Opt . help ( Config . _helpMessage graphqlEventsFetchIntervalOption )
2022-07-15 11:54:27 +03:00
)
2022-08-10 22:17:05 +03:00
graphqlEventsFetchIntervalOption :: Config . Option Milliseconds
2022-08-05 03:28:49 +03:00
graphqlEventsFetchIntervalOption =
Config . Option
2022-08-10 22:17:05 +03:00
{ Config . _default = Milliseconds ( seconds 1 ) ,
2022-08-05 03:28:49 +03:00
Config . _envVar = " HASURA_GRAPHQL_EVENTS_FETCH_INTERVAL " ,
2022-08-10 22:17:05 +03:00
Config . _helpMessage = " Interval in milliseconds to sleep before trying to fetch events again after a fetch returned no events from postgres (default: 1 second). "
2022-08-05 03:28:49 +03:00
}
2022-07-15 11:54:27 +03:00
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-07-29 03:45:51 +03:00
parseGraphqlAsyncActionsFetchInterval :: Opt . Parser ( Maybe Config . OptionalInterval )
2022-07-15 11:54:27 +03:00
parseGraphqlAsyncActionsFetchInterval =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " async-actions-fetch-interval "
2022-08-05 03:28:49 +03:00
<> Opt . metavar ( Config . _envVar asyncActionsFetchIntervalOption )
<> Opt . help ( Config . _helpMessage asyncActionsFetchIntervalOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
asyncActionsFetchIntervalOption :: Config . Option Config . OptionalInterval
asyncActionsFetchIntervalOption =
Config . Option
{ Config . _default = Config . Interval 1000 ,
Config . _envVar = " HASURA_GRAPHQL_ASYNC_ACTIONS_FETCH_INTERVAL " ,
Config . _helpMessage =
" Interval in milliseconds to sleep before trying to fetch new async actions. "
++ " Value \ " 0 \ " implies completely disable fetching async actions from storage. "
++ " Default 1000 milliseconds "
}
2022-07-15 11:54:27 +03:00
2022-07-29 03:45:51 +03:00
parseEnableRemoteSchemaPerms :: Opt . Parser Options . RemoteSchemaPermissions
2022-07-15 11:54:27 +03:00
parseEnableRemoteSchemaPerms =
2022-07-29 03:45:51 +03:00
fmap ( bool Options . DisableRemoteSchemaPermissions Options . EnableRemoteSchemaPermissions ) $
Opt . switch
( Opt . long " enable-remote-schema-permissions "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage enableRemoteSchemaPermsOption )
2022-07-29 03:45:51 +03:00
)
2022-07-15 11:54:27 +03:00
2022-08-05 03:28:49 +03:00
enableRemoteSchemaPermsOption :: Config . Option Options . RemoteSchemaPermissions
enableRemoteSchemaPermsOption =
Config . Option
{ Config . _default = Options . DisableRemoteSchemaPermissions ,
Config . _envVar = " HASURA_GRAPHQL_ENABLE_REMOTE_SCHEMA_PERMISSIONS " ,
Config . _helpMessage = " Enables remote schema permissions (default: false) "
}
2022-07-15 11:54:27 +03:00
parseWebSocketCompression :: Opt . Parser Bool
parseWebSocketCompression =
Opt . switch
( Opt . long " websocket-compression "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage webSocketCompressionOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
webSocketCompressionOption :: Config . Option Bool
webSocketCompressionOption =
Config . Option
{ Config . _default = False ,
Config . _envVar = " HASURA_GRAPHQL_CONNECTION_COMPRESSION " ,
Config . _helpMessage = " Enable WebSocket permessage-deflate compression (default: false) "
}
2022-07-15 11:54:27 +03:00
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-07-29 03:45:51 +03:00
parseWebSocketKeepAlive :: Opt . Parser ( Maybe Config . KeepAliveDelay )
2022-07-15 11:54:27 +03:00
parseWebSocketKeepAlive =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " websocket-keepalive "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage webSocketKeepAliveOption )
2022-07-15 11:54:27 +03:00
)
-- NOTE: this is purely used by Apollo-Subscription-Transport-WS
2022-08-05 03:28:49 +03:00
webSocketKeepAliveOption :: Config . Option Config . KeepAliveDelay
webSocketKeepAliveOption =
Config . Option
{ Config . _default = Config . KeepAliveDelay ( fromIntegral @ Int 5 ) ,
Config . _envVar = " HASURA_GRAPHQL_WEBSOCKET_KEEPALIVE " ,
Config . _helpMessage = " Control websocket keep-alive timeout (default 5 seconds) "
}
2022-07-15 11:54:27 +03:00
2022-07-29 03:45:51 +03:00
parseInferFunctionPerms :: Opt . Parser ( Maybe Options . InferFunctionPermissions )
2022-07-15 11:54:27 +03:00
parseInferFunctionPerms =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " infer-function-permissions "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage inferFunctionPermsOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
inferFunctionPermsOption :: Config . Option Options . InferFunctionPermissions
inferFunctionPermsOption =
Config . Option
{ Config . _default = Options . InferFunctionPermissions ,
Config . _envVar = " HASURA_GRAPHQL_INFER_FUNCTION_PERMISSIONS " ,
Config . _helpMessage = " Infers function permissions (default: true) "
}
2022-07-15 11:54:27 +03:00
2022-07-29 03:45:51 +03:00
parseEnableMaintenanceMode :: Opt . Parser ( Types . MaintenanceMode () )
2022-07-15 11:54:27 +03:00
parseEnableMaintenanceMode =
2022-07-29 03:45:51 +03:00
fmap ( bool Types . MaintenanceModeDisabled ( Types . MaintenanceModeEnabled () ) ) $
Opt . switch
( Opt . long " enable-maintenance-mode "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage enableMaintenanceModeOption )
2022-07-29 03:45:51 +03:00
)
2022-07-15 11:54:27 +03:00
2022-08-05 03:28:49 +03:00
enableMaintenanceModeOption :: Config . Option ( Types . MaintenanceMode () )
enableMaintenanceModeOption =
Config . Option
{ Config . _default = Types . MaintenanceModeDisabled ,
Config . _envVar = " HASURA_GRAPHQL_ENABLE_MAINTENANCE_MODE " ,
Config . _helpMessage = " Flag to enable maintenance mode in the graphql-engine "
}
2022-07-15 11:54:27 +03:00
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-08-05 03:28:49 +03:00
parseSchemaPollInterval :: Opt . Parser ( Maybe Config . OptionalInterval )
2022-07-15 11:54:27 +03:00
parseSchemaPollInterval =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " schema-sync-poll-interval "
2022-08-05 03:28:49 +03:00
<> Opt . metavar ( Config . _envVar schemaPollIntervalOption )
<> Opt . help ( Config . _helpMessage schemaPollIntervalOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
schemaPollIntervalOption :: Config . Option Config . OptionalInterval
schemaPollIntervalOption =
Config . Option
{ -- 1000 Milliseconds or 1 Second
Config . _default = Config . Interval 1000 ,
Config . _envVar = " HASURA_GRAPHQL_SCHEMA_SYNC_POLL_INTERVAL " ,
Config . _helpMessage = " Interval to poll metadata storage for updates in milliseconds - Default 1000 (1s) - Set to 0 to disable "
}
2022-07-15 11:54:27 +03:00
2022-08-05 03:28:49 +03:00
parseExperimentalFeatures :: Opt . Parser ( Maybe ( HashSet Types . ExperimentalFeature ) )
2022-07-15 11:54:27 +03:00
parseExperimentalFeatures =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " experimental-features "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage experimentalFeaturesOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
experimentalFeaturesOption :: Config . Option ( HashSet Types . ExperimentalFeature )
experimentalFeaturesOption =
Config . Option
{ Config . _default = Set . empty ,
Config . _envVar = " HASURA_GRAPHQL_EXPERIMENTAL_FEATURES " ,
Config . _helpMessage =
" Comma separated list of experimental features. (all: inherited_roles,optimize_permission_filters and naming_convention, streaming_subscriptions, apollo_federation). "
<> " optimize_permission_filters: Use experimental SQL optimization "
<> " transformations for permission filters. "
<> " inherited_roles: ignored; inherited roles cannot be switched off "
<> " naming_convention: apply naming convention (graphql-default/hasura-default) based on source customization "
<> " apollo_federation: use hasura as a subgraph in an Apollo gateway "
<> " streaming_subscriptions: A streaming subscription streams the response according to the cursor provided by the user "
}
2022-07-15 11:54:27 +03:00
parseEventsFetchBatchSize :: Opt . Parser ( Maybe Common . NonNegativeInt )
parseEventsFetchBatchSize =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " events-fetch-batch-size "
2022-08-05 03:28:49 +03:00
<> Opt . metavar ( Config . _envVar eventsFetchBatchSizeOption )
<> Opt . help ( Config . _helpMessage eventsFetchBatchSizeOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
eventsFetchBatchSizeOption :: Config . Option Common . NonNegativeInt
eventsFetchBatchSizeOption =
Config . Option
{ Config . _default = Common . unsafeNonNegativeInt 100 ,
Config . _envVar = " HASURA_GRAPHQL_EVENTS_FETCH_BATCH_SIZE " ,
Config . _helpMessage =
" The maximum number of events to be fetched from the events table in a single batch. Default 100 "
++ " Value \ " 0 \ " implies completely disable fetching events from events table. "
}
2022-07-15 11:54:27 +03:00
-- TODO(SOLOMON): Review, currently accepts negative integers
parseGracefulShutdownTimeout :: Opt . Parser ( Maybe Seconds )
parseGracefulShutdownTimeout =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " graceful-shutdown-timeout "
<> Opt . metavar " <INTERVAL (seconds)> "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage gracefulShutdownOption )
2022-07-15 11:54:27 +03:00
)
2022-08-05 03:28:49 +03:00
gracefulShutdownOption :: Config . Option Seconds
gracefulShutdownOption =
Config . Option
{ Config . _default = 60 ,
Config . _envVar = " HASURA_GRAPHQL_GRACEFUL_SHUTDOWN_TIMEOUT " ,
Config . _helpMessage =
" Timeout for graceful shutdown before which in-flight scheduled events, "
<> " cron events and async actions to complete (default: 60 seconds) "
}
2022-07-15 11:54:27 +03:00
-- TODO(SOLOMON): Review, currently accepts negative integers
2022-07-29 03:45:51 +03:00
parseWebSocketConnectionInitTimeout :: Opt . Parser ( Maybe Config . WSConnectionInitTimeout )
2022-07-15 11:54:27 +03:00
parseWebSocketConnectionInitTimeout =
Opt . optional $
Opt . option
2022-07-29 03:45:51 +03:00
( Opt . eitherReader Env . fromEnv )
2022-07-15 11:54:27 +03:00
( Opt . long " websocket-connection-init-timeout "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage webSocketConnectionInitTimeoutOption )
2022-07-15 11:54:27 +03:00
)
-- NOTE: this is purely used by GraphQL-WS
2022-08-05 03:28:49 +03:00
webSocketConnectionInitTimeoutOption :: Config . Option Config . WSConnectionInitTimeout
webSocketConnectionInitTimeoutOption =
Config . Option
{ Config . _default = Config . WSConnectionInitTimeout $ fromIntegral @ Int 3 ,
Config . _envVar = " HASURA_GRAPHQL_WEBSOCKET_CONNECTION_INIT_TIMEOUT " , -- FIXME?: maybe a better name
Config . _helpMessage = " Control websocket connection_init timeout (default 3 seconds) "
}
2022-07-15 11:54:27 +03:00
2022-07-29 03:45:51 +03:00
parseEnableMetadataQueryLogging :: Opt . Parser Logging . MetadataQueryLoggingMode
2022-07-15 11:54:27 +03:00
parseEnableMetadataQueryLogging =
2022-07-29 03:45:51 +03:00
fmap ( bool Logging . MetadataQueryLoggingDisabled Logging . MetadataQueryLoggingEnabled ) $
Opt . switch
( Opt . long " enable-metadata-query-logging "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage enableMetadataQueryLoggingOption )
2022-07-29 03:45:51 +03:00
)
2022-07-15 11:54:27 +03:00
2022-08-05 03:28:49 +03:00
enableMetadataQueryLoggingOption :: Config . Option Logging . MetadataQueryLoggingMode
enableMetadataQueryLoggingOption =
Config . Option
{ Config . _default = Logging . MetadataQueryLoggingDisabled ,
Config . _envVar = " HASURA_GRAPHQL_ENABLE_METADATA_QUERY_LOGGING " ,
Config . _helpMessage = " Enables the query field in http-logs for metadata queries (default: false) "
}
2022-07-15 11:54:27 +03:00
2022-08-05 03:28:49 +03:00
-- TODO(SOLOMON): The defaulting behavior for this occurs inside the Engine. In
-- an isolated PR we should move that defaulting in the parsing stage.
2022-07-15 11:54:27 +03:00
parseDefaultNamingConvention :: Opt . Parser ( Maybe NC . NamingCase )
parseDefaultNamingConvention =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " default-naming-convention "
2022-08-05 03:28:49 +03:00
<> Opt . help ( Config . _helpMessage defaultNamingConventionOption )
2022-07-15 11:54:27 +03:00
)
2022-08-09 14:42:12 +03:00
parseExtensionsSchema :: Opt . Parser ( Maybe ExtensionsSchema )
parseExtensionsSchema =
Opt . optional $
Opt . option
( Opt . eitherReader Env . fromEnv )
( Opt . long " metadata-database-extensions-schema "
<> Opt . help ( Config . _helpMessage metadataDBExtensionsSchemaOption )
)
2022-08-05 03:28:49 +03:00
-- 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 dafaulting explicitly. This
--should be changed in a subsequent PR.
defaultNamingConventionOption :: Config . Option ()
defaultNamingConventionOption =
Config . Option
{ Config . _default = () ,
Config . _envVar = " HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION " ,
Config . _helpMessage =
" Default naming convention for the auto generated graphql names. Possible values are "
<> " hasura-default: Use snake_case for all names. "
<> " graphql-default: Use camelCase for field names and PascalCase for type names. "
}
2022-07-15 11:54:27 +03:00
2022-08-09 14:42:12 +03:00
metadataDBExtensionsSchemaOption :: Config . Option ExtensionsSchema
metadataDBExtensionsSchemaOption =
Config . Option
{ Config . _default = ExtensionsSchema " public " ,
Config . _envVar = " HASURA_GRAPHQL_METADATA_DATABASE_EXTENSIONS_SCHEMA " ,
Config . _helpMessage =
" Name of the schema where Hasura can install database extensions. Default: public "
}
2022-07-15 11:54:27 +03:00
--------------------------------------------------------------------------------
-- Pretty Printer
serveCmdFooter :: PP . Doc
serveCmdFooter =
examplesDoc PP .<$> PP . text " " PP .<$> envVarDoc
where
examplesDoc = PP . mkExamplesDoc examples
examples =
[ [ " # Start GraphQL Engine on default port (8080) with console enabled " ,
" graphql-engine --database-url <database-url> serve --enable-console "
] ,
[ " # Start GraphQL Engine on default port (8080) with console disabled " ,
" graphql-engine --database-url <database-url> serve "
] ,
[ " # Start GraphQL Engine on a different port (say 9090) with console disabled " ,
" graphql-engine --database-url <database-url> serve --server-port 9090 "
] ,
[ " # Start GraphQL Engine with admin secret key " ,
" graphql-engine --database-url <database-url> serve --admin-secret <adminsecretkey> "
] ,
[ " # Start GraphQL Engine with restrictive CORS policy (only allow https://example.com:8080) " ,
" graphql-engine --database-url <database-url> serve --cors-domain https://example.com:8080 "
] ,
[ " # Start GraphQL Engine with multiple domains for CORS (https://example.com, http://localhost:3000 and https://*.foo.bar.com) " ,
" graphql-engine --database-url <database-url> serve --cors-domain \ " https://example.com, https://*.foo.bar.com, http://localhost:3000 \ " "
] ,
[ " # Start GraphQL Engine with Authentication Webhook (GET) " ,
" graphql-engine --database-url <database-url> serve --admin-secret <adminsecretkey> "
<> " --auth-hook https://mywebhook.com/get "
] ,
[ " # Start GraphQL Engine with Authentication Webhook (POST) " ,
" graphql-engine --database-url <database-url> serve --admin-secret <adminsecretkey> "
<> " --auth-hook https://mywebhook.com/post --auth-hook-mode POST "
] ,
[ " # Start GraphQL Engine with telemetry enabled/disabled " ,
" graphql-engine --database-url <database-url> serve --enable-telemetry true|false "
] ,
[ " # Start GraphQL Engine with HTTP compression enabled for '/v1/query' and '/v1/graphql' endpoints " ,
" graphql-engine --database-url <database-url> serve --enable-compression "
] ,
[ " # Start GraphQL Engine with enable/disable including 'internal' information in an error response for the request made by an 'admin' " ,
" graphql-engine --database-url <database-url> serve --admin-internal-errors true|false "
]
]
envVarDoc = PP . mkEnvVarDoc $ envVars <> eventEnvs
envVars =
2022-08-05 03:28:49 +03:00
[ Config . optionPP servePortOption ,
Config . optionPP serveHostOption ,
Config . optionPP pgStripesOption ,
Config . optionPP pgConnsOption ,
Config . optionPP pgTimeoutOption ,
Config . optionPP pgConnLifetimeOption ,
Config . optionPP pgUsePreparedStatementsOption ,
Config . optionPP pgPoolTimeoutOption ,
Config . optionPP txIsolationOption ,
Config . optionPP adminSecretOption ,
Config . optionPP accessKeyOption ,
Config . optionPP authHookOption ,
Config . optionPP authHookModeOption ,
Config . optionPP jwtSecretOption ,
Config . optionPP unAuthRoleOption ,
Config . optionPP corsDomainOption ,
Config . optionPP disableCorsOption ,
Config . optionPP enableConsoleOption ,
Config . optionPP consoleAssetsDirOption ,
Config . optionPP enableTelemetryOption ,
Config . optionPP wsReadCookieOption ,
Config . optionPP stringifyNumOption ,
Config . optionPP dangerousBooleanCollapseOption ,
Config . optionPP enabledAPIsOption ,
Config . optionPP mxRefetchDelayOption ,
Config . optionPP mxBatchSizeOption ,
Config . optionPP streamingMxRefetchDelayOption ,
Config . optionPP streamingMxBatchSizeOption ,
Config . optionPP enableAllowlistOption ,
Config . optionPP ( enabledLogsOption @ L . Hasura ) ,
Config . optionPP logLevelOption ,
Config . optionPP graphqlDevModeOption ,
Config . optionPP graphqlAdminInternalErrorsOption ,
Config . optionPP graphqlEventsHttpPoolSizeOption ,
Config . optionPP graphqlEventsFetchIntervalOption ,
Config . optionPP asyncActionsFetchIntervalOption ,
Config . optionPP enableRemoteSchemaPermsOption ,
Config . optionPP webSocketCompressionOption ,
Config . optionPP webSocketKeepAliveOption ,
Config . optionPP inferFunctionPermsOption ,
Config . optionPP enableMaintenanceModeOption ,
Config . optionPP schemaPollIntervalOption ,
Config . optionPP experimentalFeaturesOption ,
Config . optionPP eventsFetchBatchSizeOption ,
Config . optionPP gracefulShutdownOption ,
Config . optionPP webSocketConnectionInitTimeoutOption ,
Config . optionPP enableMetadataQueryLoggingOption ,
Config . optionPP defaultNamingConventionOption
2022-07-15 11:54:27 +03:00
]
2022-08-05 03:28:49 +03:00
eventEnvs = [ Config . optionPP graphqlEventsHttpPoolSizeOption , Config . optionPP graphqlEventsFetchIntervalOption ]