Fastify plugin that adds detailed GraphQL request logging to mercurius-based applications. Current stable version is 2.0.0, released 2024, compatible with Fastify v5. The plugin automatically logs GraphQL query names, mutation names, operation name, request body, and variables into structured JSON logs, addressing the default Fastify behavior that only logs a generic /graphql URL. Key differentiators: zero-config setup (plugin auto-detects GraphQL operations), optional fields for body/variables/alias, custom log levels, and use of request-scoped logger for correlation with request IDs. Ships TypeScript types.
npm install mercurius-loggingNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Set up a Fastify server with mercurius GraphQL and mercurius-logging plugin, enabling request body and variable logging.
If using Fastify 4, install mercurius-logging@1.x. If using Fastify 5, upgrade to 2.x.
Always pass { reply } as context when calling app.graphql(query, { reply }).Use logLevel to filter, or avoid enabling logBody/logVariables in production if sensitive data is present.
No workaround; future versions may add subscription support.
Ensure app.register(mercurius, {...}) is called before app.register(mercuriusLogging, {...}).Either downgrade to mercurius-logging@1 or upgrade Fastify to v5.
Use import or dynamic import() syntax. For CommonJS projects, use await import('mercurius-logging') or switch to ESM.