Skip to content

Commit

Permalink
Merge pull request #562 from dreammall-earth/no-introspection-query-i…
Browse files Browse the repository at this point in the history
…n-log

fix(backend): no introspection query in log
  • Loading branch information
Mogge authored Apr 17, 2024
2 parents 378156d + 16a4022 commit 8beee63
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions backend/src/server/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ export default {
// Fires whenever a GraphQL request is received from a client.
// eslint-disable-next-line @typescript-eslint/require-await
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]
if (requestContext.request.operationName !== 'IntrospectionQuery') {
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 (requestContext.request.variables) {
logRequest.push(JSON.stringify(requestContext.request.variables))
}
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 (requestContext.request.operationName !== 'IntrospectionQuery') {
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)
}

logger.debug(...logResponse)
},
}
},
Expand Down

0 comments on commit 8beee63

Please sign in to comment.