Mercurius is a GraphQL adapter for Fastify
Features:
npm i fastify mercurius graphql
# or
yarn add fastify mercurius graphql
The previous name of this module was fastify-gql (< 6.0.0).
'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)
Check GitHub repo for more examples.
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/, andyou can find that codebase in https://github.com/marco-c/mercurius.
MIT