fix: prisma import, rename global._prisma

This commit is contained in:
Vyacheslav Matyukhin 2022-04-23 00:49:52 +04:00
parent 66938bcaf4
commit 02cb8089a7
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
3 changed files with 5 additions and 9 deletions

View File

@ -3,13 +3,13 @@ import { PrismaClient } from "@prisma/client";
declare global { declare global {
// allow global `var` declarations // allow global `var` declarations
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var prisma: PrismaClient | undefined; var _prisma: PrismaClient | undefined;
} }
export const prisma = export const prisma =
global.prisma || global._prisma ||
new PrismaClient({ new PrismaClient({
log: ["query"], log: ["query"],
}); });
if (process.env.NODE_ENV !== "production") global.prisma = prisma; if (process.env.NODE_ENV !== "production") global._prisma = prisma;

View File

@ -1,5 +1,6 @@
import { Question } from "@prisma/client"; import { Question } from "@prisma/client";
import { prisma } from "./database/prisma";
import { measureTime } from "./utils/measureTime"; import { measureTime } from "./utils/measureTime";
export async function getFrontpage(): Promise<Question[]> { export async function getFrontpage(): Promise<Question[]> {

View File

@ -7,12 +7,7 @@ builder.queryField("frontpage", (t) =>
type: [QuestionObj], type: [QuestionObj],
description: "Get a list of questions that are currently on the frontpage", description: "Get a list of questions that are currently on the frontpage",
resolve: async () => { resolve: async () => {
try { return await getFrontpage();
return await getFrontpage();
} catch (e) {
console.error(e);
throw e;
}
}, },
}) })
); );