{-# OPTIONS_GHC -fno-warn-orphans #-}
module Hasura.Backends.DataConnector.Adapter.Execute
( DataConnectorPreparedQuery (..),
encodePreparedQueryToJsonText,
)
where
import Data.Aeson qualified as J
import Data.ByteString.Lazy qualified as BL
import Data.Text.Encoding qualified as TE
import Hasura.Backends.DataConnector.API qualified as API
import Hasura.Backends.DataConnector.Adapter.ConfigTransform (transformSourceConfig)
import Hasura.Backends.DataConnector.Adapter.Types (SourceConfig (..))
import Hasura.Backends.DataConnector.Agent.Client (AgentClientT)
import Hasura.Backends.DataConnector.Agent.Client qualified as Client
import Hasura.Backends.DataConnector.Plan.Common (Plan (..))
import Hasura.Backends.DataConnector.Plan.MutationPlan qualified as Plan
import Hasura.Backends.DataConnector.Plan.QueryPlan qualified as Plan
import Hasura.Backends.DataConnector.Plan.RemoteRelationshipPlan qualified as Plan
import Hasura.Base.Error (Code (..), QErr, throw400)
import Hasura.EncJSON (EncJSON, encJFromJEncoding, encJFromJValue)
import Hasura.GraphQL.Execute.Backend (BackendExecute (..), DBStepInfo (..), ExplainPlan (..), OnBaseMonad (..), withNoStatistics)
import Hasura.GraphQL.Namespace qualified as GQL
import Hasura.Prelude
import Hasura.RQL.Types.BackendType (BackendType (DataConnector))
import Hasura.RQL.Types.Common qualified as RQL
import Hasura.SQL.AnyBackend (mkAnyBackend)
import Hasura.Session
import Hasura.Tracing (MonadTrace)
import Hasura.Tracing qualified as Tracing
data DataConnectorPreparedQuery
= QueryRequest API.QueryRequest
| MutationRequest API.MutationRequest
encodePreparedQueryToJsonText :: DataConnectorPreparedQuery -> Text
encodePreparedQueryToJsonText :: DataConnectorPreparedQuery -> Text
encodePreparedQueryToJsonText = \case
QueryRequest QueryRequest
req -> QueryRequest -> Text
forall a. ToJSON a => a -> Text
encodeToJsonText QueryRequest
req
MutationRequest MutationRequest
req -> MutationRequest -> Text
forall a. ToJSON a => a -> Text
encodeToJsonText MutationRequest
req
encodeToJsonText :: (J.ToJSON a) => a -> Text
encodeToJsonText :: forall a. ToJSON a => a -> Text
encodeToJsonText =
ByteString -> Text
TE.decodeUtf8 (ByteString -> Text) -> (a -> ByteString) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BL.toStrict (ByteString -> ByteString) -> (a -> ByteString) -> a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ByteString
forall a. ToJSON a => a -> ByteString
J.encode
instance BackendExecute 'DataConnector where
type PreparedQuery 'DataConnector = DataConnectorPreparedQuery
type MultiplexedQuery 'DataConnector = Void
type ExecutionMonad 'DataConnector = AgentClientT
mkDBQueryPlan :: forall (m :: * -> *).
(MonadError QErr m, MonadQueryTags m,
MonadReader QueryTagsComment m) =>
UserInfo
-> SourceName
-> SourceConfig 'DataConnector
-> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> [Header]
-> Maybe Name
-> m (DBStepInfo 'DataConnector)
mkDBQueryPlan UserInfo {RoleName
BackendOnlyFieldAccess
SessionVariables
_uiRole :: RoleName
_uiSession :: SessionVariables
_uiBackendOnlyFieldAccess :: BackendOnlyFieldAccess
_uiRole :: UserInfo -> RoleName
_uiSession :: UserInfo -> SessionVariables
_uiBackendOnlyFieldAccess :: UserInfo -> BackendOnlyFieldAccess
..} SourceName
sourceName SourceConfig 'DataConnector
sourceConfig QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
ir [Header]
_headers Maybe Name
_gName = do
queryPlan :: Plan QueryRequest QueryResponse
queryPlan@Plan {QueryRequest
forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
_pRequest :: QueryRequest
_pResponseReshaper :: forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
_pRequest :: forall request response. Plan request response -> request
_pResponseReshaper :: forall request response.
Plan request response
-> forall (m :: * -> *).
MonadError QErr m =>
response -> m Encoding
..} <- (ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> SourceConfig -> m (Plan QueryRequest QueryResponse))
-> SourceConfig
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> SourceConfig -> m (Plan QueryRequest QueryResponse)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT SourceConfig 'DataConnector
SourceConfig
sourceConfig (ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse))
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse)
forall a b. (a -> b) -> a -> b
$ SessionVariables
-> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
forall (m :: * -> *) r.
(MonadError QErr m, MonadReader r m,
Has ScalarTypesCapabilities r) =>
SessionVariables
-> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> m (Plan QueryRequest QueryResponse)
Plan.mkQueryPlan SessionVariables
_uiSession QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
ir
SourceConfig
transformedSourceConfig <- SourceConfig -> Maybe SessionVariables -> m SourceConfig
forall (m :: * -> *).
MonadError QErr m =>
SourceConfig -> Maybe SessionVariables -> m SourceConfig
transformSourceConfig SourceConfig 'DataConnector
SourceConfig
sourceConfig (SessionVariables -> Maybe SessionVariables
forall a. a -> Maybe a
Just SessionVariables
_uiSession)
DBStepInfo 'DataConnector -> m (DBStepInfo 'DataConnector)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
DBStepInfo
{ dbsiSourceName :: SourceName
dbsiSourceName = SourceName
sourceName,
dbsiSourceConfig :: SourceConfig 'DataConnector
dbsiSourceConfig = SourceConfig 'DataConnector
SourceConfig
transformedSourceConfig,
dbsiPreparedQuery :: Maybe (PreparedQuery 'DataConnector)
dbsiPreparedQuery = DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a. a -> Maybe a
Just (DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery)
-> DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a b. (a -> b) -> a -> b
$ QueryRequest -> DataConnectorPreparedQuery
QueryRequest QueryRequest
_pRequest,
dbsiAction :: OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
dbsiAction = (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall (t :: (* -> *) -> * -> *) a.
(forall (m :: * -> *).
(Functor (t m), MonadIO m, MonadBaseControl IO m, MonadTrace m,
MonadError QErr m) =>
t m a)
-> OnBaseMonad t a
OnBaseMonad ((forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector))
-> (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall a b. (a -> b) -> a -> b
$ (EncJSON -> ActionResult 'DataConnector)
-> AgentClientT m EncJSON
-> AgentClientT m (ActionResult 'DataConnector)
forall a b. (a -> b) -> AgentClientT m a -> AgentClientT m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EncJSON -> ActionResult 'DataConnector
forall (b :: BackendType). EncJSON -> ActionResult b
withNoStatistics (SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
buildQueryAction SourceName
sourceName SourceConfig
transformedSourceConfig Plan QueryRequest QueryResponse
queryPlan),
dbsiResolvedConnectionTemplate :: ResolvedConnectionTemplate 'DataConnector
dbsiResolvedConnectionTemplate = ()
}
mkDBQueryExplain :: forall (m :: * -> *).
MonadError QErr m =>
RootFieldAlias
-> UserInfo
-> SourceName
-> SourceConfig 'DataConnector
-> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> [Header]
-> Maybe Name
-> m (AnyBackend DBStepInfo)
mkDBQueryExplain RootFieldAlias
fieldName UserInfo {RoleName
BackendOnlyFieldAccess
SessionVariables
_uiRole :: UserInfo -> RoleName
_uiSession :: UserInfo -> SessionVariables
_uiBackendOnlyFieldAccess :: UserInfo -> BackendOnlyFieldAccess
_uiRole :: RoleName
_uiSession :: SessionVariables
_uiBackendOnlyFieldAccess :: BackendOnlyFieldAccess
..} SourceName
sourceName SourceConfig 'DataConnector
sourceConfig QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
ir [Header]
_headers Maybe Name
_gName = do
queryPlan :: Plan QueryRequest QueryResponse
queryPlan@Plan {QueryRequest
forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
_pRequest :: forall request response. Plan request response -> request
_pResponseReshaper :: forall request response.
Plan request response
-> forall (m :: * -> *).
MonadError QErr m =>
response -> m Encoding
_pRequest :: QueryRequest
_pResponseReshaper :: forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
..} <- (ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> SourceConfig -> m (Plan QueryRequest QueryResponse))
-> SourceConfig
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> SourceConfig -> m (Plan QueryRequest QueryResponse)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT SourceConfig 'DataConnector
SourceConfig
sourceConfig (ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse))
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse)
forall a b. (a -> b) -> a -> b
$ SessionVariables
-> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
forall (m :: * -> *) r.
(MonadError QErr m, MonadReader r m,
Has ScalarTypesCapabilities r) =>
SessionVariables
-> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> m (Plan QueryRequest QueryResponse)
Plan.mkQueryPlan SessionVariables
_uiSession QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)
ir
SourceConfig
transformedSourceConfig <- SourceConfig -> Maybe SessionVariables -> m SourceConfig
forall (m :: * -> *).
MonadError QErr m =>
SourceConfig -> Maybe SessionVariables -> m SourceConfig
transformSourceConfig SourceConfig 'DataConnector
SourceConfig
sourceConfig (SessionVariables -> Maybe SessionVariables
forall a. a -> Maybe a
Just SessionVariables
_uiSession)
AnyBackend DBStepInfo -> m (AnyBackend DBStepInfo)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
(AnyBackend DBStepInfo -> m (AnyBackend DBStepInfo))
-> AnyBackend DBStepInfo -> m (AnyBackend DBStepInfo)
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType) (i :: BackendType -> *).
HasTag b =>
i b -> AnyBackend i
mkAnyBackend @'DataConnector
DBStepInfo
{ dbsiSourceName :: SourceName
dbsiSourceName = SourceName
sourceName,
dbsiSourceConfig :: SourceConfig 'DataConnector
dbsiSourceConfig = SourceConfig 'DataConnector
SourceConfig
transformedSourceConfig,
dbsiPreparedQuery :: Maybe (PreparedQuery 'DataConnector)
dbsiPreparedQuery = DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a. a -> Maybe a
Just (DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery)
-> DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a b. (a -> b) -> a -> b
$ QueryRequest -> DataConnectorPreparedQuery
QueryRequest QueryRequest
_pRequest,
dbsiAction :: OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
dbsiAction = (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall (t :: (* -> *) -> * -> *) a.
(forall (m :: * -> *).
(Functor (t m), MonadIO m, MonadBaseControl IO m, MonadTrace m,
MonadError QErr m) =>
t m a)
-> OnBaseMonad t a
OnBaseMonad ((forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector))
-> (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall a b. (a -> b) -> a -> b
$ (EncJSON -> ActionResult 'DataConnector)
-> AgentClientT m EncJSON
-> AgentClientT m (ActionResult 'DataConnector)
forall a b. (a -> b) -> AgentClientT m a -> AgentClientT m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EncJSON -> ActionResult 'DataConnector
forall (b :: BackendType). EncJSON -> ActionResult b
withNoStatistics (RootFieldAlias
-> SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
RootFieldAlias
-> SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
buildExplainAction RootFieldAlias
fieldName SourceName
sourceName SourceConfig
transformedSourceConfig Plan QueryRequest QueryResponse
queryPlan),
dbsiResolvedConnectionTemplate :: ResolvedConnectionTemplate 'DataConnector
dbsiResolvedConnectionTemplate = ()
}
mkDBMutationPlan :: forall (m :: * -> *).
(MonadError QErr m, MonadIO m, MonadQueryTags m,
MonadReader QueryTagsComment m, MonadTrace m) =>
Environment
-> Manager
-> Logger Hasura
-> UserInfo
-> StringifyNumbers
-> SourceName
-> SourceConfig 'DataConnector
-> MutationDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> [Header]
-> Maybe Name
-> Maybe (HashMap Name (Value Variable))
-> m (DBStepInfo 'DataConnector)
mkDBMutationPlan Environment
_env Manager
_manager Logger Hasura
_logger UserInfo {RoleName
BackendOnlyFieldAccess
SessionVariables
_uiRole :: UserInfo -> RoleName
_uiSession :: UserInfo -> SessionVariables
_uiBackendOnlyFieldAccess :: UserInfo -> BackendOnlyFieldAccess
_uiRole :: RoleName
_uiSession :: SessionVariables
_uiBackendOnlyFieldAccess :: BackendOnlyFieldAccess
..} StringifyNumbers
_stringifyNum SourceName
sourceName SourceConfig 'DataConnector
sourceConfig MutationDB 'DataConnector Void (UnpreparedValue 'DataConnector)
mutationDB [Header]
_headers Maybe Name
_gName Maybe (HashMap Name (Value Variable))
_maybeSelSetArgs = do
mutationPlan :: Plan MutationRequest MutationResponse
mutationPlan@Plan {MutationRequest
forall (m :: * -> *).
MonadError QErr m =>
MutationResponse -> m Encoding
_pRequest :: forall request response. Plan request response -> request
_pResponseReshaper :: forall request response.
Plan request response
-> forall (m :: * -> *).
MonadError QErr m =>
response -> m Encoding
_pRequest :: MutationRequest
_pResponseReshaper :: forall (m :: * -> *).
MonadError QErr m =>
MutationResponse -> m Encoding
..} <- (ReaderT SourceConfig m (Plan MutationRequest MutationResponse)
-> SourceConfig -> m (Plan MutationRequest MutationResponse))
-> SourceConfig
-> ReaderT SourceConfig m (Plan MutationRequest MutationResponse)
-> m (Plan MutationRequest MutationResponse)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT SourceConfig m (Plan MutationRequest MutationResponse)
-> SourceConfig -> m (Plan MutationRequest MutationResponse)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT SourceConfig 'DataConnector
SourceConfig
sourceConfig (ReaderT SourceConfig m (Plan MutationRequest MutationResponse)
-> m (Plan MutationRequest MutationResponse))
-> ReaderT SourceConfig m (Plan MutationRequest MutationResponse)
-> m (Plan MutationRequest MutationResponse)
forall a b. (a -> b) -> a -> b
$ SessionVariables
-> MutationDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> ReaderT SourceConfig m (Plan MutationRequest MutationResponse)
forall (m :: * -> *) r.
(MonadError QErr m, MonadReader r m,
Has ScalarTypesCapabilities r) =>
SessionVariables
-> MutationDB 'DataConnector Void (UnpreparedValue 'DataConnector)
-> m (Plan MutationRequest MutationResponse)
Plan.mkMutationPlan SessionVariables
_uiSession MutationDB 'DataConnector Void (UnpreparedValue 'DataConnector)
mutationDB
SourceConfig
transformedSourceConfig <- SourceConfig -> Maybe SessionVariables -> m SourceConfig
forall (m :: * -> *).
MonadError QErr m =>
SourceConfig -> Maybe SessionVariables -> m SourceConfig
transformSourceConfig SourceConfig 'DataConnector
SourceConfig
sourceConfig (SessionVariables -> Maybe SessionVariables
forall a. a -> Maybe a
Just SessionVariables
_uiSession)
DBStepInfo 'DataConnector -> m (DBStepInfo 'DataConnector)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
DBStepInfo
{ dbsiSourceName :: SourceName
dbsiSourceName = SourceName
sourceName,
dbsiSourceConfig :: SourceConfig 'DataConnector
dbsiSourceConfig = SourceConfig 'DataConnector
SourceConfig
transformedSourceConfig,
dbsiPreparedQuery :: Maybe (PreparedQuery 'DataConnector)
dbsiPreparedQuery = DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a. a -> Maybe a
Just (DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery)
-> DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a b. (a -> b) -> a -> b
$ MutationRequest -> DataConnectorPreparedQuery
MutationRequest MutationRequest
_pRequest,
dbsiAction :: OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
dbsiAction = (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall (t :: (* -> *) -> * -> *) a.
(forall (m :: * -> *).
(Functor (t m), MonadIO m, MonadBaseControl IO m, MonadTrace m,
MonadError QErr m) =>
t m a)
-> OnBaseMonad t a
OnBaseMonad ((forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector))
-> (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall a b. (a -> b) -> a -> b
$ (EncJSON -> ActionResult 'DataConnector)
-> AgentClientT m EncJSON
-> AgentClientT m (ActionResult 'DataConnector)
forall a b. (a -> b) -> AgentClientT m a -> AgentClientT m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EncJSON -> ActionResult 'DataConnector
forall (b :: BackendType). EncJSON -> ActionResult b
withNoStatistics (SourceName
-> SourceConfig
-> Plan MutationRequest MutationResponse
-> AgentClientT m EncJSON
forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> SourceConfig
-> Plan MutationRequest MutationResponse
-> AgentClientT m EncJSON
buildMutationAction SourceName
sourceName SourceConfig
transformedSourceConfig Plan MutationRequest MutationResponse
mutationPlan),
dbsiResolvedConnectionTemplate :: ResolvedConnectionTemplate 'DataConnector
dbsiResolvedConnectionTemplate = ()
}
mkLiveQuerySubscriptionPlan :: forall (m :: * -> *).
(MonadError QErr m, MonadIO m, MonadBaseControl IO m,
MonadReader QueryTagsComment m) =>
UserInfo
-> SourceName
-> SourceConfig 'DataConnector
-> Maybe Name
-> RootFieldMap
(QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector))
-> [Header]
-> Maybe Name
-> m (SubscriptionQueryPlan
'DataConnector (MultiplexedQuery 'DataConnector))
mkLiveQuerySubscriptionPlan UserInfo
_ SourceName
_ SourceConfig 'DataConnector
_ Maybe Name
_ RootFieldMap
(QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector))
_ [Header]
_ Maybe Name
_ =
Code -> Text -> m (SubscriptionQueryPlan 'DataConnector Void)
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"mkLiveQuerySubscriptionPlan: not implemented for the Data Connector backend."
mkDBStreamingSubscriptionPlan :: forall (m :: * -> *).
(MonadError QErr m, MonadIO m, MonadBaseControl IO m,
MonadReader QueryTagsComment m) =>
UserInfo
-> SourceName
-> SourceConfig 'DataConnector
-> (RootFieldAlias,
QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector))
-> [Header]
-> Maybe Name
-> m (SubscriptionQueryPlan
'DataConnector (MultiplexedQuery 'DataConnector))
mkDBStreamingSubscriptionPlan UserInfo
_ SourceName
_ SourceConfig 'DataConnector
_ (RootFieldAlias,
QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector))
_ [Header]
_ Maybe Name
_ =
Code -> Text -> m (SubscriptionQueryPlan 'DataConnector Void)
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"mkLiveQuerySubscriptionPlan: not implemented for the Data Connector backend."
mkDBRemoteRelationshipPlan :: forall (m :: * -> *).
(MonadError QErr m, MonadQueryTags m) =>
UserInfo
-> SourceName
-> SourceConfig 'DataConnector
-> NonEmpty Object
-> HashMap
FieldName (Column 'DataConnector, ScalarType 'DataConnector)
-> FieldName
-> (FieldName,
SourceRelationshipSelection 'DataConnector Void UnpreparedValue)
-> [Header]
-> Maybe Name
-> StringifyNumbers
-> m (DBStepInfo 'DataConnector)
mkDBRemoteRelationshipPlan UserInfo {RoleName
BackendOnlyFieldAccess
SessionVariables
_uiRole :: UserInfo -> RoleName
_uiSession :: UserInfo -> SessionVariables
_uiBackendOnlyFieldAccess :: UserInfo -> BackendOnlyFieldAccess
_uiRole :: RoleName
_uiSession :: SessionVariables
_uiBackendOnlyFieldAccess :: BackendOnlyFieldAccess
..} SourceName
sourceName SourceConfig 'DataConnector
sourceConfig NonEmpty Object
joinIds HashMap
FieldName (Column 'DataConnector, ScalarType 'DataConnector)
joinIdsSchema FieldName
argumentIdFieldName (FieldName
resultFieldName, SourceRelationshipSelection 'DataConnector Void UnpreparedValue
ir) [Header]
_ Maybe Name
_ StringifyNumbers
_ = do
remoteRelationshipPlan :: Plan QueryRequest QueryResponse
remoteRelationshipPlan@Plan {QueryRequest
forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
_pRequest :: forall request response. Plan request response -> request
_pResponseReshaper :: forall request response.
Plan request response
-> forall (m :: * -> *).
MonadError QErr m =>
response -> m Encoding
_pRequest :: QueryRequest
_pResponseReshaper :: forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
..} <- (ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> SourceConfig -> m (Plan QueryRequest QueryResponse))
-> SourceConfig
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> SourceConfig -> m (Plan QueryRequest QueryResponse)
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT SourceConfig 'DataConnector
SourceConfig
sourceConfig (ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse))
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
-> m (Plan QueryRequest QueryResponse)
forall a b. (a -> b) -> a -> b
$ SessionVariables
-> SourceConfig
-> NonEmpty Object
-> HashMap FieldName (ColumnName, ScalarType)
-> FieldName
-> FieldName
-> SourceRelationshipSelection 'DataConnector Void UnpreparedValue
-> ReaderT SourceConfig m (Plan QueryRequest QueryResponse)
forall (m :: * -> *) r.
(MonadError QErr m, MonadReader r m,
Has ScalarTypesCapabilities r) =>
SessionVariables
-> SourceConfig
-> NonEmpty Object
-> HashMap FieldName (ColumnName, ScalarType)
-> FieldName
-> FieldName
-> SourceRelationshipSelection 'DataConnector Void UnpreparedValue
-> m (Plan QueryRequest QueryResponse)
Plan.mkRemoteRelationshipPlan SessionVariables
_uiSession SourceConfig 'DataConnector
SourceConfig
sourceConfig NonEmpty Object
joinIds HashMap
FieldName (Column 'DataConnector, ScalarType 'DataConnector)
HashMap FieldName (ColumnName, ScalarType)
joinIdsSchema FieldName
argumentIdFieldName FieldName
resultFieldName SourceRelationshipSelection 'DataConnector Void UnpreparedValue
ir
SourceConfig
transformedSourceConfig <- SourceConfig -> Maybe SessionVariables -> m SourceConfig
forall (m :: * -> *).
MonadError QErr m =>
SourceConfig -> Maybe SessionVariables -> m SourceConfig
transformSourceConfig SourceConfig 'DataConnector
SourceConfig
sourceConfig (SessionVariables -> Maybe SessionVariables
forall a. a -> Maybe a
Just SessionVariables
_uiSession)
DBStepInfo 'DataConnector -> m (DBStepInfo 'DataConnector)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
DBStepInfo
{ dbsiSourceName :: SourceName
dbsiSourceName = SourceName
sourceName,
dbsiSourceConfig :: SourceConfig 'DataConnector
dbsiSourceConfig = SourceConfig 'DataConnector
SourceConfig
transformedSourceConfig,
dbsiPreparedQuery :: Maybe (PreparedQuery 'DataConnector)
dbsiPreparedQuery = DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a. a -> Maybe a
Just (DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery)
-> DataConnectorPreparedQuery -> Maybe DataConnectorPreparedQuery
forall a b. (a -> b) -> a -> b
$ QueryRequest -> DataConnectorPreparedQuery
QueryRequest QueryRequest
_pRequest,
dbsiAction :: OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
dbsiAction = (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall (t :: (* -> *) -> * -> *) a.
(forall (m :: * -> *).
(Functor (t m), MonadIO m, MonadBaseControl IO m, MonadTrace m,
MonadError QErr m) =>
t m a)
-> OnBaseMonad t a
OnBaseMonad ((forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector))
-> (forall (m :: * -> *).
(Functor (ExecutionMonad 'DataConnector m), MonadIO m,
MonadBaseControl IO m, MonadTrace m, MonadError QErr m) =>
ExecutionMonad 'DataConnector m (ActionResult 'DataConnector))
-> OnBaseMonad
(ExecutionMonad 'DataConnector) (ActionResult 'DataConnector)
forall a b. (a -> b) -> a -> b
$ (EncJSON -> ActionResult 'DataConnector)
-> AgentClientT m EncJSON
-> AgentClientT m (ActionResult 'DataConnector)
forall a b. (a -> b) -> AgentClientT m a -> AgentClientT m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EncJSON -> ActionResult 'DataConnector
forall (b :: BackendType). EncJSON -> ActionResult b
withNoStatistics (SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
buildQueryAction SourceName
sourceName SourceConfig
transformedSourceConfig Plan QueryRequest QueryResponse
remoteRelationshipPlan),
dbsiResolvedConnectionTemplate :: ResolvedConnectionTemplate 'DataConnector
dbsiResolvedConnectionTemplate = ()
}
mkSubscriptionExplain :: forall (m :: * -> *).
(MonadError QErr m, MonadIO m, MonadBaseControl IO m) =>
SubscriptionQueryPlan
'DataConnector (MultiplexedQuery 'DataConnector)
-> m SubscriptionQueryPlanExplanation
mkSubscriptionExplain SubscriptionQueryPlan
'DataConnector (MultiplexedQuery 'DataConnector)
_ =
Code -> Text -> m SubscriptionQueryPlanExplanation
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"mkSubscriptionExplain: not implemented for the Data Connector backend."
buildQueryAction :: (MonadIO m, MonadTrace m, MonadError QErr m) => RQL.SourceName -> SourceConfig -> Plan API.QueryRequest API.QueryResponse -> AgentClientT m EncJSON
buildQueryAction :: forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
buildQueryAction SourceName
sourceName SourceConfig {Maybe Int
Maybe Text
Config
Capabilities
Environment
Manager
BaseUrl
DataConnectorName
_scEndpoint :: BaseUrl
_scConfig :: Config
_scTemplate :: Maybe Text
_scCapabilities :: Capabilities
_scManager :: Manager
_scTimeoutMicroseconds :: Maybe Int
_scDataConnectorName :: DataConnectorName
_scEnvironment :: Environment
_scEndpoint :: SourceConfig -> BaseUrl
_scConfig :: SourceConfig -> Config
_scTemplate :: SourceConfig -> Maybe Text
_scCapabilities :: SourceConfig -> Capabilities
_scManager :: SourceConfig -> Manager
_scTimeoutMicroseconds :: SourceConfig -> Maybe Int
_scDataConnectorName :: SourceConfig -> DataConnectorName
_scEnvironment :: SourceConfig -> Environment
..} Plan {QueryRequest
forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
_pRequest :: forall request response. Plan request response -> request
_pResponseReshaper :: forall request response.
Plan request response
-> forall (m :: * -> *).
MonadError QErr m =>
response -> m Encoding
_pRequest :: QueryRequest
_pResponseReshaper :: forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
..} = do
QueryResponse
queryResponse <- SourceName
-> Config -> QueryRequest -> AgentClientT m QueryResponse
forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> Config -> QueryRequest -> AgentClientT m QueryResponse
Client.query SourceName
sourceName Config
_scConfig QueryRequest
_pRequest
Encoding
reshapedResponse <- Text -> AgentClientT m Encoding -> AgentClientT m Encoding
forall (m :: * -> *) a.
(MonadIO m, MonadTrace m) =>
Text -> m a -> m a
Tracing.newSpan Text
"QueryResponse reshaping" (AgentClientT m Encoding -> AgentClientT m Encoding)
-> AgentClientT m Encoding -> AgentClientT m Encoding
forall a b. (a -> b) -> a -> b
$ QueryResponse -> AgentClientT m Encoding
forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
_pResponseReshaper QueryResponse
queryResponse
EncJSON -> AgentClientT m EncJSON
forall a. a -> AgentClientT m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EncJSON -> AgentClientT m EncJSON)
-> EncJSON -> AgentClientT m EncJSON
forall a b. (a -> b) -> a -> b
$ Encoding -> EncJSON
encJFromJEncoding Encoding
reshapedResponse
buildExplainAction :: (MonadIO m, MonadTrace m, MonadError QErr m) => GQL.RootFieldAlias -> RQL.SourceName -> SourceConfig -> Plan API.QueryRequest API.QueryResponse -> AgentClientT m EncJSON
buildExplainAction :: forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
RootFieldAlias
-> SourceName
-> SourceConfig
-> Plan QueryRequest QueryResponse
-> AgentClientT m EncJSON
buildExplainAction RootFieldAlias
fieldName SourceName
sourceName SourceConfig {Maybe Int
Maybe Text
Config
Capabilities
Environment
Manager
BaseUrl
DataConnectorName
_scEndpoint :: SourceConfig -> BaseUrl
_scConfig :: SourceConfig -> Config
_scTemplate :: SourceConfig -> Maybe Text
_scCapabilities :: SourceConfig -> Capabilities
_scManager :: SourceConfig -> Manager
_scTimeoutMicroseconds :: SourceConfig -> Maybe Int
_scDataConnectorName :: SourceConfig -> DataConnectorName
_scEnvironment :: SourceConfig -> Environment
_scEndpoint :: BaseUrl
_scConfig :: Config
_scTemplate :: Maybe Text
_scCapabilities :: Capabilities
_scManager :: Manager
_scTimeoutMicroseconds :: Maybe Int
_scDataConnectorName :: DataConnectorName
_scEnvironment :: Environment
..} Plan {QueryRequest
forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
_pRequest :: forall request response. Plan request response -> request
_pResponseReshaper :: forall request response.
Plan request response
-> forall (m :: * -> *).
MonadError QErr m =>
response -> m Encoding
_pRequest :: QueryRequest
_pResponseReshaper :: forall (m :: * -> *).
MonadError QErr m =>
QueryResponse -> m Encoding
..} =
case Capabilities -> Maybe ExplainCapabilities
API._cExplain Capabilities
_scCapabilities of
Maybe ExplainCapabilities
Nothing -> EncJSON -> AgentClientT m EncJSON
forall a. a -> AgentClientT m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EncJSON -> AgentClientT m EncJSON)
-> (QueryRequest -> EncJSON)
-> QueryRequest
-> AgentClientT m EncJSON
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExplainPlan -> EncJSON
forall a. ToJSON a => a -> EncJSON
encJFromJValue (ExplainPlan -> EncJSON)
-> (QueryRequest -> ExplainPlan) -> QueryRequest -> EncJSON
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RootFieldAlias -> QueryRequest -> ExplainPlan
toExplainPlan RootFieldAlias
fieldName (QueryRequest -> AgentClientT m EncJSON)
-> QueryRequest -> AgentClientT m EncJSON
forall a b. (a -> b) -> a -> b
$ QueryRequest
_pRequest
Just ExplainCapabilities
API.ExplainCapabilities -> do
ExplainResponse
explainResponse <- SourceName
-> Config -> QueryRequest -> AgentClientT m ExplainResponse
forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> Config -> QueryRequest -> AgentClientT m ExplainResponse
Client.explain SourceName
sourceName Config
_scConfig QueryRequest
_pRequest
EncJSON -> AgentClientT m EncJSON
forall a. a -> AgentClientT m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
(EncJSON -> AgentClientT m EncJSON)
-> (ExplainPlan -> EncJSON)
-> ExplainPlan
-> AgentClientT m EncJSON
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExplainPlan -> EncJSON
forall a. ToJSON a => a -> EncJSON
encJFromJValue
(ExplainPlan -> AgentClientT m EncJSON)
-> ExplainPlan -> AgentClientT m EncJSON
forall a b. (a -> b) -> a -> b
$ RootFieldAlias -> Maybe Text -> Maybe [Text] -> ExplainPlan
ExplainPlan
RootFieldAlias
fieldName
(Text -> Maybe Text
forall a. a -> Maybe a
Just (ExplainResponse -> Text
API._erQuery ExplainResponse
explainResponse))
([Text] -> Maybe [Text]
forall a. a -> Maybe a
Just (ExplainResponse -> [Text]
API._erLines ExplainResponse
explainResponse))
toExplainPlan :: GQL.RootFieldAlias -> API.QueryRequest -> ExplainPlan
toExplainPlan :: RootFieldAlias -> QueryRequest -> ExplainPlan
toExplainPlan RootFieldAlias
fieldName QueryRequest
queryRequest =
RootFieldAlias -> Maybe Text -> Maybe [Text] -> ExplainPlan
ExplainPlan RootFieldAlias
fieldName (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"") ([Text] -> Maybe [Text]
forall a. a -> Maybe a
Just [QueryRequest -> Text
forall a. ToJSON a => a -> Text
encodeToJsonText QueryRequest
queryRequest])
buildMutationAction :: (MonadIO m, MonadTrace m, MonadError QErr m) => RQL.SourceName -> SourceConfig -> Plan API.MutationRequest API.MutationResponse -> AgentClientT m EncJSON
buildMutationAction :: forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> SourceConfig
-> Plan MutationRequest MutationResponse
-> AgentClientT m EncJSON
buildMutationAction SourceName
sourceName SourceConfig {Maybe Int
Maybe Text
Config
Capabilities
Environment
Manager
BaseUrl
DataConnectorName
_scEndpoint :: SourceConfig -> BaseUrl
_scConfig :: SourceConfig -> Config
_scTemplate :: SourceConfig -> Maybe Text
_scCapabilities :: SourceConfig -> Capabilities
_scManager :: SourceConfig -> Manager
_scTimeoutMicroseconds :: SourceConfig -> Maybe Int
_scDataConnectorName :: SourceConfig -> DataConnectorName
_scEnvironment :: SourceConfig -> Environment
_scEndpoint :: BaseUrl
_scConfig :: Config
_scTemplate :: Maybe Text
_scCapabilities :: Capabilities
_scManager :: Manager
_scTimeoutMicroseconds :: Maybe Int
_scDataConnectorName :: DataConnectorName
_scEnvironment :: Environment
..} Plan {MutationRequest
forall (m :: * -> *).
MonadError QErr m =>
MutationResponse -> m Encoding
_pRequest :: forall request response. Plan request response -> request
_pResponseReshaper :: forall request response.
Plan request response
-> forall (m :: * -> *).
MonadError QErr m =>
response -> m Encoding
_pRequest :: MutationRequest
_pResponseReshaper :: forall (m :: * -> *).
MonadError QErr m =>
MutationResponse -> m Encoding
..} = do
MutationResponse
mutationResponse <- SourceName
-> Config -> MutationRequest -> AgentClientT m MutationResponse
forall (m :: * -> *).
(MonadIO m, MonadTrace m, MonadError QErr m) =>
SourceName
-> Config -> MutationRequest -> AgentClientT m MutationResponse
Client.mutation SourceName
sourceName Config
_scConfig MutationRequest
_pRequest
Encoding
reshapedResponse <- Text -> AgentClientT m Encoding -> AgentClientT m Encoding
forall (m :: * -> *) a.
(MonadIO m, MonadTrace m) =>
Text -> m a -> m a
Tracing.newSpan Text
"MutationResponse reshaping" (AgentClientT m Encoding -> AgentClientT m Encoding)
-> AgentClientT m Encoding -> AgentClientT m Encoding
forall a b. (a -> b) -> a -> b
$ MutationResponse -> AgentClientT m Encoding
forall (m :: * -> *).
MonadError QErr m =>
MutationResponse -> m Encoding
_pResponseReshaper MutationResponse
mutationResponse
EncJSON -> AgentClientT m EncJSON
forall a. a -> AgentClientT m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EncJSON -> AgentClientT m EncJSON)
-> EncJSON -> AgentClientT m EncJSON
forall a b. (a -> b) -> a -> b
$ Encoding -> EncJSON
encJFromJEncoding Encoding
reshapedResponse