import SchemaBuilder from "@pothos/core";
import ErrorsPlugin from "@pothos/plugin-errors";
import type { DB } from "../db/connection";
import type { SessionUser } from "../lib/auth";
import type Redis from "ioredis";
import { GraphQLDateTime, GraphQLJSON } from "graphql-scalars";

export type Context = {
  db: DB;
  redis: InstanceType<typeof Redis>;
  currentUser: SessionUser | null;
  request: Request;
  reply: unknown;
};

export const builder = new SchemaBuilder<{
  Context: Context;
  Scalars: {
    DateTime: { Input: Date; Output: Date };
    JSON: { Input: unknown; Output: unknown };
  };
}>({
  plugins: [ErrorsPlugin],
});

builder.addScalarType("DateTime", GraphQLDateTime, {});
builder.addScalarType("JSON", GraphQLJSON, {});

builder.queryType({});
builder.mutationType({});
