Mercurius
Mercurius is a GraphQL adapter for Fastify
Installation
sh
npm i fastify mercurius graphql @gqloom/core
sh
pnpm add fastify mercurius graphql @gqloom/core
sh
yarn add fastify mercurius graphql @gqloom/core
sh
bun add fastify mercurius graphql @gqloom/core
Usage
ts
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:
ts
import { useContext } from "@gqloom/core/context"
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.