Mercurius

Mercurius is a GraphQL adapter for Fastify

Installation

npm
yarn
pnpm
bun
npm install fastify mercurius graphql @gqloom/core

Usage

import { weave } from "@gqloom/core" import Fastify from "fastify" import mercurius from "mercurius" import { HelloResolver } from "./resolvers" const schema = weave(HelloResolver) const app = Fastify() app.register(mercurius, { schema }) app.listen({ port: 4000 }, () => { console.info("Mercurius server is running on http://localhost:4000") })

Contexts

When using GQLoom together with Mercurius, you can use MercuriusContext to label the type of context:

import { useContext } from "@gqloom/core" import { type MercuriusContext } from "mercurius" export function useAuthorization() { return useContext<MercuriusContext>().reply.request.headers.authorization }

You can also learn more about contexts in the Mercurius documentation.