Mercurius

Implement GraphQL servers and gateways with Fastify

README

Mercurius Logo

mercurius


CI workflow

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.
- Subscriptions.
- Federation support.
- Federated subscriptions support.
- Gateway implementation, including Subscriptions.
- Batched query support.
- Customisable persisted queries.

Docs


- API
- Faq

Install


  1. ``` sh
  2. npm i fastify mercurius graphql
  3. # or
  4. yarn add fastify mercurius graphql
  5. ```

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

Quick Start


  1. ``` js
  2. 'use strict'

  3. const Fastify = require('fastify')
  4. const mercurius = require('mercurius')

  5. const app = Fastify()

  6. const schema = `
  7.   type Query {
  8.     add(x: Int, y: Int): Int
  9.   }
  10. `

  11. const resolvers = {
  12.   Query: {
  13.     add: async (_, { x, y }) => x + y
  14.   }
  15. }

  16. app.register(mercurius, {
  17.   schema,
  18.   resolvers
  19. })

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

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

Examples


Check GitHub repo for more examples.

Acknowledgements


The project is kindly sponsored by:

- NearForm for Matteo's time in maintaining this module.

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