2022-02-25 19:08:18 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
module Hasura.Backends.DataConnector.Adapter.Transport () where
|
2022-02-25 19:08:18 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import Control.Exception.Safe (throwIO)
|
2022-04-14 05:06:07 +03:00
|
|
|
import Data.Aeson qualified as J
|
|
|
|
import Data.Text.Extended ((<>>))
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.Adapter.Execute ()
|
|
|
|
import Hasura.Backends.DataConnector.Adapter.Types (SourceConfig)
|
2022-06-07 04:34:37 +03:00
|
|
|
import Hasura.Backends.DataConnector.IR.Query qualified as IR.Q
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.Plan qualified as DC
|
2022-04-14 05:06:07 +03:00
|
|
|
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
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.SQL.Backend (BackendType (DataConnector))
|
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
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2022-05-02 08:03:12 +03:00
|
|
|
instance BackendTransport 'DataConnector where
|
2022-04-14 05:06:07 +03:00
|
|
|
runDBQuery = runDBQuery'
|
|
|
|
runDBQueryExplain = runDBQueryExplain'
|
2022-02-25 19:08:18 +03:00
|
|
|
runDBMutation _ _ _ _ _ _ _ _ =
|
2022-05-02 08:03:12 +03:00
|
|
|
throw400 NotSupported "runDBMutation: not implemented for the Data Connector backend."
|
2022-04-07 17:41:43 +03:00
|
|
|
runDBStreamingSubscription _ _ _ =
|
2022-05-02 08:03:12 +03:00
|
|
|
liftIO . throwIO $ userError "runDBStreamingSubscription: not implemented for the Data Connector backend."
|
2022-02-25 19:08:18 +03:00
|
|
|
runDBSubscription _ _ _ =
|
2022-05-02 08:03:12 +03:00
|
|
|
liftIO . throwIO $ userError "runDBSubscription: not implemented for the Data Connector backend."
|
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 ->
|
2022-06-24 09:58:25 +03:00
|
|
|
Maybe IR.Q.QueryRequest ->
|
2022-04-14 05:06:07 +03:00
|
|
|
m (DiffTime, a)
|
2022-06-24 09:58:25 +03:00
|
|
|
runDBQuery' requestId query fieldName _userInfo logger _sourceConfig action queryRequest = do
|
|
|
|
void $ HGL.logQueryLog logger $ mkQueryLog query fieldName queryRequest requestId
|
2022-04-14 05:06:07 +03:00
|
|
|
withElapsedTime
|
2022-05-02 08:03:12 +03:00
|
|
|
. Tracing.trace ("Data Connector backend query for root field " <>> fieldName)
|
2022-04-14 05:06:07 +03:00
|
|
|
. Tracing.interpTraceT (liftEitherM . liftIO . runExceptT)
|
|
|
|
$ action
|
|
|
|
|
|
|
|
mkQueryLog ::
|
|
|
|
GQLReqUnparsed ->
|
|
|
|
RootFieldAlias ->
|
2022-06-24 09:58:25 +03:00
|
|
|
Maybe IR.Q.QueryRequest ->
|
2022-04-14 05:06:07 +03:00
|
|
|
RequestId ->
|
2022-04-28 04:51:58 +03:00
|
|
|
HGL.QueryLog
|
2022-06-07 04:34:37 +03:00
|
|
|
mkQueryLog gqlQuery fieldName maybeQuery requestId =
|
2022-04-28 04:51:58 +03:00
|
|
|
HGL.QueryLog
|
2022-04-14 05:06:07 +03:00
|
|
|
gqlQuery
|
2022-06-07 04:34:37 +03:00
|
|
|
((\query -> (fieldName, HGL.GeneratedQuery (DC.renderQuery query) J.Null)) <$> maybeQuery)
|
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) =>
|
2022-05-02 08:03:12 +03:00
|
|
|
DBStepInfo 'DataConnector ->
|
2022-04-14 05:06:07 +03:00
|
|
|
m EncJSON
|
|
|
|
runDBQueryExplain' (DBStepInfo _ _ _ action) =
|
|
|
|
liftEitherM $
|
|
|
|
liftIO $
|
|
|
|
runExceptT $
|
|
|
|
Tracing.runTraceTWithReporter Tracing.noReporter "explain" $
|
|
|
|
action
|