Mercurius is 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.
- Federated subscriptions support.
- Gateway implementation, including Subscriptions.
- Batched query support.
- Customisable persisted queries.
npm i fastify mercurius
The previous name of this module is fastify-gql (< 6.0.0).
- Install
- Example
- Context
- API
- Federation
- Subscriptions
- Batched Queries
- Persisted Queries
- Plugins
- Integrations
- Acknowledgements
- License
'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(3000)
See test.js for more examples, docs are coming.
'use strict'
const Fastify = require('fastify')
const mercurius = require('mercurius')
const { makeExecutableSchema } = require('@graphql-tools/schema')
const app = Fastify()
const typeDefs = `
type Query {
add(x: Int, y: Int): Int
}
`
const resolvers = {
Query: {
add: async (_, { x, y }) => x + y
}
}
app.register(mercurius, {
schema: makeExecutableSchema({ typeDefs, resolvers })
})
app.get('/', async function (req, reply) {
const query = '{ add(x: 2, y: 2) }'
return reply.graphql(query)
})
app.listen(3000)
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.
MIT