@pothos/plugin-drizzle 0.11.2 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dts/connection-helpers.d.ts +7 -5
  3. package/dts/connection-helpers.d.ts.map +1 -1
  4. package/dts/drizzle-field-builder.d.ts +2 -2
  5. package/dts/drizzle-field-builder.d.ts.map +1 -1
  6. package/dts/global-types.d.ts +23 -24
  7. package/dts/global-types.d.ts.map +1 -1
  8. package/dts/interface-ref.d.ts +3 -3
  9. package/dts/interface-ref.d.ts.map +1 -1
  10. package/dts/model-loader.d.ts.map +1 -1
  11. package/dts/node-ref.d.ts +1 -1
  12. package/dts/node-ref.d.ts.map +1 -1
  13. package/dts/object-ref.d.ts +2 -2
  14. package/dts/object-ref.d.ts.map +1 -1
  15. package/dts/types.d.ts +35 -31
  16. package/dts/types.d.ts.map +1 -1
  17. package/dts/utils/config.d.ts.map +1 -1
  18. package/dts/utils/cursors.d.ts +3 -3
  19. package/dts/utils/cursors.d.ts.map +1 -1
  20. package/dts/utils/selections.d.ts +1 -1
  21. package/dts/utils/selections.d.ts.map +1 -1
  22. package/esm/connection-helpers.d.ts +7 -5
  23. package/esm/connection-helpers.d.ts.map +1 -1
  24. package/esm/connection-helpers.js +2 -2
  25. package/esm/connection-helpers.js.map +1 -1
  26. package/esm/drizzle-field-builder.d.ts +2 -2
  27. package/esm/drizzle-field-builder.d.ts.map +1 -1
  28. package/esm/drizzle-field-builder.js +13 -19
  29. package/esm/drizzle-field-builder.js.map +1 -1
  30. package/esm/global-types.d.ts +34 -35
  31. package/esm/global-types.d.ts.map +1 -1
  32. package/esm/global-types.js.map +1 -1
  33. package/esm/interface-ref.d.ts +3 -3
  34. package/esm/interface-ref.d.ts.map +1 -1
  35. package/esm/model-loader.d.ts.map +1 -1
  36. package/esm/model-loader.js +3 -3
  37. package/esm/model-loader.js.map +1 -1
  38. package/esm/node-ref.d.ts +1 -1
  39. package/esm/node-ref.d.ts.map +1 -1
  40. package/esm/object-ref.d.ts +2 -2
  41. package/esm/object-ref.d.ts.map +1 -1
  42. package/esm/schema-builder.js +8 -8
  43. package/esm/schema-builder.js.map +1 -1
  44. package/esm/types.d.ts +35 -31
  45. package/esm/types.d.ts.map +1 -1
  46. package/esm/types.js.map +1 -1
  47. package/esm/utils/config.d.ts.map +1 -1
  48. package/esm/utils/config.js +17 -21
  49. package/esm/utils/config.js.map +1 -1
  50. package/esm/utils/cursors.d.ts +3 -3
  51. package/esm/utils/cursors.d.ts.map +1 -1
  52. package/esm/utils/cursors.js +17 -14
  53. package/esm/utils/cursors.js.map +1 -1
  54. package/esm/utils/selections.d.ts +1 -1
  55. package/esm/utils/selections.d.ts.map +1 -1
  56. package/esm/utils/selections.js +6 -13
  57. package/esm/utils/selections.js.map +1 -1
  58. package/lib/connection-helpers.js +2 -2
  59. package/lib/connection-helpers.js.map +1 -1
  60. package/lib/drizzle-field-builder.js +12 -18
  61. package/lib/drizzle-field-builder.js.map +1 -1
  62. package/lib/model-loader.js +2 -2
  63. package/lib/model-loader.js.map +1 -1
  64. package/lib/schema-builder.js +8 -8
  65. package/lib/schema-builder.js.map +1 -1
  66. package/lib/types.js.map +1 -1
  67. package/lib/utils/config.js +16 -20
  68. package/lib/utils/config.js.map +1 -1
  69. package/lib/utils/cursors.js +17 -14
  70. package/lib/utils/cursors.js.map +1 -1
  71. package/lib/utils/selections.js +6 -12
  72. package/lib/utils/selections.js.map +1 -1
  73. package/package.json +7 -7
  74. package/src/connection-helpers.ts +13 -12
  75. package/src/drizzle-field-builder.ts +14 -30
  76. package/src/global-types.ts +59 -85
  77. package/src/interface-ref.ts +3 -3
  78. package/src/model-loader.ts +4 -3
  79. package/src/node-ref.ts +1 -1
  80. package/src/object-ref.ts +2 -2
  81. package/src/schema-builder.ts +8 -8
  82. package/src/types.ts +45 -47
  83. package/src/utils/config.ts +21 -32
  84. package/src/utils/cursors.ts +31 -18
  85. package/src/utils/selections.ts +7 -17
