Skip to content

Commit

Permalink
do not collect logger info when not logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogge committed Apr 17, 2024
1 parent ef2b759 commit 16a4022
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions backend/src/server/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ export default {
async requestDidStart(requestContext: GraphQLRequestContext<Context>) {
const isIntrospectionQuery = requestContext.request.operationName === 'IntrospectionQuery'
const qID = randomBytes(4).toString('hex')
const logRequest = ['Apollo Request', qID, requestContext.request.operationName]
logRequest.push(JSON.stringify(requestContext.request.query))
if (requestContext.request.variables) {
logRequest.push(JSON.stringify(requestContext.request.variables))
if (!isIntrospectionQuery) {
const logRequest = ['Apollo Request', qID, requestContext.request.operationName]
logRequest.push(JSON.stringify(requestContext.request.query))
if (requestContext.request.variables) {
logRequest.push(JSON.stringify(requestContext.request.variables))
}
logger.debug(...logRequest)
}
if (!isIntrospectionQuery) logger.debug(...logRequest)
return {
// eslint-disable-next-line @typescript-eslint/require-await
async willSendResponse(requestContext: GraphQLRequestContextWillSendResponse<Context>) {
const logResponse = ['Apollo Response', qID]
if (requestContext.errors) {
logger.error(...logResponse, JSON.stringify(requestContext.errors))
return
if (!isIntrospectionQuery) {
const logResponse = ['Apollo Response', qID]
if (requestContext.errors) {
logger.error(...logResponse, JSON.stringify(requestContext.errors))
return
}
logResponse.push(JSON.stringify(requestContext.response.body))
logger.debug(...logResponse)
}

logResponse.push(JSON.stringify(requestContext.response.body))
if (!isIntrospectionQuery) logger.debug(...logResponse)
},
}
},
Expand Down

0 comments on commit 16a4022

Please sign in to comment.