import { d as defineEventHandler, dL as optionalAuth, eB as toWebRequest, s as setResponseHeader, b2 as setResponseStatus } from '../../nitro/nitro.mjs';
import { createYoga } from 'graphql-yoga';
import { g as getGraphQLSchema } from '../../_/schema-builder.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';
import 'graphql';
import '../../_/audit-log-actor.mjs';

let yogaInstance = null;
function getYoga() {
  if (!yogaInstance) {
    yogaInstance = createYoga({
      schema: () => getGraphQLSchema(),
      graphqlEndpoint: "/api/graphql",
      landingPage: false,
      graphiql: {
        title: "Notty CMS GraphQL"
      }
    });
  }
  return yogaInstance;
}
const graphql = defineEventHandler(async (event) => {
  var _a, _b, _c;
  await optionalAuth(event);
  const graphqlContext = {
    user: (_a = event.context.user) != null ? _a : null,
    adminUser: (_b = event.context.adminUser) != null ? _b : null,
    apiToken: (_c = event.context.apiToken) != null ? _c : null
  };
  const yoga = getYoga();
  const request = toWebRequest(event);
  const response = await yoga.fetch(request, graphqlContext);
  response.headers.forEach((value, key) => {
    setResponseHeader(event, key, value);
  });
  setResponseStatus(event, response.status);
  return response.text();
});

export { graphql as default };
//# sourceMappingURL=graphql.mjs.map
