Repository: hasura/graphql-engine
File: server/src-lib/Hasura/GraphQL/Resolve.hs (Haskell)

Code before:
      QRFPk <$> RS.convertSelectByPKey ctx fld
    QCSelectAgg ctx -> do
      validateHdrs userInfo (_socHeaders ctx)
      QRFAgg <$> RS.convertAggSelect ctx fld
    QCFuncQuery ctx -> do
      validateHdrs userInfo (_fqocHeaders ctx)
      QRFSimple <$> RS.convertFuncQuerySimple ctx fld
    QCFuncAggQuery ctx -> do
      validateHdrs userInfo (_fqocHeaders ctx)
      QRFAgg <$> RS.convertFuncQueryAgg ctx fld
    QCAsyncActionFetch ctx ->
      QRFActionSelect <$> RA.resolveAsyncActionQuery userInfo ctx fld
    QCAction ctx -> do
      -- query actions should not be marked reusable because we aren't
      -- capturing the variable value in the state as re-usable variables.
      -- The variables captured in non-action queries are used to generate
      -- an SQL query, but in case of query actions it's converted into JSON
      -- and included in the action's webhook payload.
      markNotReusable
      f <$> actionExecuter (RA.resolveActionQuery fld ctx (userVars userInfo))
      where
        outputType = _saecOutputType ctx
        jsonAggType = RA.mkJsonAggSelect outputType
        f = case jsonAggType of
             DS.JASMultipleRows -> QRFActionExecuteList
             DS.JASSingleObject -> QRFActionExecuteObject

mutFldToTx
  :: ( HasVersion
     , MonadReusability m
     , MonadError QErr m
     , MonadReader r m
     , Has UserInfo r
     , Has MutationCtxMap r
     , Has FieldMap r
     , Has OrdByCtx r
     , Has SQLGenCtx r
     , Has InsCtxMap r
     , Has HTTP.Manager r
     , Has [HTTP.Header] r
     , MonadIO m
     )
  => V.Field
  -> m (RespTx, HTTP.ResponseHeaders)
mutFldToTx fld = do
  userInfo <- asks getter
  opCtx <- getOpCtx $ V._fName fld
  let noRespHeaders = fmap (,[])
  case opCtx of
    MCInsert ctx -> do
      validateHdrs userInfo (_iocHeaders ctx)

Review comment (refactor):
Move this to function body under `let`. The `f` is ambiguous and it is more readable if it is used as soon as declared.

Code after:
      QRFPk <$> RS.convertSelectByPKey ctx fld
    QCSelectAgg ctx -> do
      validateHdrs userInfo (_socHeaders ctx)
      QRFAgg <$> RS.convertAggSelect ctx fld
    QCFuncQuery ctx -> do
      validateHdrs userInfo (_fqocHeaders ctx)
      QRFSimple <$> RS.convertFuncQuerySimple ctx fld
    QCFuncAggQuery ctx -> do
      validateHdrs userInfo (_fqocHeaders ctx)
      QRFAgg <$> RS.convertFuncQueryAgg ctx fld
    QCAsyncActionFetch ctx ->
      QRFActionSelect <$> RA.resolveAsyncActionQuery userInfo ctx fld
    QCAction ctx -> do
      -- query actions should not be marked reusable because we aren't
      -- capturing the variable value in the state as re-usable variables.
      -- The variables captured in non-action queries are used to generate
      -- an SQL query, but in case of query actions it's converted into JSON
      -- and included in the action's webhook payload.
      markNotReusable
      let f = case jsonAggType of
             DS.JASMultipleRows -> QRFActionExecuteList
             DS.JASSingleObject -> QRFActionExecuteObject
      f <$> actionExecuter (RA.resolveActionQuery fld ctx (userVars userInfo))
      where
        outputType = _saecOutputType ctx
        jsonAggType = RA.mkJsonAggSelect outputType

mutFldToTx
  :: ( HasVersion
     , MonadReusability m
     , MonadError QErr m
     , MonadReader r m
     , Has UserInfo r
     , Has MutationCtxMap r
     , Has FieldMap r
     , Has OrdByCtx r
     , Has SQLGenCtx r
     , Has InsCtxMap r
     , Has HTTP.Manager r
     , Has [HTTP.Header] r
     , MonadIO m
     )
  => V.Field
  -> m (RespTx, HTTP.ResponseHeaders)
mutFldToTx fld = do
  userInfo <- asks getter
  opCtx <- getOpCtx $ V._fName fld
  let noRespHeaders = fmap (,[])
  case opCtx of
    MCInsert ctx -> do
      validateHdrs userInfo (_iocHeaders ctx)