2021-04-12 13:18:29 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
|
|
|
module Hasura.Backends.BigQuery.Instances.Transport () where
|
|
|
|
|
2021-05-05 19:20:04 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
|
2021-04-13 14:10:08 +03:00
|
|
|
import qualified Data.Aeson as J
|
2021-05-05 19:20:04 +03:00
|
|
|
import qualified Language.GraphQL.Draft.Syntax as G
|
|
|
|
|
|
|
|
import qualified Hasura.Logging as L
|
|
|
|
import qualified Hasura.Tracing as Tracing
|
|
|
|
|
2021-04-12 13:18:29 +03:00
|
|
|
import Hasura.Backends.BigQuery.Instances.Execute ()
|
2021-04-13 14:10:08 +03:00
|
|
|
import Hasura.Backends.MSSQL.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-04-12 13:18:29 +03:00
|
|
|
import Hasura.GraphQL.Transport.Backend
|
|
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol
|
|
|
|
import Hasura.RQL.Types
|
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
|
|
|
|
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."
|
|
|
|
|
2021-05-05 19:20:04 +03:00
|
|
|
|
2021-04-12 13:18:29 +03:00
|
|
|
runQuery
|
|
|
|
:: ( MonadIO m
|
|
|
|
, MonadQueryLog m
|
|
|
|
, MonadTrace m
|
|
|
|
, MonadError QErr m
|
|
|
|
)
|
|
|
|
=> RequestId
|
|
|
|
-> GQLReqUnparsed
|
|
|
|
-> G.Name
|
|
|
|
-> UserInfo
|
|
|
|
-> L.Logger L.Hasura
|
|
|
|
-> SourceConfig 'BigQuery
|
|
|
|
-> Tracing.TraceT (ExceptT QErr IO) EncJSON
|
|
|
|
-> Maybe Text
|
|
|
|
-> m (DiffTime, EncJSON)
|
|
|
|
-- ^ Also return the time spent in the PG query; for telemetry.
|
|
|
|
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
|
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
|
|
|
|
runQueryExplain (DBStepInfo _ _ _ action) = run $ runTraceTWithReporter noReporter "explain" action
|
2021-04-12 13:18:29 +03:00
|
|
|
|
|
|
|
runMutation
|
|
|
|
:: ( MonadError QErr m
|
|
|
|
)
|
|
|
|
=> RequestId
|
|
|
|
-> GQLReqUnparsed
|
|
|
|
-> G.Name
|
|
|
|
-> UserInfo
|
|
|
|
-> L.Logger L.Hasura
|
|
|
|
-> SourceConfig 'BigQuery
|
|
|
|
-> Tracing.TraceT (ExceptT QErr IO) EncJSON
|
|
|
|
-> Maybe Text
|
|
|
|
-> m (DiffTime, EncJSON)
|
|
|
|
-- ^ Also return 'Mutation' when the operation was a mutation, and the time
|
|
|
|
-- spent in the PG query; for telemetry.
|
|
|
|
runMutation _reqId _query _fieldName _userInfo _logger _sourceConfig _tx _genSql = -- 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
|
|
|
|
-> G.Name
|
|
|
|
-> Maybe Text
|
|
|
|
-> RequestId
|
|
|
|
-> QueryLog
|
|
|
|
mkQueryLog gqlQuery fieldName preparedSql requestId =
|
2021-04-28 20:38:05 +03:00
|
|
|
QueryLog gqlQuery ((fieldName,) <$> generatedQuery) requestId QueryLogKindDatabase
|
2021-04-12 13:18:29 +03:00
|
|
|
where
|
|
|
|
generatedQuery = preparedSql <&> \qs -> GeneratedQuery qs J.Null
|