graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.App

Description

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

Documentation

data ExitCode Source #

Instances

Instances details
Show ExitCode Source # 
Instance details

Defined in Hasura.App

throwErrExit :: MonadIO m => forall a. ExitCode -> String -> m a Source #

throwErrJExit :: (ToJSON a, MonadIO m) => forall b. ExitCode -> a -> m b Source #

printJSON :: (ToJSON a, MonadIO m) => a -> m () Source #

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.

Constructors

BasicConnectionInfo 

Fields

initMetadataConnectionInfo Source #

Arguments

:: 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 #

Arguments

:: 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 #

Creates a ConnInfo from a UrlConf parameter.

!!! throws a fatal error if the configuration is invalid

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.

data AppM a Source #

The base app monad of the CE engine.

Instances

Instances details
MonadFix AppM Source # 
Instance details

Defined in Hasura.App

Methods

mfix :: (a -> AppM a) -> AppM a #

MonadIO AppM Source # 
Instance details

Defined in Hasura.App

Methods

liftIO :: IO a -> AppM a #

Applicative AppM Source # 
Instance details

Defined in Hasura.App

Methods

pure :: a -> AppM a #

(<*>) :: AppM (a -> b) -> AppM a -> AppM b #

liftA2 :: (a -> b -> c) -> AppM a -> AppM b -> AppM c #

(*>) :: AppM a -> AppM b -> AppM b #

(<*) :: AppM a -> AppM b -> AppM a #

Functor AppM Source # 
Instance details

Defined in Hasura.App

Methods

fmap :: (a -> b) -> AppM a -> AppM b #

(<$) :: a -> AppM b -> AppM a #

Monad AppM Source # 
Instance details

Defined in Hasura.App

Methods

(>>=) :: AppM a -> (a -> AppM b) -> AppM b #

(>>) :: AppM a -> AppM b -> AppM b #

return :: a -> AppM a #

MonadCatch AppM Source # 
Instance details

Defined in Hasura.App

Methods

catch :: Exception e => AppM a -> (e -> AppM a) -> AppM a #

MonadMask AppM Source # 
Instance details

Defined in Hasura.App

Methods

mask :: ((forall a. AppM a -> AppM a) -> AppM b) -> AppM b #

uninterruptibleMask :: ((forall a. AppM a -> AppM a) -> AppM b) -> AppM b #

generalBracket :: AppM a -> (a -> ExitCase b -> AppM c) -> (a -> AppM b) -> AppM (b, c) #

MonadThrow AppM Source # 
Instance details

Defined in Hasura.App

Methods

throwM :: Exception e => e -> AppM a #

HasAppEnv AppM Source # 
Instance details

Defined in Hasura.App

MonadGQLExecutionCheck AppM Source # 
Instance details

Defined in Hasura.App

MonadExecutionLog AppM Source # 
Instance details

Defined in Hasura.App

MonadQueryLog AppM Source # 
Instance details

Defined in Hasura.App

MonadExecuteQuery AppM Source # 
Instance details

Defined in Hasura.App

MonadWSLog AppM Source # 
Instance details

Defined in Hasura.App

Methods

logWSLog :: Logger Hasura -> WSLog -> AppM () Source #

MonadEECredentialsStorage AppM Source # 
Instance details

Defined in Hasura.App

MonadMetadataStorage AppM Source #

Each of the function in the type class is executed in a totally separate transaction.

Instance details

Defined in Hasura.App

Methods

fetchMetadataResourceVersion :: AppM (Either QErr MetadataResourceVersion) Source #

fetchMetadata :: AppM (Either QErr MetadataWithResourceVersion) Source #

fetchMetadataNotifications :: MetadataResourceVersion -> InstanceId -> AppM (Either QErr [(MetadataResourceVersion, CacheInvalidations)]) Source #

setMetadata :: MetadataResourceVersion -> Metadata -> AppM (Either QErr MetadataResourceVersion) Source #

notifySchemaCacheSync :: MetadataResourceVersion -> InstanceId -> CacheInvalidations -> AppM (Either QErr ()) Source #

getCatalogState :: AppM (Either QErr CatalogState) Source #

setCatalogState :: CatalogStateType -> Value -> AppM (Either QErr ()) Source #

fetchSourceIntrospection :: MetadataResourceVersion -> AppM (Either QErr (Maybe StoredIntrospection)) Source #

storeSourceIntrospection :: StoredIntrospection -> MetadataResourceVersion -> AppM (Either QErr ()) Source #

getMetadataDbUid :: AppM (Either QErr MetadataDbId) Source #

checkMetadataStorageHealth :: AppM (Either QErr ()) Source #

getDeprivedCronTriggerStats :: [TriggerName] -> AppM (Either QErr [CronTriggerStats]) Source #

