graphql-engine/server/src-lib/Hasura/Backends/MySQL/Instances/Transport.hs
Sibi Prabakaran c93996d06c Mysql: Simple graphql queries along with offset/limits
https://github.com/hasura/graphql-engine-mono/pull/1851

Co-authored-by: Chris Done <11019+chrisdone@users.noreply.github.com>
Co-authored-by: Aniket Deshpande <922486+aniketd@users.noreply.github.com>
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: 4b4ba6dd86c302d873bb5f8e6dbc9412e77a8bfe
2021-08-04 11:43:19 +00:00

70 lines
2.3 KiB
Haskell

{-# OPTIONS_GHC -fno-warn-orphans #-}
module Hasura.Backends.MySQL.Instances.Transport (runQuery) where
import Hasura.Prelude
import qualified Data.Aeson 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 qualified Hasura.Logging as L
import Hasura.RQL.Types
import Hasura.Server.Types (RequestId)
import Hasura.Session
import Hasura.Tracing
import qualified Language.GraphQL.Draft.Syntax 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)
-> 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