hunk.code_window: The Hasura GraphQL Engine supports HTTP compression.
   The server looks for the ``Accept-Encoding`` header in request.
   If the header contains ``br`` then the server uses `Brotli <https://en.wikipedia.org/wiki/Brotli>`__ compression else if the header contains
   ``gzip`` then the server uses `Gzip <https://en.wikipedia.org/wiki/Gzip>`__ compression.
   If both values are present then the server prefers ``Brotli`` over ``Gzip``.
   Also, the server sets the ``Content-Encoding`` response header value to ``br`` for ``Brotli`` compression or ``gzip`` for ``Gzip`` compression.
   **Only responses from "/v1/query" and "/v1/graphql" endpoints are compressed.**
hunk.labels: keep keep keep replace replace replace replace keep keep
hunk.after_edit: If the header contains ``gzip`` then the server uses `Gzip <https://en.wikipedia.org/wiki/Gzip>`__ compression.
   Also, the server sets the ``Content-Encoding`` response header value to ``gzip``.
  
hunk.file_path: docs/graphql/manual/deployment/compression.rst
hunk.type: replace
file: module Hasura.GraphQL.Transport.HTTP
    ( runGQ
    ) where
  
  import qualified Network.HTTP.Types                     as N
  
  import           Hasura.EncJSON
  import           Hasura.GraphQL.Logging
  import           Hasura.GraphQL.Transport.HTTP.Protocol
  import           Hasura.Prelude
  import           Hasura.RQL.Types
  import           Hasura.Server.Context
  import           Hasura.Server.Utils                    (RequestId)
  
  import qualified Hasura.GraphQL.Execute                 as E
  
  runGQ
    :: ( MonadIO m
       , MonadError QErr m
       , MonadReader E.ExecutionCtx m
       )
    => RequestId
    -> UserInfo
    -> [N.Header]
    -> GQLReqUnparsed
    -> m (HttpResponse EncJSON)
  runGQ reqId userInfo reqHdrs req = do
    E.ExecutionCtx _ sqlGenCtx pgExecCtx planCache sc scVer _ enableAL <- ask
    execPlan <- E.getResolvedExecPlan pgExecCtx planCache
                userInfo sqlGenCtx enableAL sc scVer req
    case execPlan of
      E.GExPHasura resolvedOp ->
        flip HttpResponse Nothing <$> runHasuraGQ reqId req userInfo resolvedOp
      E.GExPRemote rsi opDef  ->
        E.execRemoteGQ reqId userInfo reqHdrs req rsi opDef
  
  runHasuraGQ
    :: ( MonadIO m
       , MonadError QErr m
       , MonadReader E.ExecutionCtx m
       )
    => RequestId
    -> GQLReqUnparsed
    -> UserInfo
    -> E.ExecOp
    -> m EncJSON
  runHasuraGQ reqId query userInfo resolvedOp = do
    E.ExecutionCtx logger _ pgExecCtx _ _ _ _ _ <- ask
    respE <- liftIO $ runExceptT $ case resolvedOp of
      E.ExOpQuery tx genSql  -> do
        -- log the generated SQL and the graphql query
        liftIO $ logGraphqlQuery logger $ QueryLog query genSql reqId
        runLazyTx' pgExecCtx tx
      E.ExOpMutation tx -> do
        -- log the graphql query
        liftIO $ logGraphqlQuery logger $ QueryLog query Nothing reqId
        runLazyTx pgExecCtx $ withUserInfo userInfo tx
      E.ExOpSubs _ ->
        throw400 UnexpectedPayload
        "subscriptions are not supported over HTTP, use websockets instead"
    resp <- liftEither respE
    return $ encodeGQResp $ GQSuccess $ encJToLBS resp
  