Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Defines the CE version of the engine.
This module contains everything that is required to run the community edition of the engine: the base application monad and the implementation of all its behaviour classes.
Synopsis
- data ExitCode
- data ExitException = ExitException {
- eeCode :: !ExitCode
- eeMessage :: !ByteString
- throwErrExit :: MonadIO m => forall a. ExitCode -> String -> m a
- throwErrJExit :: (ToJSON a, MonadIO m) => forall b. ExitCode -> a -> m b
- accessDeniedErrMsg :: Text
- printJSON :: (ToJSON a, MonadIO m) => a -> m ()
- mkPGLogger :: Logger Hasura -> PGLogger
- mkLoggers :: (MonadIO m, MonadBaseControl IO m) => HashSet (EngineLogType Hasura) -> LogLevel -> ManagedT m Loggers
- data BasicConnectionInfo = BasicConnectionInfo {}
- initMetadataConnectionInfo :: MonadIO m => Environment -> Maybe String -> PostgresConnInfo (Maybe UrlConf) -> m ConnInfo
- initBasicConnectionInfo :: MonadIO m => Environment -> Maybe String -> PostgresConnInfo (Maybe UrlConf) -> Maybe PostgresPoolSettings -> Bool -> TxIsolation -> m BasicConnectionInfo
- resolvePostgresConnInfo :: MonadIO m => Environment -> UrlConf -> Maybe Int -> m ConnInfo
- initialiseAppEnv :: ForkableMonadIO m => Environment -> BasicConnectionInfo -> ServeOptions Hasura -> Maybe SubscriptionPostPollHook -> ServerMetrics -> PrometheusMetrics -> SamplingPolicy -> ManagedT m (AppInit, AppEnv)
- initialiseAppContext :: (ForkableMonadIO m, HasAppEnv m) => Environment -> ServeOptions Hasura -> AppInit -> m (AppStateRef Hasura)
- migrateCatalogAndFetchMetadata :: (MonadIO m, MonadBaseControl IO m) => Logger Hasura -> PGPool -> Maybe (SourceConnConfiguration ('Postgres 'Vanilla)) -> MaintenanceMode () -> ExtensionsSchema -> m MetadataWithResourceVersion
- buildFirstSchemaCache :: MonadIO m => Environment -> Logger Hasura -> SourceResolver ('Postgres 'Vanilla) -> SourceResolver 'MSSQL -> MetadataWithResourceVersion -> CacheStaticConfig -> CacheDynamicConfig -> Manager -> Maybe SchemaRegistryContext -> m RebuildableSchemaCache
- initSubscriptionsState :: Logger Hasura -> Maybe SubscriptionPostPollHook -> IO SubscriptionsState
- initLockedEventsCtx :: IO LockedEventsCtx
- data AppM a
- runAppM :: AppEnv -> AppM a -> IO a
- parseArgs :: EnabledLogTypes impl => Environment -> IO (HGEOptions (ServeOptions impl))
- updateJwkCtxThread :: ForkableMonadIO m => IO AppContext -> Manager -> Logger Hasura -> m Void
- runHGEServer :: forall m impl. (MonadIO m, MonadFix m, MonadMask m, MonadStateless IO m, Forall (Pure m), UserAuthentication m, HttpLog m, HasAppEnv m, HasCacheStaticConfig m, HasFeatureFlagChecker m, ConsoleRenderer m, MonadVersionAPIWithExtraData m, MonadMetadataApiAuthorization m, MonadGQLExecutionCheck m, MonadConfigApiHandler m, MonadQueryLog m, MonadExecutionLog m, MonadWSLog m, MonadExecuteQuery m, HasResourceLimits m, MonadMetadataStorage m, MonadResolveSource m, MonadQueryTags m, MonadEventLogCleanup m, ProvidesHasuraServices m, MonadTrace m, MonadGetPolicies m) => (AppStateRef impl -> SpockT m ()) -> AppStateRef impl -> UTCTime -> Maybe (IO ()) -> ConsoleType m -> Store EmptyMetrics -> ManagedT m ()
- mkHGEServer :: forall m impl. (MonadIO m, MonadFix m, MonadMask m, MonadStateless IO m, Forall (Pure m), UserAuthentication m, HttpLog m, HasAppEnv m, HasCacheStaticConfig m, HasFeatureFlagChecker m, ConsoleRenderer m, MonadVersionAPIWithExtraData m, MonadMetadataApiAuthorization m, MonadGQLExecutionCheck m, MonadConfigApiHandler m, MonadQueryLog m, MonadExecutionLog m, MonadWSLog m, MonadExecuteQuery m, HasResourceLimits m, MonadMetadataStorage m, MonadResolveSource m, MonadQueryTags m, MonadEventLogCleanup m, ProvidesHasuraServices m, MonadTrace m, MonadGetPolicies m) => (AppStateRef impl -> SpockT m ()) -> AppStateRef impl -> ConsoleType m -> Store EmptyMetrics -> ManagedT m Application
- notifySchemaCacheSyncTx :: MetadataResourceVersion -> InstanceId -> CacheInvalidations -> TxE QErr ()
- getCatalogStateTx :: TxE QErr CatalogState
- setCatalogStateTx :: CatalogStateType -> Value -> TxE QErr ()
- mkPgSourceResolver :: PGLogger -> SourceResolver ('Postgres 'Vanilla)
- mkMSSQLSourceResolver :: SourceResolver 'MSSQL
Documentation
InvalidEnvironmentVariableOptionsError | |
InvalidDatabaseConnectionParamsError | |
AuthConfigurationError | |
DatabaseMigrationError | |
SchemaCacheInitError | used by MT because it initialises the schema cache only these are used in app/Main.hs: |
MetadataExportError | |
MetadataCleanError | |
DowngradeProcessError |
data ExitException Source #
ExitException | |
|
Instances
Exception ExitException Source # | |
Defined in Hasura.App | |
Show ExitException Source # | |
Defined in Hasura.App showsPrec :: Int -> ExitException -> ShowS # show :: ExitException -> String # showList :: [ExitException] -> ShowS # |
mkLoggers :: (MonadIO m, MonadBaseControl IO m) => HashSet (EngineLogType Hasura) -> LogLevel -> ManagedT m Loggers Source #
Create all loggers based on the set of enabled logs and chosen log level.
data BasicConnectionInfo Source #
Basic information required to connect to the metadata DB, and to the default Postgres DB if any.
BasicConnectionInfo | |
|
initMetadataConnectionInfo Source #
:: MonadIO m | |
=> Environment | |
-> Maybe String | metadata DB URL (--metadata-database-url) |
-> PostgresConnInfo (Maybe UrlConf) | user's DB URL (--database-url) |
-> m ConnInfo |
Only create the metadata connection info.
Like initBasicConnectionInfo
, it prioritizes --metadata-database-url
, and
falls back to --database-url
otherwise.
!!! This function throws a fatal error if the --database-url
cannot be
!!! resolved.
initBasicConnectionInfo Source #
:: MonadIO m | |
=> Environment | |
-> Maybe String | metadata DB URL (--metadata-database-url) |
-> PostgresConnInfo (Maybe UrlConf) | user's DB URL (--database-url) |
-> Maybe PostgresPoolSettings | pool settings of the default PG connection |
-> Bool | whether the default PG config should use prepared statements |
-> TxIsolation | default transaction isolation level |
-> m BasicConnectionInfo |
Create a BasicConnectionInfo
based on the given options.
The default postgres connection is only created when the --database-url
option is given. If the --metadata-database-url
isn't given, the
--database-url
will be used for the metadata connection.
All arguments related to the default postgres connection are ignored if the
--database-url
is missing.
!!! This function throws a fatal error if the --database-url
cannot be
!!! resolved.
resolvePostgresConnInfo :: MonadIO m => Environment -> UrlConf -> Maybe Int -> m ConnInfo Source #
initialiseAppEnv :: ForkableMonadIO m => Environment -> BasicConnectionInfo -> ServeOptions Hasura -> Maybe SubscriptionPostPollHook -> ServerMetrics -> PrometheusMetrics -> SamplingPolicy -> ManagedT m (AppInit, AppEnv) Source #
Initializes or migrates the catalog and creates the AppEnv
required to
start the server, and also create the AppInit
that needs to be threaded
along the init code.
For historical reasons, this function performs a few additional startup tasks
that are not required to create the AppEnv
, such as starting background
processes and logging startup information. All of those are flagged with a
comment marking them as a side-effect.
initialiseAppContext :: (ForkableMonadIO m, HasAppEnv m) => Environment -> ServeOptions Hasura -> AppInit -> m (AppStateRef Hasura) Source #
Initializes the AppContext
and returns a corresponding AppStateRef
.
This function is meant to be run in the app monad, which provides the
AppEnv
.
migrateCatalogAndFetchMetadata :: (MonadIO m, MonadBaseControl IO m) => Logger Hasura -> PGPool -> Maybe (SourceConnConfiguration ('Postgres 'Vanilla)) -> MaintenanceMode () -> ExtensionsSchema -> m MetadataWithResourceVersion Source #
Runs catalogue migration, and returns the metadata that was fetched.
On success, this function logs the result of the migration, on failure it
logs a catalog_migrate
error and throws a fatal error.
buildFirstSchemaCache :: MonadIO m => Environment -> Logger Hasura -> SourceResolver ('Postgres 'Vanilla) -> SourceResolver 'MSSQL -> MetadataWithResourceVersion -> CacheStaticConfig -> CacheDynamicConfig -> Manager -> Maybe SchemaRegistryContext -> m RebuildableSchemaCache Source #
Build the original RebuildableSchemaCache
.
On error, it logs a catalog_migrate
error and throws a fatal error. This
misnomer is intentional: it is to preserve a previous behaviour of the code
and avoid a breaking change.
initSubscriptionsState :: Logger Hasura -> Maybe SubscriptionPostPollHook -> IO SubscriptionsState Source #
The base app monad of the CE engine.
Instances
parseArgs :: EnabledLogTypes impl => Environment -> IO (HGEOptions (ServeOptions impl)) Source #
Parse cli arguments to graphql-engine executable.
updateJwkCtxThread :: ForkableMonadIO m => IO AppContext -> Manager -> Logger Hasura -> m Void Source #
Core logic to fork a poller thread to update the JWK based on the
expiry time specified in Expires
header or Cache-Control
header
:: forall m impl. (MonadIO m, MonadFix m, MonadMask m, MonadStateless IO m, Forall (Pure m), UserAuthentication m, HttpLog m, HasAppEnv m, HasCacheStaticConfig m, HasFeatureFlagChecker m, ConsoleRenderer m, MonadVersionAPIWithExtraData m, MonadMetadataApiAuthorization m, MonadGQLExecutionCheck m, MonadConfigApiHandler m, MonadQueryLog m, MonadExecutionLog m, MonadWSLog m, MonadExecuteQuery m, HasResourceLimits m, MonadMetadataStorage m, MonadResolveSource m, MonadQueryTags m, MonadEventLogCleanup m, ProvidesHasuraServices m, MonadTrace m, MonadGetPolicies m) | |
=> (AppStateRef impl -> SpockT m ()) | |
-> AppStateRef impl | |
-> UTCTime | start time |
-> Maybe (IO ()) | A hook which can be called to indicate when the server is started succesfully |
-> ConsoleType m | |
-> Store EmptyMetrics | |
-> ManagedT m () |
This function acts as the entrypoint for the graphql-engine webserver.
Note: at the exit of this function, or in case of a graceful server shutdown (SIGTERM, or more generally, whenever the shutdown latch is set), we need to make absolutely sure that we clean up any resources which were allocated during server setup. In the case of a multitenant process, failure to do so can lead to resource leaks.
To track these resources, we use the ManagedT monad, and attach finalizers at
the same point in the code where we allocate resources. If you fork a new
long-lived thread, or create a connection pool, or allocate any other
long-lived resource, make sure to pair the allocator with its finalizer.
There are plenty of examples throughout the code. For example, see
forkManagedT
.
Note also: the order in which the finalizers run can be important. Specifically, we want the finalizers for the logger threads to run last, so that we retain as many "thread stopping" log messages as possible. The order in which the finalizers is run is determined by the order in which they are introduced in the code.
mkHGEServer :: forall m impl. (MonadIO m, MonadFix m, MonadMask m, MonadStateless IO m, Forall (Pure m), UserAuthentication m, HttpLog m, HasAppEnv m, HasCacheStaticConfig m, HasFeatureFlagChecker m, ConsoleRenderer m, MonadVersionAPIWithExtraData m, MonadMetadataApiAuthorization m, MonadGQLExecutionCheck m, MonadConfigApiHandler m, MonadQueryLog m, MonadExecutionLog m, MonadWSLog m, MonadExecuteQuery m, HasResourceLimits m, MonadMetadataStorage m, MonadResolveSource m, MonadQueryTags m, MonadEventLogCleanup m, ProvidesHasuraServices m, MonadTrace m, MonadGetPolicies m) => (AppStateRef impl -> SpockT m ()) -> AppStateRef impl -> ConsoleType m -> Store EmptyMetrics -> ManagedT m Application Source #
Part of a factorization of runHGEServer
to expose the constructed WAI
application for testing purposes. See runHGEServer
for documentation.
notifySchemaCacheSyncTx :: MetadataResourceVersion -> InstanceId -> CacheInvalidations -> TxE QErr () Source #
setCatalogStateTx :: CatalogStateType -> Value -> TxE QErr () Source #
mkPgSourceResolver :: PGLogger -> SourceResolver ('Postgres 'Vanilla) Source #