package/src/types.ts CHANGED
@@ -75,7 +75,7 @@ export type DrizzlePluginOptions<Types extends SchemaTypes> = {
75
75
  }[];
76
76
  readonly columns: Column[];
77
77
  };
78
- relations?: Types['DrizzleRelations'];
78
+ relations: Types['DrizzleRelations'];
79
79
  }
80
80
  );
81
81
 
@@ -93,7 +93,7 @@ type NameOrVariant =
93
93
 
94
94
  export type DrizzleObjectOptions<
95
95
  Types extends SchemaTypes,
96
- Table extends keyof Types['DrizzleRelationsConfig'],
96
+ Table extends keyof Types['DrizzleRelations'],
97
97
  Shape,
98
98
  Selection,
99
99
  Interfaces extends InterfaceParam<Types>[],
@@ -103,7 +103,7 @@ export type DrizzleObjectOptions<
103
103
  fields?: (
104
104
  t: DrizzleObjectFieldBuilder<
105
105
  Types,
106
- Types['DrizzleRelationsConfig'][Table],
106
+ Types['DrizzleRelations'][Table],
107
107
  Shape & { [drizzleTableName]?: Table }
108
108
  >,
109
109
  ) => FieldMap;
@@ -111,7 +111,7 @@ export type DrizzleObjectOptions<
111
111
 
112
112
  export type DrizzleInterfaceOptions<
113
113
  Types extends SchemaTypes,
114
- Table extends keyof Types['DrizzleRelationsConfig'],
114
+ Table extends keyof Types['DrizzleRelations'],
115
115
  Shape,
116
116
  Selection,
117
117
  Interfaces extends InterfaceParam<Types>[],
@@ -121,7 +121,7 @@ export type DrizzleInterfaceOptions<
121
121
  fields?: (
122
122
  t: DrizzleObjectFieldBuilder<
123
123
  Types,
124
- Types['DrizzleRelationsConfig'][Table],
124
+ Types['DrizzleRelations'][Table],
125
125
  Shape & { [drizzleTableName]?: Table }
126
126
  >,
127
127
  ) => FieldMap;
@@ -129,7 +129,7 @@ export type DrizzleInterfaceOptions<
129
129
 
130
130
  export type DrizzleNodeOptions<
131
131
  Types extends SchemaTypes,
132
- Table extends keyof Types['DrizzleRelationsConfig'],
132
+ Table extends keyof Types['DrizzleRelations'],
133
133
  Shape,
134
134
  Selection,
135
135
  Interfaces extends InterfaceParam<Types>[],
@@ -157,14 +157,14 @@ export type DrizzleNodeOptions<
157
157
  (
158
158
  | Column
159
159
  | Column[]
160
- | ((columns: Types['DrizzleRelationsConfig'][Table]['columns']) => Column | Column[])
160
+ | ((columns: Types['DrizzleRelations'][Table]['table']) => Column | Column[])
161
161
  );
162
162
  };
163
163
  select?: Selection;
164
164
  fields?: (
165
165
  t: DrizzleObjectFieldBuilder<
166
166
  Types,
167
- Types['DrizzleRelationsConfig'][Table],
167
+ Types['DrizzleRelations'][Table],
168
168
  Shape & { [drizzleTableName]?: Table }
169
169
  >,
170
170
  ) => FieldMap;
@@ -172,7 +172,7 @@ export type DrizzleNodeOptions<
172
172
 
173
173
  export type ShapeFromIdColumns<
174
174
  Types extends SchemaTypes,
175
- Table extends keyof Types['DrizzleRelationsConfig'],
175
+ Table extends keyof Types['DrizzleRelations'],
176
176
  IDColumns,
177
177
  > = IDColumns extends Column
