Skip to content

Commit 3173e12

Browse files
committed
Added library name to error message for easier debugging, fixed lack of library's own error messages on empty schema in drizzle instance
1 parent e34eea8 commit 3173e12

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "drizzle-graphql",
33
"type": "module",
44
"author": "Drizzle Team",
5-
"version": "0.8.3",
5+
"version": "0.8.4",
66
"description": "Automatically generate GraphQL schema or customizable schema config fields from Drizzle ORM schema",
77
"scripts": {
88
"build": "pnpm tsx scripts/build.ts",

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ export const buildSchema = <TDbClient extends AnyDrizzleDB<any>>(
2121
const schema = db._.fullSchema;
2222
if (!schema) {
2323
throw new Error(
24-
"Schema not found in drizzle instance. Make sure you're using drizzle-orm v0.30.9 or above and schema is passed to drizzle constructor!",
24+
"Drizzle-GraphQL Error: Schema not found in drizzle instance. Make sure you're using drizzle-orm v0.30.9 or above and schema is passed to drizzle constructor!",
2525
);
2626
}
2727

2828
if (typeof config?.relationsDepthLimit === 'number') {
2929
if (config.relationsDepthLimit < 0) {
30-
throw new Error('config.relationsDepthLimit is supposed to be nonnegative integer or undefined!');
30+
throw new Error(
31+
'Drizzle-GraphQL Error: config.relationsDepthLimit is supposed to be nonnegative integer or undefined!',
32+
);
3133
}
3234
if (config.relationsDepthLimit !== ~~config.relationsDepthLimit) {
33-
throw new Error('config.relationsDepthLimit is supposed to be nonnegative integer or undefined!');
35+
throw new Error(
36+
'Drizzle-GraphQL Error: config.relationsDepthLimit is supposed to be nonnegative integer or undefined!',
37+
);
3438
}
3539
}
3640

@@ -41,7 +45,7 @@ export const buildSchema = <TDbClient extends AnyDrizzleDB<any>>(
4145
generatorOutput = generatePG(db, schema, config?.relationsDepthLimit);
4246
} else if (is(db, BaseSQLiteDatabase)) {
4347
generatorOutput = generateSQLite(db, schema, config?.relationsDepthLimit);
44-
} else throw new Error('Unknown database instance type');
48+
} else throw new Error('Drizzle-GraphQL Error: Unknown database instance type');
4549

4650
const { queries, mutations, inputs, types } = generatorOutput;
4751

src/util/builders/mysql.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const generateSelectArray = (
4545
| undefined;
4646
if (!queryBase) {
4747
throw new Error(
48-
`Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
48+
`Drizzle-GraphQL Error: Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
4949
);
5050
}
5151

@@ -116,7 +116,7 @@ const generateSelectSingle = (
116116
| undefined;
117117
if (!queryBase) {
118118
throw new Error(
119-
`Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
119+
`Drizzle-GraphQL Error: Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
120120
);
121121
}
122122

@@ -346,6 +346,12 @@ export const generateSchemaData = <
346346
const tableEntries = schemaEntries.filter(([key, value]) => is(value, MySqlTable)) as [string, MySqlTable][];
347347
const tables = Object.fromEntries(tableEntries);
348348

349+
if (!tableEntries.length) {
350+
throw new Error(
351+
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?",
352+
);
353+
}
354+
349355
const rawRelations = schemaEntries
350356
.filter(([key, value]) => is(value, Relations))
351357
.map<[string, Relations]>(([key, value]) => [

src/util/builders/pg.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const generateSelectArray = (
4545
| undefined;
4646
if (!queryBase) {
4747
throw new Error(
48-
`Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
48+
`Drizzle-GraphQL Error: Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
4949
);
5050
}
5151

@@ -116,7 +116,7 @@ const generateSelectSingle = (
116116
| undefined;
117117
if (!queryBase) {
118118
throw new Error(
119-
`Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
119+
`Drizzle-GraphQL Error: Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
120120
);
121121
}
122122

@@ -360,6 +360,12 @@ export const generateSchemaData = <
360360
PgTable
361361
>;
362362

363+
if (!tableEntries.length) {
364+
throw new Error(
365+
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?",
366+
);
367+
}
368+
363369
const rawRelations = schemaEntries
364370
.filter(([key, value]) => is(value, Relations))
365371
.map<[string, Relations]>(([key, value]) => [

src/util/builders/sqlite.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const generateSelectArray = (
4545
| undefined;
4646
if (!queryBase) {
4747
throw new Error(
48-
`Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
48+
`Drizzle-GraphQL Error: Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
4949
);
5050
}
5151

@@ -116,7 +116,7 @@ const generateSelectSingle = (
116116
| undefined;
117117
if (!queryBase) {
118118
throw new Error(
119-
`Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
119+
`Drizzle-GraphQL Error: Table ${tableName} not found in drizzle instance. Did you forget to pass schema to drizzle constructor?`,
120120
);
121121
}
122122

@@ -363,9 +363,10 @@ export const generateSchemaData = <
363363
string,
364364
SQLiteTable
365365
>;
366-
if (!tables || !Object.keys(tables).length) {
366+
367+
if (!tableEntries.length) {
367368
throw new Error(
368-
`Unable to extract tables from drizzle instance.\nDid you forget to pass tables to graphql schema constructor?`,
369+
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?",
369370
);
370371
}
371372

src/util/type-converter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const columnToGraphQLCore = (column: Column, columnName: string, tableName: stri
7171
}
7272
case 'custom':
7373
default:
74-
throw new Error(`Type ${column.dataType} is not implemented!`);
74+
throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
7575
}
7676
};
7777

0 commit comments

Comments
 (0)