2021-04-12 13:18:29 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
|
|
|
module Hasura.Backends.BigQuery.Instances.Transport () where
|
|
|
|
|
2021-04-13 14:10:08 +03:00
|
|
|
import Data.Aeson qualified as J
|
2021-04-12 13:18:29 +03:00
|
|
|
import Hasura.Backends.BigQuery.Instances.Execute ()
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Base.Error
|
2021-04-12 13:18:29 +03:00
|
|
|
import Hasura.EncJSON
|
2021-05-05 19:20:04 +03:00
|
|
|
import Hasura.GraphQL.Execute.Backend
|
2021-04-13 14:10:08 +03:00
|
|
|
import Hasura.GraphQL.Logging
|
|
|
|
( GeneratedQuery (..),
|
2021-04-19 04:21:34 +03:00
|
|
|
MonadQueryLog (..),
|
|
|
|
QueryLog (..),
|
2021-04-28 20:38:05 +03:00
|
|
|
QueryLogKind (QueryLogKindDatabase),
|
2021-09-24 01:56:37 +03:00
|
|
|
)
|
2021-10-29 17:42:07 +03:00
|
|
|
import Hasura.GraphQL.Namespace (RootFieldAlias)
|
2021-04-12 13:18:29 +03:00
|
|
|
import Hasura.GraphQL.Transport.Backend
|
|
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol
|
2021-05-05 19:20:04 +03:00
|
|
|
import Hasura.Logging qualified as L
|
|
|
|
import Hasura.Prelude
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Backend
|
|
|
|
import Hasura.SQL.Backend
|
2021-04-13 14:10:08 +03:00
|
|
|
import Hasura.Server.Types (RequestId)
|
2021-04-12 13:18:29 +03:00
|
|
|
import Hasura.Session
|
|
|
|
import Hasura.Tracing
|
2021-05-05 19:20:04 +03:00
|
|
|
import Hasura.Tracing qualified as Tracing
|
|
|
|
|
2021-04-12 13:18:29 +03:00
|
|
|
instance BackendTransport 'BigQuery where
|
|
|
|
runDBQuery = runQuery
|
2021-05-05 19:20:04 +03:00
|
|
|
runDBQueryExplain = runQueryExplain
|
2021-04-12 13:18:29 +03:00
|
|
|
runDBMutation = runMutation
|
|
|
|
runDBSubscription = error "Not supported."
|
2022-04-07 17:41:43 +03:00
|
|
|
runDBStreamingSubscription = error "Not supported"
|
2021-04-12 13:18:29 +03:00
|
|
|
|
|
|
|
runQuery ::
|
|
|
|
( MonadIO m,
|
|
|
|
MonadQueryLog m,
|
|
|
|
MonadTrace m,
|
|
|
|
MonadError QErr m
|
|
|
|
) =>
|
|
|
|
RequestId ->
|
|
|
|
GQLReqUnparsed ->
|
2021-10-29 17:42:07 +03:00
|
|
|
RootFieldAlias ->
|
2021-04-12 13:18:29 +03:00
|
|
|
UserInfo ->
|
|
|
|
L.Logger L.Hasura ->
|
|
|
|
SourceConfig 'BigQuery ->
|
|
|
|
Tracing.TraceT (ExceptT QErr IO) EncJSON ->
|
|
|
|
Maybe Text ->
|
2023-01-25 10:12:53 +03:00
|
|
|
ResolvedConnectionTemplate 'BigQuery ->
|
2021-04-12 13:18:29 +03:00
|
|
|
-- | Also return the time spent in the PG query; for telemetry.
|
|
|
|
m (DiffTime, EncJSON)
|
2023-01-25 10:12:53 +03:00
|
|
|
runQuery reqId query fieldName _userInfo logger _sourceConfig tx genSql _ = do
|
2021-04-12 13:18:29 +03:00
|
|
|
-- 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
|
2021-05-05 19:20:04 +03:00
|
|
|
withElapsedTime $ Tracing.interpTraceT run tx
|
2021-04-12 13:18:29 +03:00
|
|
|
|
2021-05-05 19:20:04 +03:00
|
|
|
runQueryExplain ::
|
|
|
|
( MonadIO m,
|
|
|
|
MonadError QErr m
|
|
|
|
) =>
|
|
|
|
DBStepInfo 'BigQuery ->
|
|
|
|
m EncJSON
|
2023-01-25 10:12:53 +03:00
|
|
|
runQueryExplain (DBStepInfo _ _ _ action _) = run $ ignoreTraceT action
|
2021-04-12 13:18:29 +03:00
|
|
|
|
|
|
|
runMutation ::
|
|
|
|
( MonadError QErr m
|
|
|
|
) =>
|
|
|
|
RequestId ->
|
|
|
|
GQLReqUnparsed ->
|
2021-10-29 17:42:07 +03:00
|
|
|
RootFieldAlias ->
|
2021-04-12 13:18:29 +03:00
|
|
|
UserInfo ->
|
|
|
|
L.Logger L.Hasura ->
|
|
|
|
SourceConfig 'BigQuery ->
|
|
|
|
Tracing.TraceT (ExceptT QErr IO) EncJSON ->
|
|
|
|
Maybe Text ->
|
2023-01-25 10:12:53 +03:00
|
|
|
ResolvedConnectionTemplate 'BigQuery ->
|
2021-04-12 13:18:29 +03:00
|
|
|
-- | Also return 'Mutation' when the operation was a mutation, and the time
|
|
|
|
-- spent in the PG query; for telemetry.
|
|
|
|
m (DiffTime, EncJSON)
|
2023-01-25 10:12:53 +03:00
|
|
|
runMutation _reqId _query _fieldName _userInfo _logger _sourceConfig _tx _genSql _ =
|
2021-04-12 13:18:29 +03:00
|
|
|
-- do
|
|
|
|
throw500 "BigQuery does not support mutations!"
|
|
|
|
|
2021-05-05 19:20:04 +03:00
|
|
|
run :: (MonadIO m, MonadError QErr m) => ExceptT QErr IO a -> m a
|
|
|
|
run action = do
|
|
|
|
result <- liftIO $ runExceptT action
|
|
|
|
result `onLeft` throwError
|
|
|
|
|
2021-04-12 13:18:29 +03:00
|
|
|
mkQueryLog ::
|
|
|
|
GQLReqUnparsed ->
|
2021-10-29 17:42:07 +03:00
|
|
|
RootFieldAlias ->
|
2021-04-12 13:18:29 +03:00
|
|
|
Maybe Text ->
|
|
|
|
RequestId ->
|
|
|
|
QueryLog
|
|
|
|
mkQueryLog gqlQuery fieldName preparedSql requestId =
|
2023-01-25 10:12:53 +03:00
|
|
|
-- @QueryLogKindDatabase Nothing@ means that the backend doesn't support connection templates
|
|
|
|
QueryLog gqlQuery ((fieldName,) <$> generatedQuery) requestId (QueryLogKindDatabase Nothing)
|
2021-04-12 13:18:29 +03:00
|
|
|
where
|
|
|
|
generatedQuery = preparedSql <&> \qs -> GeneratedQuery qs J.Null
|