{"id":17673,"library":"graphql-pino-middleware","title":"Pino Logger GraphQL Middleware","description":"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.","status":"abandoned","version":"0.0.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install graphql-pino-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-pino-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-pino-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as the core logging library used by the middleware.","package":"pino","optional":false},{"reason":"Essential for applying the pino middleware to a GraphQL schema.","package":"graphql-middleware","optional":false}],"imports":[{"note":"The package exports a default function for creating the middleware instance.","wrong":"import { graphqlPinoMiddleware } from 'graphql-pino-middleware';\nconst graphqlPinoMiddleware = require('graphql-pino-middleware');","symbol":"graphqlPinoMiddleware","correct":"import graphqlPinoMiddleware from 'graphql-pino-middleware';"},{"note":"Standard import for the Pino logger library. Ensure you're importing the default export.","wrong":"const pino = require('pino');","symbol":"pino","correct":"import pino from 'pino';"},{"note":"This is a named export from the 'graphql-middleware' package, crucial for integrating any GraphQL middleware.","wrong":"const { applyMiddleware } = require('graphql-middleware');","symbol":"applyMiddleware","correct":"import { applyMiddleware } from 'graphql-middleware';"}],"quickstart":{"code":"import express from 'express';\nimport graphqlExpressHttp from 'express-graphql';\nimport { applyMiddleware } from 'graphql-middleware';\nimport { makeExecutableSchema } from 'graphql-tools';\nimport pino from 'pino';\nimport graphqlPinoMiddleware from 'graphql-pino-middleware';\n\n// 1. Create the pino logger\nconst logger = pino();\n\n// 2. Create the graphql-pino-middleware instance\nconst loggerMiddleware = graphqlPinoMiddleware({\n  logger\n});\n\n// 3. Define your GraphQL schema and resolvers\nconst typeDefs = `\n  type Query {\n    hello(name: String): String\n  }\n`;\n\nconst resolvers = {\n  Query: {\n    hello: (parent, args, context) => {\n      const result = `Hello ${args.name ? args.name : 'world'}!`;\n      // The logger is available in the context now, thanks to the middleware\n      context.logger.info({\n        helloResolver: result,\n        name: args.name // Log resolver arguments\n      });\n      return result;\n    }\n  }\n};\n\n// 4. Apply the middleware to the schema\nconst schema = applyMiddleware(\n  makeExecutableSchema({ typeDefs, resolvers }),\n  loggerMiddleware\n);\n\n// 5. Set up your Express GraphQL server\nconst app = express();\napp.use(\n  '/graphql',\n  graphqlExpressHttp({\n    schema: schema,\n    rootValue: resolvers,\n    graphiql: true // Enable GraphiQL for easy testing\n  })\n);\n\n// 6. Start the server\nconst port = process.env.PORT ?? 4000;\napp.listen(port, () => {\n  console.log(`🚀 Server ready at http://localhost:${port}/graphql`);\n  logger.info(`GraphQL server running on http://localhost:${port}/graphql`);\n});\n","lang":"javascript","description":"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."},"warnings":[{"fix":"Thoroughly test after any update and review the source code for changes. Consider forking or contributing if long-term stability is required.","message":"The package is currently at version 0.0.2, indicating an extremely early development stage. APIs are highly unstable and may change drastically without adhering to semantic versioning, leading to frequent breaking changes.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Explicitly pass the logger to async functions or utilize tools like `async_hooks` for advanced context management if deep logging context is critical.","message":"The middleware injects a logger into the GraphQL context. In complex scenarios involving async operations, `dataloader`, or other context-modifying patterns, ensure the logger instance or its context is correctly propagated or scoped to avoid unexpected logging behavior or data races.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"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.","message":"Enabling very verbose logging (e.g., logging every resolver call with extensive data) via Pino in a high-throughput GraphQL API can introduce significant performance overhead due to I/O operations and serialization. Configure Pino appropriately for your production environment.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure `graphqlPinoMiddleware` is instantiated with a `pino` logger instance (`const loggerMiddleware = graphqlPinoMiddleware({ logger });`) and that this middleware instance is passed to `applyMiddleware`.","cause":"The `logger` object was not correctly initialized or passed to `graphqlPinoMiddleware`, or the middleware was not correctly applied, preventing `context.logger` from being populated.","error":"TypeError: Cannot read properties of undefined (reading 'info') at hello (YOUR_RESOLVER_FILE.js:XX:YY)"},{"fix":"Call `graphqlPinoMiddleware()` to get the middleware instance before passing it to `applyMiddleware`. For example: `const loggerMiddleware = graphqlPinoMiddleware({ logger }); applyMiddleware(schema, loggerMiddleware);`","cause":"You likely passed the `graphqlPinoMiddleware` function directly to `applyMiddleware` instead of calling it to create an instance of the middleware.","error":"Error: GraphQL middleware must be a function"},{"fix":"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.","cause":"This typically indicates a CommonJS module (`require`) trying to import an ESM default export incorrectly, or a general incorrect default import pattern.","error":"TypeError: (0 , graphql_pino_middleware_1.default) is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}