Skip to content
Mercurius
Mercurius v16.10.1 · Fastify 5

GraphQL, at Fastify speed.

Mercurius is a GraphQL adapter for Fastify. Register the plugin, hand it a schema and resolvers, and you get cached parsing, automatic loaders, a JIT executor, subscriptions and federation out of the box.

Read the docs
$npm i fastify mercurius graphql
downloads / mo
0
github stars
0
license
MIT
'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 })

Run it, then open http://localhost:3000/graphiql.

// core features

Everything a production GraphQL server needs

Mercurius sits on the Fastify plugin system, so hooks, decorators and encapsulation work exactly the way they do in the rest of your app.

parse once

Cached parsing and validation

Query parsing and validation results are cached, so repeated operations skip straight to execution.

no 1 + N

Loaders built in

Automatic loader integration batches nested resolvers and avoids the 1 + N query problem without extra wiring.

graphql-jit

Just-In-Time compiler

Resolvers are compiled with graphql-jit for execution that is much faster than the reference graphql-js executor.

over WebSocket

Subscriptions

First-class subscriptions with graphql-ws and subscriptions-transport-ws, including custom pub/sub backends.

@mercuriusjs/*

Federation and gateway

Build Apollo-compatible federated services with @mercuriusjs/federation, and compose them with @mercuriusjs/gateway, subscriptions included.

fewer round trips

Batched and persisted queries

Accept batched operations in a single request and configure persisted queries to cut payload size on the wire.

// acknowledgements

The project is kindly sponsored by

Ship your first query

Start from the introduction, browse the examples, or open a good first issue if you'd rather contribute.