@pothos/plugin-drizzle 0.11.2 → 0.12.0

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 +6 -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 +33 -29
  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 +14 -18
  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 +33 -29
  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 +13 -17
  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 -22
  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 +41 -45
  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,
@@ -225,7 +225,7 @@ export type DrizzleFieldOptions<
225
225
  export type DrizzleFieldWithInputOptions<
226
226
  Types extends SchemaTypes,
227
227
  ParentShape,
228
- Table extends keyof Types['DrizzleRelationsConfig'],
228
+ Table extends keyof Types['DrizzleRelations'],
229
229
  Type extends TypeParam<Types>,
230
230
  Nullable extends FieldNullability<Type>,
231
231
  Args extends InputFieldMap,
@@ -271,7 +271,7 @@ export type DrizzleObjectFieldOptions<
271
271
  unknown extends Select
272
272
  ? ParentShape
273
273
  : BuildQueryResult<
274
- Types['DrizzleRelationsConfig'],
274
+ Types['DrizzleRelations'],
275
275
  ExtractTable<Types, ParentShape>,
276
276
  Record<string, unknown> &
277
277
  // biome-ignore lint/suspicious/noExplicitAny: this is fine
@@ -302,7 +302,7 @@ export type DrizzleObjectFieldOptions<
302
302
  > & {
303
303
  select?: Select &
304
304
  (
305
- | DBQueryConfig<'one', Types['DrizzleRelationsConfig'], ExtractTable<Types, ParentShape>>
305
+ | DBQueryConfig<'one', Types['DrizzleRelations'], ExtractTable<Types, ParentShape>>
306
306
  | ((
307
307
  args: InputShapeFromFields<Args>,
308
308
  ctx: Types['Context'],
@@ -310,11 +310,7 @@ export type DrizzleObjectFieldOptions<
310
310
  selection?: Selection,
311
311
  path?: string[],
312
312
  ) => Selection,
313
- ) => DBQueryConfig<
314
- 'one',
315
- Types['DrizzleRelationsConfig'],
316
- ExtractTable<Types, ParentShape>
317
- >)
313
+ ) => DBQueryConfig<'one', Types['DrizzleRelations'], ExtractTable<Types, ParentShape>>)
318
314
  );
319
315
  };
320
316
 
@@ -335,9 +331,9 @@ export type DrizzleFieldSelection =
335
331
  ) => SelectionMap);
336
332
 
337
333
  export type ExtractTable<Types extends SchemaTypes, Shape> = Shape extends {
338
- [drizzleTableName]?: keyof Types['DrizzleRelationsConfig'];
334
+ [drizzleTableName]?: keyof Types['DrizzleRelations'];
339
335
  }
340
- ? Types['DrizzleRelationsConfig'][NonNullable<Shape[typeof drizzleTableName]>]
336
+ ? Types['DrizzleRelations'][NonNullable<Shape[typeof drizzleTableName]>]
341
337
  : never;
342
338
 
343
339
  export type RelatedFieldOptions<
@@ -371,7 +367,7 @@ export type RelatedFieldOptions<
371
367
 
372
368
  export type VariantFieldOptions<
373
369
  Types extends SchemaTypes,
374
- Table extends keyof Types['DrizzleRelationsConfig'],
370
+ Table extends keyof Types['DrizzleRelations'],
375
371
  // biome-ignore lint/suspicious/noExplicitAny: this is fine
376
372
  Variant extends DrizzleRef<any, Table> | Table,
377
373
  Args extends InputFieldMap,
@@ -400,7 +396,7 @@ export type VariantFieldOptions<
400
396
  unknown extends ResolveShape
401
397
  ? Shape
402
398
  : BuildQueryResult<
403
- Types['DrizzleRelationsConfig'],
399
+ Types['DrizzleRelations'],
404
400
  ExtractTable<Types, Shape>,
405
401
  Record<string, unknown> &
406
402
  // biome-ignore lint/suspicious/noExplicitAny: this is fine
@@ -425,8 +421,8 @@ export type RefForRelation<Types extends SchemaTypes, Rel extends Relation> = Re
425
421
  : [ObjectRef<Types, TypesForRelation<Types, Rel>>];
426
422
 
427
423
  export type TypesForRelation<Types extends SchemaTypes, Rel extends Relation> = BuildQueryResult<
428
- Types['DrizzleRelationsConfig'],
429
- Types['DrizzleRelationsConfig'][Rel['targetTable']['_']['name']],
424
+ Types['DrizzleRelations'],
425
+ Types['DrizzleRelations'][Rel['targetTable']['_']['name']],
430
426
  true
431
427
  >;
432
428
 
@@ -441,16 +437,16 @@ export type QueryForField<
441
437
  ? Omit<
442
438
  DBQueryConfig<
443
439
  'one',
444
- Types['DrizzleRelationsConfig'],
445
- Types['DrizzleRelationsConfig'][Rel['targetTable']['_']['name']]
440
+ Types['DrizzleRelations'],
441
+ Types['DrizzleRelations'][Rel['targetTable']['_']['name']]
446
442
  >,
447
443
  'columns' | 'extra' | 'with'
448
444
  >
449
445
  : Omit<
450
446
  DBQueryConfig<
451
447
  'many',
