Files
blackroad-os-api-gateway/src/plugins/graphql.ts
2025-11-24 01:26:02 -06:00

33 lines
720 B
TypeScript

import { FastifyInstance } from 'fastify';
import fp from 'fastify-plugin';
import mercurius from 'mercurius';
const typeDefs = /* GraphQL */ `
type Query {
_ping: String
}
# TODO(gateway-next): Extend schema with federation v2 directives and compose remote schemas.
`;
const resolvers = {
Query: {
_ping: async () => 'pong',
},
};
async function graphqlPlugin(fastify: FastifyInstance) {
fastify.register(mercurius, {
schema: typeDefs,
resolvers,
graphiql: process.env.NODE_ENV !== 'production',
context: () => ({
// TODO(gateway-next): Inject authenticated user + stitched service clients.
}),
});
}
export default fp(graphqlPlugin, {
name: 'graphql-plugin',
});