178
178
  ? IDColumns['_']['data']
@@ -191,7 +191,7 @@ export type ShapeFromIdColumns<
191
191
  export type DrizzleFieldOptions<
192
192
  Types extends SchemaTypes,
193
193
  ParentShape,
194
- Table extends keyof Types['DrizzleRelationsConfig'],
194
+ Table extends keyof Types['DrizzleRelations'],
195
195
  Type extends TypeParam<Types>,
196
196
  Nullable extends FieldNullability<Type>,
197
197
  Args extends InputFieldMap,
@@ -214,7 +214,9 @@ export type DrizzleFieldOptions<
214
214
  > & {
215
215
  type: Param;
216
216
  resolve: (
217
- query: <T extends QueryForDrizzleField<Types, Param, Table>>(selection?: T) => T,
217
+ query: <T extends QueryForDrizzleField<Types, Param, Table>>(
218
+ selection?: T,
219
+ ) => Omit<T, 'columns'>,
218
220
  parent: ParentShape,
219
221
  args: InputShapeFromFields<Args>,
220
222
  ctx: Types['Context'],
@@ -225,7 +227,7 @@ export type DrizzleFieldOptions<
225
227
  export type DrizzleFieldWithInputOptions<
226
228
  Types extends SchemaTypes,
227
229
  ParentShape,
228
- Table extends keyof Types['DrizzleRelationsConfig'],
230
+ Table extends keyof Types['DrizzleRelations'],
229
231
  Type extends TypeParam<Types>,
230
232
  Nullable extends FieldNullability<Type>,
231
233
  Args extends InputFieldMap,
@@ -271,7 +273,7 @@ export type DrizzleObjectFieldOptions<
271
273
  unknown extends Select
272
274
  ? ParentShape
273
275
  : BuildQueryResult<
274
- Types['DrizzleRelationsConfig'],
276
+ Types['DrizzleRelations'],
275
277
  ExtractTable<Types, ParentShape>,
276
278
  Record<string, unknown> &
277
279
  // biome-ignore lint/suspicious/noExplicitAny: this is fine
@@ -302,7 +304,7 @@ export type DrizzleObjectFieldOptions<
302
304
  > & {
303
305
  select?: Select &
304
306
  (
305
- | DBQueryConfig<'one', Types['DrizzleRelationsConfig'], ExtractTable<Types, ParentShape>>
307
+ | DBQueryConfig<'one', Types['DrizzleRelations'], ExtractTable<Types, ParentShape>>
306
308
  | ((
307
309
  args: InputShapeFromFields<Args>,
308
310
  ctx: Types['Context'],
@@ -310,11 +312,7 @@ export type DrizzleObjectFieldOptions<
310
312
  selection?: Selection,
311
313
  path?: string[],
312
314
  ) => Selection,
313
- ) => DBQueryConfig<
314
- 'one',
315
- Types['DrizzleRelationsConfig'],
316
- ExtractTable<Types, ParentShape>
317
- >)
315
+ ) => DBQueryConfig<'one', Types['DrizzleRelations'], ExtractTable<Types, ParentShape>>)
318
316
  );
319
317
  };
320
318
 
@@ -335,9 +333,9 @@ export type DrizzleFieldSelection =
335
333
  ) => SelectionMap);
336
334
 
337
335
  export type ExtractTable<Types extends SchemaTypes, Shape> = Shape extends {
338
- [drizzleTableName]?: keyof Types['DrizzleRelationsConfig'];
336
+ [drizzleTableName]?: keyof Types['DrizzleRelations'];
339
337
  }
340
- ? Types['DrizzleRelationsConfig'][NonNullable<Shape[typeof drizzleTableName]>]
338
+ ? Types['DrizzleRelations'][NonNullable<Shape[typeof drizzleTableName]>]
341
339
  : never;
342
340
 
343
341
  export type RelatedFieldOptions<
@@ -371,7 +369,7 @@ export type RelatedFieldOptions<
371
369
 
372
370
  export type VariantFieldOptions<
373
371
  Types extends SchemaTypes,
374
- Table extends keyof Types['DrizzleRelationsConfig'],
372
+ Table extends keyof Types['DrizzleRelations'],
375
373
  // biome-ignore lint/suspicious/noExplicitAny: this is fine
376
374
  Variant extends DrizzleRef<any, Table> | Table,
