mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 18:42:30 +03:00
f2a5d7cef3
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6822 Co-authored-by: paritosh-08 <85472423+paritosh-08@users.noreply.github.com> Co-authored-by: Naveen Naidu <30195193+Naveenaidu@users.noreply.github.com> Co-authored-by: Sooraj <8408875+soorajshankar@users.noreply.github.com> Co-authored-by: Varun Choudhary <68095256+Varun-Choudhary@users.noreply.github.com> Co-authored-by: Sean Park-Ross <94021366+seanparkross@users.noreply.github.com> GitOrigin-RevId: 61cfc00a97de88df1ede3f26829a0d78ec9c0bc5
101 lines
3.0 KiB
Haskell
101 lines
3.0 KiB
Haskell
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
module Hasura.Backends.BigQuery.Instances.Transport () where
|
|
|
|
import Data.Aeson qualified as J
|
|
import Hasura.Backends.BigQuery.Instances.Execute ()
|
|
import Hasura.Base.Error
|
|
import Hasura.EncJSON
|
|
import Hasura.GraphQL.Execute.Backend
|
|
import Hasura.GraphQL.Logging
|
|
( GeneratedQuery (..),
|
|
MonadQueryLog (..),
|
|
QueryLog (..),
|
|
QueryLogKind (QueryLogKindDatabase),
|
|
)
|
|
import Hasura.GraphQL.Namespace (RootFieldAlias)
|
|
import Hasura.GraphQL.Transport.Backend
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol
|
|
import Hasura.Logging qualified as L
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Backend
|
|
import Hasura.SQL.Backend
|
|
import Hasura.Server.Types (RequestId)
|
|
import Hasura.Session
|
|
import Hasura.Tracing
|
|
import Hasura.Tracing qualified as Tracing
|
|
|
|
instance BackendTransport 'BigQuery where
|
|
runDBQuery = runQuery
|
|
runDBQueryExplain = runQueryExplain
|
|
runDBMutation = runMutation
|
|
runDBSubscription = error "Not supported."
|
|
runDBStreamingSubscription = error "Not supported"
|
|
|
|
runQuery ::
|
|
( MonadIO m,
|
|
MonadQueryLog m,
|
|
MonadTrace m,
|
|
MonadError QErr m
|
|
) =>
|
|
RequestId ->
|
|
GQLReqUnparsed ->
|
|
RootFieldAlias ->
|
|
UserInfo ->
|
|
L.Logger L.Hasura ->
|
|
SourceConfig 'BigQuery ->
|
|
Tracing.TraceT (ExceptT QErr IO) EncJSON ->
|
|
Maybe Text ->
|
|
ResolvedConnectionTemplate 'BigQuery ->
|
|
-- | Also return the time spent in the PG query; for telemetry.
|
|
m (DiffTime, EncJSON)
|
|
runQuery reqId query fieldName _userInfo logger _sourceConfig tx genSql _ = do
|
|
-- log the generated SQL and the graphql query
|
|
-- FIXME: fix logging by making logQueryLog expect something backend agnostic!
|
|
logQueryLog logger $ mkQueryLog query fieldName genSql reqId
|
|
withElapsedTime $ Tracing.interpTraceT run tx
|
|
|
|
runQueryExplain ::
|
|
( MonadIO m,
|
|
MonadError QErr m
|
|
) =>
|
|
DBStepInfo 'BigQuery ->
|
|
m EncJSON
|
|
runQueryExplain (DBStepInfo _ _ _ action _) = run $ ignoreTraceT action
|
|
|
|
runMutation ::
|
|
( MonadError QErr m
|
|
) =>
|
|
RequestId ->
|
|
GQLReqUnparsed ->
|
|
RootFieldAlias ->
|
|
UserInfo ->
|
|
L.Logger L.Hasura ->
|
|
SourceConfig 'BigQuery ->
|
|
Tracing.TraceT (ExceptT QErr IO) EncJSON ->
|
|
Maybe Text ->
|
|
ResolvedConnectionTemplate 'BigQuery ->
|
|
-- | Also return 'Mutation' when the operation was a mutation, and the time
|
|
-- spent in the PG query; for telemetry.
|
|
m (DiffTime, EncJSON)
|
|
runMutation _reqId _query _fieldName _userInfo _logger _sourceConfig _tx _genSql _ =
|
|
-- do
|
|
throw500 "BigQuery does not support mutations!"
|
|
|
|
run :: (MonadIO m, MonadError QErr m) => ExceptT QErr IO a -> m a
|
|
run action = do
|
|
result <- liftIO $ runExceptT action
|
|
result `onLeft` throwError
|
|
|
|
mkQueryLog ::
|
|
GQLReqUnparsed ->
|
|
RootFieldAlias ->
|
|
Maybe Text ->
|
|
RequestId ->
|
|
QueryLog
|
|
mkQueryLog gqlQuery fieldName preparedSql requestId =
|
|
-- @QueryLogKindDatabase Nothing@ means that the backend doesn't support connection templates
|
|
QueryLog gqlQuery ((fieldName,) <$> generatedQuery) requestId (QueryLogKindDatabase Nothing)
|
|
where
|
|
generatedQuery = preparedSql <&> \qs -> GeneratedQuery qs J.Null
|