getScheduledEventsForDelivery :: [TriggerName] -> AppM (Either QErr ([CronEvent], [OneOffScheduledEvent])) Source #

insertCronEvents :: [CronEventSeed] -> AppM (Either QErr ()) Source #

insertOneOffScheduledEvent :: OneOffEvent -> AppM (Either QErr EventId) Source #

insertScheduledEventInvocation :: Invocation 'ScheduledType -> ScheduledEventType -> AppM (Either QErr ()) Source #

setScheduledEventOp :: ScheduledEventId -> ScheduledEventOp -> ScheduledEventType -> AppM (Either QErr ()) Source #

unlockScheduledEvents :: ScheduledEventType -> [ScheduledEventId] -> AppM (Either QErr Int) Source #

unlockAllLockedScheduledEvents :: AppM (Either QErr ()) Source #

clearFutureCronEvents :: ClearCronEvents -> AppM (Either QErr ()) Source #

getOneOffScheduledEvents :: ScheduledEventPagination -> [ScheduledEventStatus] -> RowsCountOption -> AppM (Either QErr (WithOptionalTotalCount [OneOffScheduledEvent])) Source #

getCronEvents :: TriggerName -> ScheduledEventPagination -> [ScheduledEventStatus] -> RowsCountOption -> AppM (Either QErr (WithOptionalTotalCount [CronEvent])) Source #

getScheduledEventInvocations :: GetScheduledEventInvocations -> AppM (Either QErr (WithOptionalTotalCount [ScheduledEventInvocation])) Source #

deleteScheduledEvent :: ScheduledEventId -> ScheduledEventType -> AppM (Either QErr ()) Source #

insertAction :: ActionName -> SessionVariables -> [Header] -> Value -> AppM (Either QErr ActionId) Source #

fetchUndeliveredActionEvents :: AppM (Either QErr [ActionLogItem]) Source #

setActionStatus :: ActionId -> AsyncActionStatus -> AppM (Either QErr ()) Source #

fetchActionResponse :: ActionId -> AppM (Either QErr ActionLogResponse) Source #

clearActionData :: ActionName -> AppM (Either QErr ()) Source #

setProcessingActionLogsToPending :: LockedActionIdArray -> AppM (Either QErr ()) Source #

MonadQueryTags AppM Source # 
Instance details

Defined in Hasura.App

MonadEventLogCleanup AppM Source # 
Instance details

Defined in Hasura.App

HasCacheStaticConfig AppM Source # 
Instance details

Defined in Hasura.App

MonadResolveSource AppM Source # 
Instance details

Defined in Hasura.App

ConsoleRenderer AppM Source # 
Instance details

Defined in Hasura.App

Associated Types

type ConsoleType AppM Source #

MonadConfigApiHandler AppM Source # 
Instance details

Defined in Hasura.App

MonadMetadataApiAuthorization AppM Source # 
Instance details

Defined in Hasura.App

MonadVersionAPIWithExtraData AppM Source # 
Instance details

Defined in Hasura.App

UserAuthentication AppM Source # 
Instance details

Defined in Hasura.App

HasFeatureFlagChecker AppM Source # 
Instance details

Defined in Hasura.App

HasResourceLimits AppM Source # 
Instance details

Defined in Hasura.App

HttpLog AppM Source # 
Instance details

Defined in Hasura.App

Associated Types

type ExtraHttpLogMetadata AppM Source #

MonadGetPolicies AppM Source # 
Instance details

Defined in Hasura.App

ProvidesNetwork AppM Source # 
Instance details

Defined in Hasura.App

MonadTrace AppM Source # 
Instance details

Defined in Hasura.App

MonadBaseControl IO AppM Source # 
Instance details

Defined in Hasura.App

Associated Types

type StM AppM a Source #

Methods

liftBaseWith :: (RunInBase AppM IO -> IO a) -> AppM a Source #

restoreM :: StM AppM a -> AppM a Source #

MonadReader AppEnv AppM Source # 
Instance details

Defined in Hasura.App

Methods

ask :: AppM AppEnv #

local :: (AppEnv -> AppEnv) -> AppM a -> AppM a #

reader :: (AppEnv -> a) -> AppM a #

MonadBase IO AppM Source # 
Instance details

Defined in Hasura.App

Methods

liftBase :: IO α -> AppM α Source #

type ConsoleType AppM Source # 
Instance details

Defined in Hasura.App

type ExtraHttpLogMetadata AppM Source # 
Instance details

Defined in Hasura.App

type StM AppM a Source # 
Instance details

Defined in Hasura.App

type StM AppM a = StM (ReaderT AppEnv (TraceT IO)) a

runAppM :: AppEnv -> AppM a -> IO a Source #

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

runHGEServer Source #

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.