From c7d427ff278630e094d9e4cc1c3005e270cc973f Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 13 Jul 2023 16:00:03 +1000 Subject: [PATCH 1/2] fix errors when db.url is undefined --- packages/core/src/artifacts.ts | 1 + packages/core/src/lib/config.ts | 6 +++++- packages/core/src/types/config/index.ts | 12 ++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/core/src/artifacts.ts b/packages/core/src/artifacts.ts index 3df0b717203..65a80991ce0 100644 --- a/packages/core/src/artifacts.ts +++ b/packages/core/src/artifacts.ts @@ -187,6 +187,7 @@ export async function generateTypescriptTypesAndPrisma( if (dataProxy === true) { console.log('✨ Generating Prisma Client (data proxy)'); } + await Promise.all([ generatePrismaClient(paths.schema.prisma, dataProxy), generateTypescriptTypes(cwd, config, graphQLSchema), diff --git a/packages/core/src/lib/config.ts b/packages/core/src/lib/config.ts index cc8751fe907..fc429921cf1 100644 --- a/packages/core/src/lib/config.ts +++ b/packages/core/src/lib/config.ts @@ -92,11 +92,15 @@ function applyIdFieldDefaults(config: KeystoneConfig): KeystoneConfig['lists'] { export function initConfig(config: KeystoneConfig) { if (!['postgresql', 'sqlite', 'mysql'].includes(config.db.provider)) { - throw new Error( + throw new TypeError( 'Invalid db configuration. Please specify db.provider as either "sqlite", "postgresql" or "mysql"' ); } + // WARNING: Typescript should prevent this, but empty string is useful for Prisma errors + config.db.url ??= 'postgres://'; + + // TODO: use zod or something if want to follow this path return { ...config, lists: applyIdFieldDefaults(config), diff --git a/packages/core/src/types/config/index.ts b/packages/core/src/types/config/index.ts index 570b8e95b50..fafb57cf340 100644 --- a/packages/core/src/types/config/index.ts +++ b/packages/core/src/types/config/index.ts @@ -140,22 +140,22 @@ type PrismaLogDefinition = { }; export type DatabaseConfig = { + provider: DatabaseProvider; url: string; + shadowDatabaseUrl?: string; onConnect?: (args: KeystoneContext) => Promise; - /** @deprecated */ - useMigrations?: boolean; enableLogging?: boolean | PrismaLogLevel | Array; idField?: IdFieldConfig; - provider: DatabaseProvider; + prismaClientPath?: string; + extendPrismaSchema?: (schema: string) => string; + /** @deprecated */ + useMigrations?: boolean; /** @deprecated use extendPrismaSchema */ prismaPreviewFeatures?: readonly string[]; // https://www.prisma.io/docs/concepts/components/preview-features /** @deprecated use extendPrismaSchema */ additionalPrismaDatasourceProperties?: { [key: string]: string }; - - prismaClientPath?: string; - extendPrismaSchema?: (schema: string) => string; }; // config.ui From a46ebf9a57cfb0590cbf0805fd02f3d2b4e379ce Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 13 Jul 2023 16:07:48 +1000 Subject: [PATCH 2/2] add changeset --- .changeset/better-errors-please.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/better-errors-please.md diff --git a/.changeset/better-errors-please.md b/.changeset/better-errors-please.md new file mode 100644 index 00000000000..d2b2b3194ff --- /dev/null +++ b/.changeset/better-errors-please.md @@ -0,0 +1,5 @@ +--- +'@keystone-6/core': patch +--- + +Fixes misleading error when `db.url` is `undefined`