377
375
  Args extends InputFieldMap,
@@ -400,7 +398,7 @@ export type VariantFieldOptions<
400
398
  unknown extends ResolveShape
401
399
  ? Shape
402
400
  : BuildQueryResult<
403
- Types['DrizzleRelationsConfig'],
401
+ Types['DrizzleRelations'],
404
402
  ExtractTable<Types, Shape>,
405
403
  Record<string, unknown> &
406
404
  // biome-ignore lint/suspicious/noExplicitAny: this is fine
@@ -425,8 +423,8 @@ export type RefForRelation<Types extends SchemaTypes, Rel extends Relation> = Re
425
423
  : [ObjectRef<Types, TypesForRelation<Types, Rel>>];
426
424
 
427
425
  export type TypesForRelation<Types extends SchemaTypes, Rel extends Relation> = BuildQueryResult<
428
- Types['DrizzleRelationsConfig'],
429
- Types['DrizzleRelationsConfig'][Rel['targetTable']['_']['name']],
426
+ Types['DrizzleRelations'],
427
+ Types['DrizzleRelations'][Rel['targetTable']['_']['name']],
430
428
  true
431
429
  >;
432
430
 
@@ -441,16 +439,16 @@ export type QueryForField<
441
439
  ? Omit<
442
440
  DBQueryConfig<
443
441
  'one',
444
- Types['DrizzleRelationsConfig'],
445
- Types['DrizzleRelationsConfig'][Rel['targetTable']['_']['name']]
442
+ Types['DrizzleRelations'],
443
+ Types['DrizzleRelations'][Rel['targetTable']['_']['name']]
446
444
  >,
447
445
  'columns' | 'extra' | 'with'
448
446
  >
449
447
  : Omit<
450
448
  DBQueryConfig<
451
449
  'many',
452
- Types['DrizzleRelationsConfig'],
453
- Types['DrizzleRelationsConfig'][Rel['targetTable']['_']['name']]
450
+ Types['DrizzleRelations'],
451
+ Types['DrizzleRelations'][Rel['targetTable']['_']['name']]
454
452
  >,
455
453
  'columns' | 'extra' | 'with'
456
454
  >
@@ -461,14 +459,9 @@ export type QueryForField<
461
459
  export type QueryForDrizzleField<
462
460
  Types extends SchemaTypes,
463
461
  Param,
464
- Table extends keyof Types['DrizzleRelationsConfig'],
462
+ Table extends keyof Types['DrizzleRelations'],
465
463
  > = Omit<
466
- DBQueryConfig<
467
- 'many',
468
- Types['DrizzleRelationsConfig'],
469
- Types['DrizzleRelationsConfig'][Table],
470
- true
471
- >,
464
+ DBQueryConfig<'many', Types['DrizzleRelations'], Types['DrizzleRelations'][Table]>,
472
465
  Param extends [unknown] ? never : 'limit'
473
466
  >;
474
467
 
@@ -477,33 +470,33 @@ export type QueryForRelatedConnection<
477
470
  Table extends TableRelationalConfig,
478
471
  Args,
479
472
  > = Omit<
480
- DBQueryConfig<'many', Types['DrizzleRelationsConfig'], Table>,
473
+ DBQueryConfig<'many', Types['DrizzleRelations'], Table>,
481
474
  'limit' | 'offset' | 'columns' | 'extra' | 'with' | 'orderBy'
482
475
  > & {
483
- orderBy?: ConnectionOrderBy<Table> | ((columns: Table['columns']) => ConnectionOrderBy<Table>);
476
+ orderBy?: ConnectionOrderBy<Table> | ((table: Table) => ConnectionOrderBy<Table>);
484
477
  } extends infer QueryConfig
485
478
  ? QueryConfig | ((args: Args, context: Types['Context']) => QueryConfig)
486
479
  : never;
487
480
 
488
481
  export type QueryForDrizzleConnection<
489
482
  Types extends SchemaTypes,
490
- Table extends TableRelationalConfig,
483
+ TableConfig extends TableRelationalConfig,
491
484
  > = Omit<
492
- DBQueryConfig<'many', Types['DrizzleRelationsConfig'], Table>,
485
+ DBQueryConfig<'many', Types['DrizzleRelations'], TableConfig>,
493
486
  'limit' | 'offset' | 'orderBy'
