This package, `graphql-pino-middleware`, provides a GraphQL middleware specifically designed to integrate the Pino logger into GraphQL resolvers. It aims to reduce boilerplate by automatically injecting a `pino` logger instance into the GraphQL context for each request, allowing resolvers to easily log relevant information without directly instantiating or managing logger instances. Currently at version 0.0.2, this package appears to be in an early development stage or possibly unmaintained given its very low version number and the lack of publicly available information regarding its release cadence or roadmap. Its primary differentiator is its direct, focused integration with `pino` and `graphql-middleware` for simple resolver instrumentation.
npm install graphql-pino-middlewareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `graphql-pino-middleware` with a basic Express GraphQL server, injecting a Pino logger into the GraphQL context for use within resolvers.
Thoroughly test after any update and review the source code for changes. Consider forking or contributing if long-term stability is required.
Explicitly pass the logger to async functions or utilize tools like `async_hooks` for advanced context management if deep logging context is critical.
Adjust Pino's logging level and avoid excessive data logging in production. Consider asynchronous logging transport for better performance, if supported by your Pino setup.
Ensure `graphqlPinoMiddleware` is instantiated with a `pino` logger instance (`const loggerMiddleware = graphqlPinoMiddleware({ logger });`) and that this middleware instance is passed to `applyMiddleware`.Call `graphqlPinoMiddleware()` to get the middleware instance before passing it to `applyMiddleware`. For example: `const loggerMiddleware = graphqlPinoMiddleware({ logger }); applyMiddleware(schema, loggerMiddleware);`For ESM, use `import graphqlPinoMiddleware from 'graphql-pino-middleware';`. If using CommonJS and the package is ESM-only or uses default exports, you might need `const graphqlPinoMiddleware = require('graphql-pino-middleware').default;` if supported by your build setup.