Mercurius integration
Mercurius is a GraphQL adapter for Fastify. It is very simple to set up and does not require an HTTP adapter from InversifyJS.
You can simply create a Fastify instance, register Mercurius, and start the server.
import fastify, { FastifyInstance } from 'fastify';
import mercurius from 'mercurius';
const app: FastifyInstance = fastify();
const schema: string = `
type Query {
add(x: Int, y: Int): Int
}
`;
const resolvers: mercurius.IResolvers<unknown, mercurius.MercuriusContext> = {
Query: {
add: async (_: unknown, { x, y }: { x: number; y: number }) => x + y,
},
};
app.register(mercurius, {
resolvers,
schema,
});
await app.listen({ port: 3000 });
If you want to use the InversifyJS HTTP adapter, you can get the Fastify instance by calling adapter.build() and then register Mercurius.
For more information, please refer to the Mercurius documentation.