2021-07-15 15:44:26 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
|
|
|
|
2021-08-04 14:42:24 +03:00
|
|
|
module Hasura.Backends.MySQL.Instances.Transport (runQuery) where
|
2021-07-15 15:44:26 +03:00
|
|
|
|
2021-08-04 14:42:24 +03:00
|
|
|
import Hasura.Prelude
|
2021-07-15 15:44:26 +03:00
|
|
|
|
2021-08-04 14:42:24 +03:00
|
|
|
import qualified Data.Aeson as J
|
|
|
|
import Data.Text.Extended
|
2021-07-15 15:44:26 +03:00
|
|
|
import Hasura.Backends.MySQL.Instances.Execute ()
|
2021-08-04 14:42:24 +03:00
|
|
|
import Hasura.Base.Error
|
|
|
|
import Hasura.EncJSON
|
|
|
|
import Hasura.GraphQL.Execute.Backend (PreparedQuery)
|
|
|
|
import Hasura.GraphQL.Logging
|
2021-07-15 15:44:26 +03:00
|
|
|
import Hasura.GraphQL.Transport.Backend
|
2021-08-04 14:42:24 +03:00
|
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol
|
|
|
|
import qualified Hasura.Logging as L
|
2021-07-15 15:44:26 +03:00
|
|
|
import Hasura.RQL.Types
|
2021-08-04 14:42:24 +03:00
|
|
|
import Hasura.Server.Types (RequestId)
|
|
|
|
import Hasura.Session
|
|
|
|
import Hasura.Tracing
|
|
|
|
import qualified Language.GraphQL.Draft.Syntax as G
|
2021-07-15 15:44:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
instance BackendTransport 'MySQL where
|
2021-08-04 14:42:24 +03:00
|
|
|
runDBQuery = runQuery
|
|
|
|
runDBQueryExplain = error "runDBQueryExplain: MySQL backend does not support this operation yet."
|
|
|
|
runDBMutation = error "runDBMutation: MySQL backend does not support this operation yet."
|
|
|
|
runDBSubscription = error "runDBSubscription: MySQL backend does not support this operation yet."
|
|
|
|
|
|
|
|
runQuery
|
|
|
|
:: ( MonadIO m
|
|
|
|
, MonadQueryLog m
|
|
|
|
, MonadTrace m
|
|
|
|
, MonadError QErr m
|
|
|
|
)
|
|
|
|
=> RequestId
|
|
|
|
-> GQLReqUnparsed
|
|
|
|
-> G.Name
|
|
|
|
-> UserInfo
|
|
|
|
-> L.Logger L.Hasura
|
|
|
|
-> SourceConfig 'MySQL
|
|
|
|
-> ExceptT QErr IO EncJSON
|
|
|
|
-> Maybe (PreparedQuery 'MySQL)
|
|
|
|
-> m (DiffTime, EncJSON)
|
|
|
|
-- ^ Also return the time spent in the PG query; for telemetry.
|
|
|
|
runQuery reqId query fieldName _userInfo logger _sourceConfig tx genSql = do
|
|
|
|
logQueryLog logger $ mkQueryLog query fieldName genSql reqId
|
|
|
|
withElapsedTime
|
|
|
|
$ trace ("MySQL Query for root field " <>> fieldName)
|
|
|
|
$ run tx
|
|
|
|
|
|
|
|
run :: (MonadIO m, MonadError QErr m) => ExceptT QErr IO a -> m a
|
|
|
|
run action = do
|
|
|
|
result <- liftIO $ runExceptT action
|
|
|
|
result `onLeft` throwError
|
|
|
|
|
|
|
|
mkQueryLog
|
|
|
|
:: GQLReqUnparsed
|
|
|
|
-> G.Name
|
|
|
|
-> Maybe (PreparedQuery 'MySQL)
|
|
|
|
-> RequestId
|
|
|
|
-> QueryLog
|
|
|
|
mkQueryLog gqlQuery fieldName preparedSql requestId =
|
|
|
|
QueryLog gqlQuery ((fieldName,) <$> generatedQuery) requestId QueryLogKindDatabase
|
|
|
|
where
|
|
|
|
generatedQuery =
|
|
|
|
preparedSql <&> \queryString
|
|
|
|
-> GeneratedQuery queryString J.Null
|