import Fastify from 'fastify';
import mercurius from 'mercurius';

import { config } from './config.js';
import { prisma } from './prisma.js';
import { resolvers, schema } from './graphql/schema.js';

const app = Fastify({ logger: true });

app.register(mercurius, {
  schema,
  resolvers,
  graphiql: true,
});

app.get('/health', async () => ({ ok: true }));

app.addHook('onClose', async () => {
  await prisma.$disconnect();
});

await app.listen({ host: config.host, port: config.port });