494
487
  > & {
495
- orderBy?: ConnectionOrderBy<Table> | ((columns: Table['columns']) => ConnectionOrderBy<Table>);
488
+ orderBy?: ConnectionOrderBy<TableConfig> | ((table: Table) => ConnectionOrderBy<TableConfig>);
496
489
  };
497
490
 
498
491
  export type ListRelation<T extends TableRelationalConfig> = {
499
- [K in keyof T['relations']]: T['relations'][K] extends Many<string, string> ? K : never;
492
+ [K in keyof T['relations']]: T['relations'][K] extends Many<string> ? K : never;
500
493
  }[keyof T['relations']];
501
494
 
502
495
  export type DrizzleConnectionFieldOptions<
503
496
  Types extends SchemaTypes,
504
497
  ParentShape,
505
498
  Type extends // biome-ignore lint/suspicious/noExplicitAny: this is fine
506
- DrizzleRef<any, keyof Types['DrizzleRelationsConfig']> | keyof Types['DrizzleRelationsConfig'],
499
+ DrizzleRef<any, keyof Types['DrizzleRelations']> | keyof Types['DrizzleRelations'],
507
500
  TableConfig extends TableRelationalConfig,
508
501
  Param extends OutputType<Types>,
509
502
  Nullable extends boolean,
