From b4a9616cbc31d26c1e9006fc9e355dd86540d6c4 Mon Sep 17 00:00:00 2001 From: jiahui92 <547652008@qq.com> Date: Thu, 19 Sep 2024 16:00:08 +0800 Subject: [PATCH 1/2] fix: large response array size call 'require()' many times make gql slow --- packages/plugins/src/select.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/plugins/src/select.ts b/packages/plugins/src/select.ts index 0a2f8cb7..5234209c 100644 --- a/packages/plugins/src/select.ts +++ b/packages/plugins/src/select.ts @@ -1,6 +1,7 @@ import { GraphQLResolveInfo } from 'graphql'; import { DMMF } from '@paljs/types'; import { parseResolveInfo } from 'graphql-parse-resolve-info'; +import { Prisma } from '@prisma/client'; export interface PrismaSelectOptions< ModelName extends string, @@ -122,8 +123,9 @@ export class PrismaSelect< }); return models; } else { - const { Prisma } = require('@prisma/client'); + // @ts-ignore: Prisma.dmmf is a lazy/runtime property and not defined in @prisma/client ts type if (Prisma.dmmf && Prisma.dmmf.datamodel) { + // @ts-ignore return Prisma.dmmf.datamodel.models; } else { return []; From 81eed8fc82d4ddd6bc360e455a8e1f30643b2185 Mon Sep 17 00:00:00 2001 From: jiahui92 <547652008@qq.com> Date: Mon, 30 Sep 2024 16:49:29 +0800 Subject: [PATCH 2/2] fix: ts-ignore --- packages/plugins/src/select.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/plugins/src/select.ts b/packages/plugins/src/select.ts index 5234209c..da3e757b 100644 --- a/packages/plugins/src/select.ts +++ b/packages/plugins/src/select.ts @@ -123,10 +123,10 @@ export class PrismaSelect< }); return models; } else { - // @ts-ignore: Prisma.dmmf is a lazy/runtime property and not defined in @prisma/client ts type - if (Prisma.dmmf && Prisma.dmmf.datamodel) { - // @ts-ignore - return Prisma.dmmf.datamodel.models; + // Prisma.dmmf is a lazy/runtime property and not defined in @prisma/client ts type + const dmmf = (Prisma as any).dmmf; + if (dmmf && dmmf.datamodel) { + return dmmf.datamodel.models; } else { return []; }