Registry / observability / graphql-pino-middleware

graphql-pino-middleware

JSON →
library0.0.2jsnpmunverified

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-middleware
INSTALL
IMPORT
SIG · GRAPHQL-PINO-MIDDL
G
graphql-pino-middleware
observabilityjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

graphqlPinoMiddleware
import graphqlPinoMiddleware from 'graphql-pino-middleware';
import { graphqlPinoMiddleware } from 'graphql-pino-middleware'; const graphqlPinoMiddleware = require('graphql-pino-middleware');
The package exports a default function for creating the middleware instance.
pino
import pino from 'pino';
const pino = require('pino');
Standard import for the Pino logger library. Ensure you're importing the default export.
applyMiddleware
import { applyMiddleware } from 'graphql-middleware';
const { applyMiddleware } = require('graphql-middleware');
This is a named export from the 'graphql-middleware' package, crucial for integrating any GraphQL middleware.

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.

import express from 'express'; import graphqlExpressHttp from 'express-graphql'; import { applyMiddleware } from 'graphql-middleware'; import { makeExecutableSchema } from 'graphql-tools'; import pino from 'pino'; import graphqlPinoMiddleware from 'graphql-pino-middleware'; // 1. Create the pino logger const logger = pino(); // 2. Create the graphql-pino-middleware instance const loggerMiddleware = graphqlPinoMiddleware({ logger }); // 3. Define your GraphQL schema and resolvers const typeDefs = ` type Query { hello(name: String): String } `; const resolvers = { Query: { hello: (parent, args, context) => { const result = `Hello ${args.name ? args.name : 'world'}!`; // The logger is available in the context now, thanks to the middleware context.logger.info({ helloResolver: result, name: args.name // Log resolver arguments }); return result; } } }; // 4. Apply the middleware to the schema const schema = applyMiddleware( makeExecutableSchema({ typeDefs, resolvers }), loggerMiddleware ); // 5. Set up your Express GraphQL server const app = express(); app.use( '/graphql', graphqlExpressHttp({ schema: schema, rootValue: resolvers, graphiql: true // Enable GraphiQL for easy testing }) ); // 6. Start the server const port = process.env.PORT ?? 4000; app.listen(port, () => { console.log(`🚀 Server ready at http://localhost:${port}/graphql`); logger.info(`GraphQL server running on http://localhost:${port}/graphql`); });
Debug
Known issues
breakingThe 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.
fix
Thoroughly test after any update and review the source code for changes. Consider forking or contributing if long-term stability is required.
affects: >=0.0.1
gotchaThe 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.
fix
Explicitly pass the logger to async functions or utilize tools like `async_hooks` for advanced context management if deep logging context is critical.
affects: >=0.0.1
gotchaEnabling 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.
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.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'info') at hello (YOUR_RESOLVER_FILE.js:XX:YY)
The `logger` object was not correctly initialized or passed to `graphqlPinoMiddleware`, or the middleware was not correctly applied, preventing `context.logger` from being populated.
fix
Ensure `graphqlPinoMiddleware` is instantiated with a `pino` logger instance (`const loggerMiddleware = graphqlPinoMiddleware({ logger });`) and that this middleware instance is passed to `applyMiddleware`.
Error: GraphQL middleware must be a function
You likely passed the `graphqlPinoMiddleware` function directly to `applyMiddleware` instead of calling it to create an instance of the middleware.
fix
Call `graphqlPinoMiddleware()` to get the middleware instance before passing it to `applyMiddleware`. For example: `const loggerMiddleware = graphqlPinoMiddleware({ logger }); applyMiddleware(schema, loggerMiddleware);`
TypeError: (0 , graphql_pino_middleware_1.default) is not a function
This typically indicates a CommonJS module (`require`) trying to import an ESM default export incorrectly, or a general incorrect default import pattern.
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.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
pinorequiredRequired as the core logging library used by the middleware.
graphql-middlewarerequiredEssential for applying the pino middleware to a GraphQL schema.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
2
Resources
graphql-pino-middleware — npm install graphql-pino-middleware · libregistry