mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
67 lines
2.1 KiB
Haskell
67 lines
2.1 KiB
Haskell
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
module Hasura.Backends.MySQL.Instances.Transport (runQuery) where
|
|
|
|
import Data.Aeson qualified as J
|
|
import Data.Text.Extended
|
|
import Hasura.Backends.MySQL.Instances.Execute ()
|
|
import Hasura.Base.Error
|
|
import Hasura.EncJSON
|
|
import Hasura.GraphQL.Execute.Backend (PreparedQuery)
|
|
import Hasura.GraphQL.Logging
|
|
import Hasura.GraphQL.Transport.Backend
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol
|
|
import Hasura.Logging qualified as L
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types
|
|
import Hasura.Server.Types (RequestId)
|
|
import Hasura.Session
|
|
import Hasura.Tracing
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
|
|
|
instance BackendTransport 'MySQL where
|
|
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) ->
|
|
-- | Also return the time spent in the PG query; for telemetry.
|
|
m (DiffTime, EncJSON)
|
|
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
|