Skip to content

Commit 81cc005

Browse files
committed
improve grapgql log
1 parent ffb4897 commit 81cc005

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/utils/logger.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ morgan.token('graphql-operation', (req: express.Request) => {
1313
if (req.body && req.body.query) {
1414
/* Try to extract operation name from query string if operationName is not provided */
1515
const match = req.body.query.match(/(?:query|mutation)\s+(\w+)/);
16+
const isMutation = req.body.query.includes('mutation');
17+
18+
const effect = isMutation ? Effect.ForegroundRed : Effect.ForegroundMagenta;
19+
const prefix = sgr(isMutation ? 'Mutation' : 'Query', effect);
1620

1721
if (match && match[1]) {
18-
return sgr(sgr(match[1], Effect.ForegroundMagenta), Effect.Bold);
22+
return prefix + ' ' + sgr(sgr(match[1], effect), Effect.Bold);
1923
}
2024
}
2125

0 commit comments

Comments
 (0)