{"id":13546855,"url":"https://github.com/addityasingh/graphql-pino-middleware","last_synced_at":"2026-01-16T15:31:06.045Z","repository":{"id":43468002,"uuid":"236595489","full_name":"addityasingh/graphql-pino-middleware","owner":"addityasingh","description":"GraphQL middleware to instrument resolvers with pino logger","archived":false,"fork":false,"pushed_at":"2023-01-05T05:56:27.000Z","size":359,"stargazers_count":13,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-03T15:38:12.419Z","etag":null,"topics":["graphql","graphql-middleware","graphql-pino-middleware","logger","logging","pino"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/addityasingh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"addityasingh","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-01-27T21:08:55.000Z","updated_at":"2024-02-02T23:02:20.000Z","dependencies_parsed_at":"2023-02-03T14:31:58.482Z","dependency_job_id":null,"html_url":"https://github.com/addityasingh/graphql-pino-middleware","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fgraphql-pino-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fgraphql-pino-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fgraphql-pino-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fgraphql-pino-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/addityasingh","download_url":"https://codeload.github.com/addityasingh/graphql-pino-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246880059,"owners_count":20848802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","graphql-middleware","graphql-pino-middleware","logger","logging","pino"],"created_at":"2024-08-01T12:00:46.355Z","updated_at":"2026-01-16T15:31:05.990Z","avatar_url":"https://github.com/addityasingh.png","language":"TypeScript","funding_links":["https://patreon.com/addityasingh"],"categories":["Libraries"],"sub_categories":["JavaScript Libraries"],"readme":"# graphql-pino-middleware 🚀\n\n[![NPM](https://nodei.co/npm/graphql-pino-middleware.png)](https://npmjs.org/package/graphql-pino-middleware)\n\nGraphQL middleware to augment resolvers with pino logger. This middleware intends to remove cross-cutting concerns from the application by providing logger in the resolver context.\n\n![build](https://github.com/addityasingh/graphql-pino-middleware/workflows/build/badge.svg)\n[![downloads](https://img.shields.io/npm/dt/graphql-pino-middleware.svg)](https://npmjs.org/package/graphql-pino-middleware?cacheSeconds=3600)\n[![version](https://img.shields.io/npm/v/graphql-pino-middleware.svg)](https://npmjs.org/package/graphql-pino-middleware?cacheSeconds=3600)\n\n\n## Table of contents\n\n- [Getting started](#getting-started)\n- [API](#api)\n- [Contributing](#contributing)\n  - [Code of Conduct](#code-of-conduct)\n  - [Contributing](#contributing)\n  - [Good first issues](#good-first-issues)\n- [License](#licence)\n\n## Getting started\n\n1. Install the `graphql-pino-middleware` and `graphql-middleware` packages\n\n```sh\nyarn add graphql-pino-middleware\nyarn add graphql-middleware\n```\n\n2. Create the pino logger and configure the middleware with options\n\n```javascript\nimport pino from \"pino\";\nimport graphqlPinoMiddleware from \"graphql-pino-middleware\";\n\nconst logger = pino();\n\n// create the graphql-pino-middleware\nconst loggerMiddleware = graphqlPinoMiddleware({\n  logger\n});\n```\n\n4. Apply the middleware to the schema\n\n```javascript\nimport express from \"express\";\nimport graphqlExpressHttp from \"express-graphql\";\nimport { applyMiddleware } from \"graphql-middleware\";\nimport { makeExecutableSchema } from \"graphql-tools\";\n\n// Construct a schema, using GraphQL schema language\nconst typeDefs = `\n  type Query {\n    hello(name: String): String\n  }\n`;\n\nconst resolvers = {\n  Query: {\n    hello: (parent, args, context) =\u003e {\n      const result = `Hello ${args.name ? args.name : \"world\"}!`;\n      // The logger is available in the context now\n      context.logger.info({\n        helloResolver: result\n      });\n      return result;\n    }\n  }\n};\n\n// apply the middleware to the schema\nconst schema = applyMiddleware(\n  makeExecutableSchema({ typeDefs, resolvers }),\n  loggerMiddleware\n);\n\n// Use the schema in your graphql server\nconst app = express();\napp.use(\n  \"/graphql\",\n  graphqlExpressHttp({\n    schema: schema,\n    rootValue: resolvers,\n    graphiql: true\n  })\n);\n```\n\n## API\n\n### middleware = graphqlPinoMiddleware([options])\n\n- `options`\n  - `logger`: An optional `pino` logger\n  - `hooks`: Lost of `PreResolve` and `PostResolve` hooks\n\nRefer the [examples](./examples) for more usage examples\n\n## Contributing\n\n`graphql-pino-middleware` package intends to support contribution and support and thanks the open source community to making it better. Read below to learn how you can improve this repository and package\n\n### Code of Conduct\n\nPlease check the [CODE OF CONDUCT](./CODE_OF_CONDUCT) which we have in place to ensure safe and supportive environment for contributors\n\n### Contributing\n\nFeel free to create issues and bugs in the issues section using issues and bugs template. Please also ensure that there are not existing issues created on the same topic\n\n### Good first issues\n\nPlease check issues labeled [#good-first-issues](https://github.com/addityasingh/graphql-pino-middleware/labels/good%20first%20issue) under the issues section\n\n## Licence\n\n`graphql-pino-middleware` uses [MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddityasingh%2Fgraphql-pino-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faddityasingh%2Fgraphql-pino-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddityasingh%2Fgraphql-pino-middleware/lists"}