2022-02-25 19:08:18 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
|
|
|
module Hasura.Backends.DataWrapper.Adapter.Transport () where
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import Control.Exception.Safe (throwIO)
|
2022-04-14 05:06:07 +03:00
|
|
|
import Data.Aeson qualified as J
|
|
|
|
import Data.Text.Extended ((<>>))
|
2022-02-25 19:08:18 +03:00
|
|
|
import Hasura.Backends.DataWrapper.Adapter.Execute ()
|
2022-04-14 05:06:07 +03:00
|
|
|
import Hasura.Backends.DataWrapper.Adapter.Types (SourceConfig)
|
|
|
|
import Hasura.Backends.DataWrapper.Plan qualified as GDW
|
|
|
|
import Hasura.Base.Error (Code (NotSupported), QErr, throw400)
|
|
|
|
import Hasura.EncJSON (EncJSON)
|
|
|
|
import Hasura.GraphQL.Execute.Backend (DBStepInfo (..))
|
2022-04-28 04:51:58 +03:00
|
|
|
import Hasura.GraphQL.Logging qualified as HGL
|
2022-04-14 05:06:07 +03:00
|
|
|
import Hasura.GraphQL.Namespace (RootFieldAlias)
|
2022-02-25 19:08:18 +03:00
|
|
|
import Hasura.GraphQL.Transport.Backend (BackendTransport (..))
|
2022-04-14 05:06:07 +03:00
|
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol (GQLReqUnparsed)
|
|
|
|
import Hasura.Logging (Hasura, Logger)
|
2022-02-25 19:08:18 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.SQL.Backend (BackendType (DataWrapper))
|
2022-04-14 05:06:07 +03:00
|
|
|
import Hasura.Server.Types (RequestId)
|
|
|
|
import Hasura.Session (UserInfo)
|
|
|
|
import Hasura.Tracing qualified as Tracing
|
2022-02-25 19:08:18 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
instance BackendTransport 'DataWrapper where
|
2022-04-14 05:06:07 +03:00
|
|
|
runDBQuery = runDBQuery'
|
|
|
|
runDBQueryExplain = runDBQueryExplain'
|
2022-02-25 19:08:18 +03:00
|
|
|
runDBMutation _ _ _ _ _ _ _ _ =
|
|
|
|
throw400 NotSupported "runDBMutation: not implemented for GraphQL Data Wrappers."
|
2022-04-07 17:41:43 +03:00
|
|
|
runDBStreamingSubscription _ _ _ =
|
|
|
|
liftIO . throwIO $ userError "runDBStreamingSubscription: not implemented for GraphQL Data Wrappers."
|
2022-02-25 19:08:18 +03:00
|
|
|
runDBSubscription _ _ _ =
|
|
|
|
liftIO . throwIO $ userError "runDBSubscription: not implemented for GraphQL Data Wrappers."
|
2022-04-14 05:06:07 +03:00
|
|
|
|
|
|
|
runDBQuery' ::
|
|
|
|
( MonadIO m,
|
|
|
|
MonadError QErr m,
|
|
|
|
Tracing.MonadTrace m,
|
2022-04-28 04:51:58 +03:00
|
|
|
HGL.MonadQueryLog m
|
2022-04-14 05:06:07 +03:00
|
|
|
) =>
|
|
|
|
RequestId ->
|
|
|
|
GQLReqUnparsed ->
|
|
|
|
RootFieldAlias ->
|
|
|
|
UserInfo ->
|
|
|
|
Logger Hasura ->
|
|
|
|
SourceConfig ->
|
|
|
|
Tracing.TraceT (ExceptT QErr IO) a ->
|
|
|
|
Maybe GDW.Plan ->
|
|
|
|
m (DiffTime, a)
|
|
|
|
runDBQuery' requestId query fieldName _userInfo logger _sourceConfig action ir = do
|
2022-04-28 04:51:58 +03:00
|
|
|
void $ HGL.logQueryLog logger $ mkQueryLog query fieldName ir requestId
|
2022-04-14 05:06:07 +03:00
|
|
|
withElapsedTime
|
|
|
|
. Tracing.trace ("Dynamic backend query for root field " <>> fieldName)
|
|
|
|
. Tracing.interpTraceT (liftEitherM . liftIO . runExceptT)
|
|
|
|
$ action
|
|
|
|
|
|
|
|
mkQueryLog ::
|
|
|
|
GQLReqUnparsed ->
|
|
|
|
RootFieldAlias ->
|
|
|
|
Maybe GDW.Plan ->
|
|
|
|
RequestId ->
|
2022-04-28 04:51:58 +03:00
|
|
|
HGL.QueryLog
|
2022-04-14 05:06:07 +03:00
|
|
|
mkQueryLog gqlQuery fieldName maybePlan requestId =
|
2022-04-28 04:51:58 +03:00
|
|
|
HGL.QueryLog
|
2022-04-14 05:06:07 +03:00
|
|
|
gqlQuery
|
2022-04-28 04:51:58 +03:00
|
|
|
((\plan -> (fieldName, HGL.GeneratedQuery (GDW.renderPlan plan) J.Null)) <$> maybePlan)
|
2022-04-14 05:06:07 +03:00
|
|
|
requestId
|
2022-04-28 04:51:58 +03:00
|
|
|
HGL.QueryLogKindDatabase
|
2022-04-14 05:06:07 +03:00
|
|
|
|
|
|
|
runDBQueryExplain' ::
|
|
|
|
(MonadIO m, MonadError QErr m) =>
|
|
|
|
DBStepInfo 'DataWrapper ->
|
|
|
|
m EncJSON
|
|
|
|
runDBQueryExplain' (DBStepInfo _ _ _ action) =
|
|
|
|
liftEitherM $
|
|
|
|
liftIO $
|
|
|
|
runExceptT $
|
|
|
|
Tracing.runTraceTWithReporter Tracing.noReporter "explain" $
|
|
|
|
action
|