@@ -547,9 +540,11 @@ export type DrizzleConnectionFieldOptions<
547
540
  resolve: (
548
541
  query: <T extends QueryForRelatedConnection<Types, TableConfig, ConnectionArgs>>(
549
542
  selection?: T,
550
- ) => Omit<T, 'orderBy'> & {
543
+ ) => Omit<T, 'orderBy' | 'columns'> & {
551
544
  orderBy: {
552
- [K in keyof TableConfig['columns']]?: 'asc' | 'desc' | undefined;
545
+ [K in TableConfig['table']['_'] extends { columns: infer Columns }
546
+ ? keyof Columns
547
+ : never]?: 'asc' | 'desc' | undefined;
553
548
  };
554
549
  },
555
550
  parent: ParentShape,
@@ -572,7 +567,7 @@ export type RelatedConnectionOptions<
572
567
  Nullable extends boolean,
573
568
  Args extends InputFieldMap,
574
569
  NodeTable extends
575
- TableRelationalConfig = Types['DrizzleRelationsConfig'][Table['relations'][Field]['targetTable']['_']['name']],
570
+ TableRelationalConfig = Types['DrizzleRelations'][Table['relations'][Field]['targetTable']['_']['name']],
576
571
  > = Omit<
577
572
  PothosSchemaTypes.ObjectFieldOptions<
578
573
  Types,
@@ -627,7 +622,10 @@ export type ConnectionOrderBy<T extends TableRelationalConfig> =
627
622
  | Column
628
623
  | Column[]
629
624
  | {
630
- [K in keyof T['columns']]?: 'asc' | 'desc' | undefined;
625
+ [K in T['table']['_'] extends { columns: infer Columns } ? keyof Columns : never]?:
626
+ | 'asc'
627
+ | 'desc'
628
+ | undefined;
631
629
  };
632
630
 
633
631
  export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
@@ -1,5 +1,5 @@
1
1
  import { createContextCache, type SchemaTypes } from '@pothos/core';
2
- import { type AnyRelations, type Column, getTableName, type Table } from 'drizzle-orm';
2
+ import { type AnyRelations, type Column, getTableColumns, isTable, type Table } from 'drizzle-orm';
3
3
  import type { DrizzleClient } from '../types';
4
4
 
5
5
  export interface PothosDrizzleSchemaConfig {
@@ -17,46 +17,35 @@ const configCache = createContextCache(
17
17
  relations = (builder.options.drizzle.client as DrizzleClient)._.relations;
18
18
  }
19
19
 
20
- const dbToSchema = Object.values(relations.tables).reduce<Record<string, Table>>(
21
- (acc, table) => {
22
- const tableName = getTableName(table);
23
- if (tableName) {
24
- acc[tableName] = table;
25
- }
26
- return acc;
27
- },
28
- {},
29
- );
30
-
31
- const columnMappings = Object.values(dbToSchema).reduce<Record<string, Record<string, string>>>(
32
- (acc, table) => {
33
- acc[getTableName(table)] = Object.entries(table).reduce<Record<string, string>>(
34
- (acc, [name, column]) => {
35
- acc[(column as Column).name] = name;
36
- return acc;
37
- },
38
- {},
39
- );
40
- return acc;
41
- },
42
- {},
43
- );
20
+ const columnNameMappings: Record<string, string> = {};
21
+
22
+ Object.values(relations).forEach(({ table }) => {
23
+ if (isTable(table)) {
24
+ Object.entries(getTableColumns(table)).forEach(([tsName, col]) => {
25
+ if (col.uniqueName) {
26
+ columnNameMappings[col.uniqueName] = tsName;
27
+ }
28
+ });
29
+ }
30
+ });
44
31
 
45
32
  return {
46
33
  skipDeferredFragments: builder.options.drizzle.skipDeferredFragments ?? true,
47
34
  columnToTsName: (column) => {
48
- const tableName = getTableName(column.table);
49
- const table = columnMappings[tableName];
50
- const columnName = table?.[column.name];
35
+ if (!column.uniqueName) {
36
+ throw new Error(`Column ${String(column.name)} has no uniqueName`);
37
+ }
51
38
 
52
- if (!columnName) {
53
- throw new Error(`Could not find column mapping for ${tableName}.${column.name}`);
39
+ if (!(column.uniqueName in columnNameMappings)) {
40
+ throw new Error(`Typescript name not found for ${column.uniqueName}`);
54
41
  }
55
42
 
56
- return columnName;
43
+ return columnNameMappings[column.uniqueName];
57
44
  },
58
45
  getPrimaryKey: (tableName) => {
59
- const tableConfig = builder.options.drizzle.getTableConfig(relations.tables[tableName]);
46
+ const tableConfig = builder.options.drizzle.getTableConfig(
47
+ relations[tableName].table as Table,
48
+ );
60
49
 
61
50
  const primaryKey = tableConfig.columns.find((column) => column.primary);
62
51
 
@@ -5,7 +5,14 @@ import {
5
5
  PothosValidationError,
6
6
  type SchemaTypes,
7
7
  } from '@pothos/core';
8
- import type { Column, DBQueryConfig, SQL, TableConfig, TableRelationalConfig } from 'drizzle-orm';
8
+ import {
9
+ type Column,
10
+ type DBQueryConfig,
11
+ getTableColumns,
12
+ type SQL,
13
+ type Table,
14
+ type TableRelationalConfig,
15
+ } from 'drizzle-orm';
9
16
  import type { GraphQLResolveInfo } from 'graphql';
10
17
  import type { ConnectionOrderBy, QueryForDrizzleConnection } from '../types';
11
18
  import type { PothosDrizzleSchemaConfig } from './config';
@@ -150,18 +157,23 @@ export function parseSerializedIDColumn(id: string, field: Column): unknown {
150
157
  }
151
158
 
152
159
  try {
153
- switch (field.dataType) {
154
- case 'date':
155
- return new Date(id);
156
- case 'string':
157
- return id;
158
- case 'number':
159
- return Number.parseInt(id, 10);
160
- case 'bigint':
161
- return BigInt(id);
162
- default:
163
- throw new PothosValidationError(`Unsupported ID type ${field.dataType}`);
160
+ if (field.dataType.startsWith('number')) {
161
+ return Number.parseInt(id, 10);
164
162
  }
163
+
164
+ if (field.dataType.startsWith('bigint')) {
165
+ return BigInt(id);
166
+ }
167
+
168
+ if (field.dataType.startsWith('string')) {
169
+ return id;
170
+ }
171
+
172
+ if (field.dataType === 'object date') {
173
+ return new Date(id);
174
+ }
175
+
176
+ throw new PothosValidationError(`Unsupported ID type ${field.dataType}`);
165
177
  } catch (error: unknown) {
166
178
  if (error instanceof PothosValidationError) {
167
179
  throw error;
@@ -283,12 +295,12 @@ export interface DrizzleCursorConnectionQueryOptions {
283
295
  orderBy: ConnectionOrderBy<TableRelationalConfig>;
284
296
  where?: SQL;
285
297
  config: PothosDrizzleSchemaConfig;
286
- table: TableRelationalConfig | TableConfig;
298
+ table: TableRelationalConfig;
287
299
  }
288
300
 
289
301
  function parseOrderBy(
290
302
  config: PothosDrizzleSchemaConfig,
291
- table: TableRelationalConfig | TableConfig,
303
+ table: TableRelationalConfig,
292
304
  orderBy: ConnectionOrderBy<TableRelationalConfig>,
293
305
  invert: boolean,
294
306
  ) {
@@ -310,13 +322,14 @@ function parseOrderBy(
310
322
  normalized.push({ direction: 'asc', column: field });
311
323
  }
312
324
  } else {
325
+ const tableColumns = getTableColumns(table.table as Table);
313
326
  Object.entries(
314
327
  orderBy as {
315
328
  [k: string]: 'asc' | 'desc' | undefined;
316
329
  },
317
330
  ).forEach(([name, direction]) => {
318
331
  if (direction) {
319
- const column = table.columns[name] as Column;
332
+ const column = tableColumns[name];
320
333
  columns.push(column);
321
334
  entries.push([name, direction === 'asc' ? asc : desc]);
322
335
  normalized.push({ direction: direction, column });
@@ -506,7 +519,7 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
506
519
  ) => MaybePromise<readonly T[]>,
507
520
  parent: unknown,
508
521
  ) {
509
- const table = config.relations.tablesConfig[tableName];
522
+ const table = config.relations[tableName];
510
523
  let query: DBQueryConfig<'many'>;
511
524
  let formatter: (node: Record<string, unknown>) => string;
512
525
  const results = await resolve((q = {}) => {
@@ -514,8 +527,8 @@ export async function resolveDrizzleCursorConnection<T extends {}>(
514
527
  ...options,
515
528
  config,
516
529
  orderBy:
517
- (typeof q.orderBy === 'function' ? q.orderBy(table.columns) : q.orderBy) ??
518
- config.getPrimaryKey(table.tsName),
530
+ (typeof q.orderBy === 'function' ? q.orderBy(table.table as Table) : q.orderBy) ??
531
+ config.getPrimaryKey(table.name),
519
532
  table,
520
533
  });
521
534
  formatter = getCursorFormatter(cursorColumns, config);
@@ -1,10 +1,5 @@
1
1
  import { PothosValidationError } from '@pothos/core';
2
- import {
3
- type DBQueryConfig,
4
- getTableUniqueName,
5
- type Table,
6
- type TableRelationalConfig,
7
- } from 'drizzle-orm';
2
+ import type { DBQueryConfig, TableRelationalConfig } from 'drizzle-orm';
8
3
  import type { PothosDrizzleSchemaConfig } from './config';
9
4
  import { deepEqual } from './deep-equal';
10
5
  import type { LoaderMappings } from './loader-map';
@@ -132,12 +127,10 @@ export function mergeSelection(
132
127
  const relation = state.table.relations[key];
133
128
 
134
129
  if (!relation) {
135
- throw new PothosValidationError(`Relation ${key} does not exist on ${state.table.dbName}`);
130
+ throw new PothosValidationError(`Relation ${key} does not exist on ${state.table.name}`);
136
131
  }
137
132
 
138
- const tableUniqueName = getTableUniqueName(relation.targetTable as Table);
139
- const tableName = config.relations.tableNamesMap[tableUniqueName];
140
- merge(config.relations.tablesConfig[tableName], key, value as SelectionMap | boolean);
133
+ merge(config.relations[relation.targetTableName], key, value as SelectionMap | boolean);
141
134
  }
142
135
  }
143
136
 
@@ -184,21 +177,18 @@ export function selectionToQuery(
184
177
  ): SelectionMap {
185
178
  const query: SelectionMap & { extras: Record<string, unknown> } = {
186
179
  ...state.query,
180
+ columns: undefined,
187
181
  with: {},
188
- columns: {},
189
182
  extras: {},
190
183
  };
191
184
 
192
- if (state.allColumns) {
193
- for (const key of Object.keys(state.table.columns)) {
194
- query.columns![key] = true;
195
- }
196
- } else {
185
+ if (!state.allColumns) {
186
+ query.columns = {};
197
187
  for (const key of state.columns) {
198
188
  query.columns![key] = true;
199
189
  }
200
190
 
201
- for (const column of config.getPrimaryKey(state.table.tsName)) {
191
+ for (const column of config.getPrimaryKey(state.table.name)) {
202
192
  const tsName = config.columnToTsName(column);
203
193
  query.columns![tsName] = true;
204
194
  }