Mercurius is a GraphQL adapter for Fastify, providing high-performance GraphQL server capabilities including query caching, automatic loader integration to avoid N+1 queries, JIT compilation via graphql-jit, subscriptions, federation support, and a gateway implementation. It is the recommended GraphQL solution for Fastify applications. Current stable version is 16.9.0, released under an active development cadence. It requires Node.js >=20.9.0 or >=22.0.0 and peer dependency graphql ^16.0.0. Key differentiators: tight integration with Fastify, built-in loaders, subscriptions, and federation support.
npm install mercuriusNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up a basic GraphQL server with Fastify and Mercurius, defining a schema and resolvers, handling a GET route with GraphQL query via reply.graphql().
Update Node.js to version 20.9.0 or later, or 22.0.0 or later.
Upgrade graphql to version 16.x.
Use ESM imports (import mercurius from 'mercurius') or dynamic import().
Replace queryDepth with validationRules in plugin options.
Register Mercurius plugin before routes that use reply.graphql().
Ensure the 'subscription' option is true and define subscription resolvers.
Either set `"type": "module"` in package.json, or use `const mercurius = require('mercurius')` for CommonJS (though v16 is ESM only, so upgrade Node and use ESM).Ensure `app.register(mercurius, ...)` is called before defining the route that uses reply.graphql.
Run `npm install graphql@^16` to upgrade.
Install Fastify: `npm install fastify`.