mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
29925eb08d
An incremental PR towards https://github.com/hasura/graphql-engine/pull/5797 * metadata storage abstraction for scheduled triggers Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com> Co-authored-by: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com> Co-authored-by: Auke Booij <auke@hasura.io> GITHUB_PR_NUMBER: 6131 GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/6131 * update pro server code Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com> Co-authored-by: Auke Booij <auke@hasura.io> GitOrigin-RevId: 17244a47b3e8633acf2492e0b0734b72025f0a09
62 lines
1.9 KiB
Haskell
62 lines
1.9 KiB
Haskell
{-|
|
|
This module holds functions and data types used for logging at the GraphQL
|
|
layer. In contrast with, logging at the HTTP server layer.
|
|
-}
|
|
|
|
module Hasura.GraphQL.Logging
|
|
( QueryLog(..)
|
|
, MonadQueryLog(..)
|
|
) where
|
|
|
|
import qualified Data.Aeson as J
|
|
import qualified Language.GraphQL.Draft.Syntax as G
|
|
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol (GQLReqUnparsed)
|
|
import Hasura.Prelude
|
|
import Hasura.Server.Types (RequestId)
|
|
import Hasura.Tracing (TraceT)
|
|
|
|
import qualified Hasura.GraphQL.Execute.Query as EQ
|
|
import qualified Hasura.Logging as L
|
|
|
|
|
|
-- | A GraphQL query, optionally generated SQL, and the request id makes up the
|
|
-- | 'QueryLog'
|
|
data QueryLog
|
|
= QueryLog
|
|
{ _qlQuery :: !GQLReqUnparsed
|
|
, _qlGeneratedSql :: !(Maybe (G.Name, EQ.PreparedSql))
|
|
, _qlRequestId :: !RequestId
|
|
}
|
|
|
|
instance J.ToJSON QueryLog where
|
|
toJSON (QueryLog q sql reqId) =
|
|
J.object [ "query" J..= q
|
|
, "generated_sql" J..= sql
|
|
, "request_id" J..= reqId
|
|
]
|
|
|
|
instance L.ToEngineLog QueryLog L.Hasura where
|
|
toEngineLog ql = (L.LevelInfo, L.ELTQueryLog, J.toJSON ql)
|
|
|
|
class Monad m => MonadQueryLog m where
|
|
logQueryLog
|
|
:: L.Logger L.Hasura
|
|
-- ^ logger
|
|
-> GQLReqUnparsed
|
|
-- ^ GraphQL request
|
|
-> Maybe (G.Name, EQ.PreparedSql)
|
|
-- ^ Generated SQL if any
|
|
-> RequestId
|
|
-- ^ unique identifier for a request. NOTE this can be spoofed!
|
|
-> m ()
|
|
|
|
instance MonadQueryLog m => MonadQueryLog (ExceptT e m) where
|
|
logQueryLog l req sqlMap reqId = lift $ logQueryLog l req sqlMap reqId
|
|
|
|
instance MonadQueryLog m => MonadQueryLog (ReaderT r m) where
|
|
logQueryLog l req sqlMap reqId = lift $ logQueryLog l req sqlMap reqId
|
|
|
|
instance MonadQueryLog m => MonadQueryLog (TraceT m) where
|
|
logQueryLog l req sqlMap reqId = lift $ logQueryLog l req sqlMap reqId
|