graphql-engine/server/src-lib/Hasura/Server/Limits.hs
Brandon Simmons b167120f96 server: add explicit export lists in OSS server and enforce with warning
We'll see if this improves compile times at all, but I think it's worth
doing as at least the most minimal form of module documentation.

This was accomplished by first compiling everything with
-ddump-minimal-imports, and then a bunch of scripting (with help from
ormolu)

**EDIT** it doesn't seem to improve CI compile times but the noise floor is high as it looks like we're not caching library dependencies anymore

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2730
GitOrigin-RevId: 667eb8de1e0f1af70420cbec90402922b8b84cb4
2021-11-04 16:09:38 +00:00

49 lines
1.5 KiB
Haskell

module Hasura.Server.Limits
( HasResourceLimits (..),
ResourceLimits (..),
)
where
import Control.Monad.Trans.Control (MonadBaseControl)
import Hasura.Base.Error
import Hasura.Metadata.Class
import Hasura.Prelude
import Hasura.RQL.Types.ApiLimit (ApiLimit)
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 :: m (UserInfo -> ApiLimit -> 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) =>
m (UserInfo -> ApiLimit -> ResourceLimits)
askGraphqlOperationLimit = lift askGraphqlOperationLimit
instance HasResourceLimits m => HasResourceLimits (ReaderT r m)
instance HasResourceLimits m => HasResourceLimits (ExceptT e m)
instance HasResourceLimits m => HasResourceLimits (Tracing.TraceT m)
instance HasResourceLimits m => HasResourceLimits (MetadataStorageT m)