mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
e99f9a2f57
## Description This PR removes `MetadataStorageT`, and cleans up all top-level error handling. In short: this PR changes `MonadMetadataStorage` to explicitly return a bunch of `Either QErr a`, instead of relying on the stack providing a `MonadError QErr`. Since we implement that class on the base monad *below any ExceptT*, this removes a lot of very complicated instances that make assumptions about the shape of the stack. On the back of this, we can remove several layers of ExceptT from the core of the code, including the one in `RunT`, which allows us to remove several instances of `liftEitherM . runExceptT`. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7689 GitOrigin-RevId: 97d600154d690f58c0b93fb4cc2d30fd383fd8b8
50 lines
1.6 KiB
Haskell
50 lines
1.6 KiB
Haskell
module Hasura.Server.Limits
|
|
( HasResourceLimits (..),
|
|
ResourceLimits (..),
|
|
)
|
|
where
|
|
|
|
import Control.Monad.Trans.Control (MonadBaseControl)
|
|
import Hasura.Base.Error
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.ApiLimit (ApiLimit)
|
|
import Hasura.Server.Types qualified as HGE
|
|
import Hasura.Session (UserInfo)
|
|
import Hasura.Tracing qualified as Tracing
|
|
|
|
-- | Resource limits, represented by a function which modifies IO actions to
|
|
-- enforce those limits by throwing errors using 'MonadError' in the case
|
|
-- where they are exceeded.
|
|
data ResourceLimits = ResourceLimits
|
|
{ runResourceLimits ::
|
|
forall m a.
|
|
(MonadBaseControl IO m, MonadError QErr m) =>
|
|
m a ->
|
|
m a
|
|
}
|
|
|
|
-- | Monads which support resource (memory, CPU time, etc.) limiting
|
|
class Monad m => HasResourceLimits m where
|
|
askHTTPHandlerLimit :: m ResourceLimits
|
|
askGraphqlOperationLimit :: HGE.RequestId -> UserInfo -> ApiLimit -> m ResourceLimits
|
|
|
|
-- A default for monad transformer instances
|
|
default askHTTPHandlerLimit ::
|
|
(m ~ t n, MonadTrans t, HasResourceLimits n) =>
|
|
m ResourceLimits
|
|
askHTTPHandlerLimit = lift askHTTPHandlerLimit
|
|
|
|
default askGraphqlOperationLimit ::
|
|
(m ~ t n, MonadTrans t, HasResourceLimits n) =>
|
|
HGE.RequestId ->
|
|
UserInfo ->
|
|
ApiLimit ->
|
|
m ResourceLimits
|
|
askGraphqlOperationLimit reqId userInfo apiLimit = lift $ askGraphqlOperationLimit reqId userInfo apiLimit
|
|
|
|
instance HasResourceLimits m => HasResourceLimits (ReaderT r m)
|
|
|
|
instance HasResourceLimits m => HasResourceLimits (ExceptT e m)
|
|
|
|
instance HasResourceLimits m => HasResourceLimits (Tracing.TraceT m)
|