452
- Types['DrizzleRelationsConfig'],
453
- Types['DrizzleRelationsConfig'][Rel['targetTable']['_']['name']]
448
+ Types['DrizzleRelations'],
449
+ Types['DrizzleRelations'][Rel['targetTable']['_']['name']]
454
450
  >,
455
451
  'columns' | 'extra' | 'with'
456
452
  >
@@ -461,14 +457,9 @@ export type QueryForField<
461
457
  export type QueryForDrizzleField<
462
458
  Types extends SchemaTypes,
463
459
  Param,
464
- Table extends keyof Types['DrizzleRelationsConfig'],
460
+ Table extends keyof Types['DrizzleRelations'],
465
461
  > = Omit<
466
- DBQueryConfig<
467
- 'many',
468
- Types['DrizzleRelationsConfig'],
469
- Types['DrizzleRelationsConfig'][Table],
470
- true
471
- >,
462
+ DBQueryConfig<'many', Types['DrizzleRelations'], Types['DrizzleRelations'][Table]>,
472
463
  Param extends [unknown] ? never : 'limit'
473
464
  >;
474
465
 
@@ -477,33 +468,33 @@ export type QueryForRelatedConnection<
477
468
  Table extends TableRelationalConfig,
478
469
  Args,
479
470
  > = Omit<
480
- DBQueryConfig<'many', Types['DrizzleRelationsConfig'], Table>,
471
+ DBQueryConfig<'many', Types['DrizzleRelations'], Table>,
481
472
  'limit' | 'offset' | 'columns' | 'extra' | 'with' | 'orderBy'
482
473
  > & {
483
- orderBy?: ConnectionOrderBy<Table> | ((columns: Table['columns']) => ConnectionOrderBy<Table>);
474
+ orderBy?: ConnectionOrderBy<Table> | ((table: Table) => ConnectionOrderBy<Table>);
484
475
  } extends infer QueryConfig
485
476
  ? QueryConfig | ((args: Args, context: Types['Context']) => QueryConfig)
486
477
  : never;
487
478
 
488
479
  export type QueryForDrizzleConnection<
489
480
  Types extends SchemaTypes,
490
- Table extends TableRelationalConfig,
481
+ TableConfig extends TableRelationalConfig,
491
482
  > = Omit<
492
- DBQueryConfig<'many', Types['DrizzleRelationsConfig'], Table>,
483
+ DBQueryConfig<'many', Types['DrizzleRelations'], TableConfig>,
493
484
  'limit' | 'offset' | 'orderBy'
494
485
  > & {
495
- orderBy?: ConnectionOrderBy<Table> | ((columns: Table['columns']) => ConnectionOrderBy<Table>);
486
+ orderBy?: ConnectionOrderBy<TableConfig> | ((table: Table) => ConnectionOrderBy<TableConfig>);
496
487
  };
497
488
 
498
489
  export type ListRelation<T extends TableRelationalConfig> = {
499
- [K in keyof T['relations']]: T['relations'][K] extends Many<string, string> ? K : never;
490
+ [K in keyof T['relations']]: T['relations'][K] extends Many<string> ? K : never;
500
491
  }[keyof T['relations']];
501
492
 
502
493
  export type DrizzleConnectionFieldOptions<
503
494
  Types extends SchemaTypes,
504
495
  ParentShape,
505
496
  Type extends // biome-ignore lint/suspicious/noExplicitAny: this is fine
506
- DrizzleRef<any, keyof Types['DrizzleRelationsConfig']> | keyof Types['DrizzleRelationsConfig'],
497
+ DrizzleRef<any, keyof Types['DrizzleRelations']> | keyof Types['DrizzleRelations'],
507
498
  TableConfig extends TableRelationalConfig,
508
499
  Param extends OutputType<Types>,
509
500
  Nullable extends boolean,
@@ -549,7 +540,9 @@ export type DrizzleConnectionFieldOptions<
549
540
  selection?: T,
550
541
  ) => Omit<T, 'orderBy'> & {
551
542
  orderBy: {
552
- [K in keyof TableConfig['columns']]?: 'asc' | 'desc' | undefined;
543
+ [K in TableConfig['table']['_'] extends { columns: infer Columns }
544
+ ? keyof Columns
545
+ : never]?: 'asc' | 'desc' | undefined;
553
546
  };
554
547
  },
555
548
  parent: ParentShape,
@@ -572,7 +565,7 @@ export type RelatedConnectionOptions<
572
565
  Nullable extends boolean,
573
566
  Args extends InputFieldMap,
574
567
  NodeTable extends
575
- TableRelationalConfig = Types['DrizzleRelationsConfig'][Table['relations'][Field]['targetTable']['_']['name']],
568
+ TableRelationalConfig = Types['DrizzleRelations'][Table['relations'][Field]['targetTable']['_']['name']],
576
569
  > = Omit<
577
570
  PothosSchemaTypes.ObjectFieldOptions<
578
571
  Types,
@@ -627,7 +620,10 @@ export type ConnectionOrderBy<T extends TableRelationalConfig> =
627
620
  | Column
628
621
  | Column[]
629
622
  | {
630
- [K in keyof T['columns']]?: 'asc' | 'desc' | undefined;
623
+ [K in T['table']['_'] extends { columns: infer Columns } ? keyof Columns : never]?:
624
+ | 'asc'
625
+ | 'desc'
626
+ | undefined;
631
627
  };
632
628
 
633
629
  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
  }