# mercurius

> Fastify GraphQL adapter with subscription support

Latest version **16.10.1** (published 2026-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install mercurius
pnpm add mercurius
yarn add mercurius
bun add mercurius
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 16.10.1 |
| Published | 2026-09-26 |
| First published | 2015-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | ^20.9.0 \|\| >=22.0.0 |
| Dependencies | 14 |
| Unpacked size | 734.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2490 |
| Author | Matteo Collina |
| Maintainers | matteo.collina, jonnydgreen |

## Links

- npm: https://www.npmjs.com/package/mercurius
- Repository: https://github.com/mercurius-js/mercurius
- Homepage: https://mercurius.dev
- Issues: https://github.com/mercurius-js/mercurius/issues
- npm.io page: https://npm.io/package/mercurius

## Dependencies (14)

- [ws](https://npm.io/package/ws.md) ^8.2.2
- [p-map](https://npm.io/package/p-map.md) ^4.0.0
- [tiny-lru](https://npm.io/package/tiny-lru.md) ^11.0.0
- [mqemitter](https://npm.io/package/mqemitter.md) ^7.0.0
- [quick-lru](https://npm.io/package/quick-lru.md) ^7.0.0
- [graphql-jit](https://npm.io/package/graphql-jit.md) 0.8.9
- [@fastify/error](https://npm.io/package/@fastify/error.md) ^4.0.0
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^6.0.0
- [@fastify/static](https://npm.io/package/@fastify/static.md) ^10.1.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^4.0.0
- [secure-json-parse](https://npm.io/package/secure-json-parse.md) ^4.1.0
- [single-user-cache](https://npm.io/package/single-user-cache.md) ^2.0.0
- [@fastify/websocket](https://npm.io/package/@fastify/websocket.md) ^11.0.0
- [safe-stable-stringify](https://npm.io/package/safe-stable-stringify.md) ^2.3.0

## Recent versions

- 16.10.1 (latest) — 2026-09-26
- 15.0.0 (next) — 2024-09-09
- 8.13.2 (eight) — 2023-01-10
- 16.10.0 — 2026-07-14
- 16.9.0 — 2026-04-03
- 16.8.0 — 2026-03-06
- 16.7.0 — 2026-01-19
- 16.6.0 — 2025-11-13
- 16.5.0 — 2025-10-10
- 16.4.0 — 2025-09-30
- 16.3.0 — 2025-09-25
- 16.2.0 — 2025-06-19
- 16.1.0 — 2025-02-24
- 16.0.1 — 2025-01-14
- 16.0.0 — 2024-12-21
- … 113 more at https://npm.io/package/mercurius/versions

## README

![Mercurius Logo](https://raw.githubusercontent.com/mercurius-js/graphics/main/mercurius-horizontal.svg)

# mercurius

[![CI workflow](https://github.com/mercurius-js/mercurius/actions/workflows/ci.yml/badge.svg)](https://github.com/mercurius-js/mercurius/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/mercurius.svg?style=flat)](https://www.npmjs.com/package/mercurius)
[![NPM downloads](https://img.shields.io/npm/dm/mercurius.svg?style=flat)](https://www.npmjs.com/package/mercurius)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Mercurius is a [**GraphQL**](https://graphql.org/) adapter for [**Fastify**](https://www.fastify.io)

Features:

- Caching of query parsing and validation.
- Automatic loader integration to avoid 1 + N queries.
- Just-In-Time compiler via [graphql-jit](http://npm.im/graphql-jit).
- Subscriptions.
- Federation support via [@mercuriusjs/federation](https://github.com/mercurius-js/mercurius-federation), including Subscriptions.
- Gateway implementation via [@mercuriusjs/gateway](https://github.com/mercurius-js/mercurius-gateway), including Subscriptions.
- Batched query support.
- Customisable persisted queries.

## Docs

- [Install](#install)
- [Quick Start](#quick-start)
- [Examples](#examples)
- [API](docs/api/options.md)
- [Context](docs/context.md)
- [Loaders](docs/loaders.md)
- [Hooks](docs/hooks.md)
- [Lifecycle](docs/lifecycle.md)
- [Federation](docs/federation.md)
- [Subscriptions](docs/subscriptions.md)
- [Batched Queries](docs/batched-queries.md)
- [Persisted Queries](docs/persisted-queries.md)
- [TypeScript Usage](/docs/typescript.md)
- [HTTP](/docs/http.md)
- [GraphQL over WebSocket](/docs/graphql-over-websocket.md)
- [Integrations](docs/integrations/)
- [Related Plugins](docs/plugins.md)
- [Security - CSRF Prevention](docs/security/csrf-prevention.md)
- [Faq](/docs/faq.md)
- [Contributing](#contributing)
- [Acknowledgements](#acknowledgements)
- [License](#license)

## Install

```bash
npm i fastify mercurius graphql
# or
yarn add fastify mercurius graphql
```

The previous name of this module was [fastify-gql](http://npm.im/fastify-gql) (< 6.0.0).

## Quick Start

```js
'use strict'

const Fastify = require('fastify')
const mercurius = require('mercurius')

const app = Fastify()

const schema = `
  type Query {
    add(x: Int, y: Int): Int
  }
`

const resolvers = {
  Query: {
    add: async (_, { x, y }) => x + y
  }
}

app.register(mercurius, {
  schema,
  resolvers
})

app.get('/', async function (req, reply) {
  const query = '{ add(x: 2, y: 2) }'
  return reply.graphql(query)
})

app.listen({ port: 3000 })
```

## Examples

Check [GitHub repo](https://github.com/mercurius-js/mercurius/tree/master/examples) for more examples.

## Contributing

Mercurius is an **OPEN Open Source Project**. This means that:

> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the [CONTRIBUTING.md](https://github.com/mercurius-js/mercurius/blob/master/CONTRIBUTING.md) file for more details.

## Acknowledgements

The project is kindly sponsored by:

- [NearForm](https://www.nearform.com)
- [Platformatic](https://platformatic.dev)

The Mercurius name was gracefully donated by [Marco Castelluccio](https://github.com/marco-c).
The usage of that library was described in https://hacks.mozilla.org/2015/12/web-push-notifications-from-irssi/, and
you can find that codebase in https://github.com/marco-c/mercurius.

## License

MIT

---
_Source: https://npm.io/package/mercurius · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
