Skip to content

mercurius-js/mercurius

Folders and files

NameName
Last commit message
Last commit date
Feb 1, 2025
Sep 15, 2022
Mar 18, 2025
May 1, 2023
May 1, 2023
Feb 24, 2025
Apr 11, 2025
Dec 12, 2024
Feb 24, 2025
Dec 12, 2024
Sep 5, 2024
Oct 1, 2020
Feb 17, 2025
Sep 5, 2024
Nov 18, 2022
Oct 1, 2020
Apr 28, 2021
Sep 5, 2024
Mar 18, 2025
Mar 3, 2024
Sep 9, 2024
Apr 14, 2025
Mar 10, 2021

Repository files navigation

Mercurius Logo

mercurius

CI workflow NPM version NPM downloads neostandard javascript style

Mercurius is a GraphQL adapter for Fastify

Features:

  • Caching of query parsing and validation.
  • Automatic loader integration to avoid 1 + N queries.
  • Just-In-Time compiler via graphql-jit.
  • Subscriptions.
  • Federation support via @mercuriusjs/federation, including Subscriptions.
  • Gateway implementation via @mercuriusjs/gateway, including Subscriptions.
  • Batched query support.
  • Customisable persisted queries.

Docs

Install

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

The previous name of this module was fastify-gql (< 6.0.0).

Quick Start

'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 for more examples.

Acknowledgements

The project is kindly sponsored by:

The Mercurius name was gracefully donated by Marco Castelluccio. 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