@pothos/plugin-drizzle 0.11.1 → 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.
- package/CHANGELOG.md +15 -0
- package/dts/connection-helpers.d.ts +7 -5
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/drizzle-field-builder.d.ts +3 -3
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/global-types.d.ts +30 -25
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/interface-ref.d.ts +3 -3
- package/dts/interface-ref.d.ts.map +1 -1
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/node-ref.d.ts +1 -1
- package/dts/node-ref.d.ts.map +1 -1
- package/dts/object-ref.d.ts +2 -2
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/types.d.ts +41 -29
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/config.d.ts.map +1 -1
- package/dts/utils/cursors.d.ts +3 -3
- package/dts/utils/cursors.d.ts.map +1 -1
- package/dts/utils/selections.d.ts +1 -1
- package/dts/utils/selections.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +7 -5
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/connection-helpers.js +2 -2
- package/esm/connection-helpers.js.map +1 -1
- package/esm/drizzle-field-builder.d.ts +2 -2
- package/esm/drizzle-field-builder.d.ts.map +1 -1
- package/esm/drizzle-field-builder.js +14 -18
- package/esm/drizzle-field-builder.js.map +1 -1
- package/esm/global-types.d.ts +41 -36
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +7 -1
- package/esm/index.js.map +1 -1
- package/esm/interface-ref.d.ts +3 -3
- package/esm/interface-ref.d.ts.map +1 -1
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +3 -3
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +1 -1
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/object-ref.d.ts +2 -2
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/schema-builder.js +16 -10
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +41 -29
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/config.d.ts.map +1 -1
- package/esm/utils/config.js +17 -21
- package/esm/utils/config.js.map +1 -1
- package/esm/utils/cursors.d.ts +3 -3
- package/esm/utils/cursors.d.ts.map +1 -1
- package/esm/utils/cursors.js +17 -14
- package/esm/utils/cursors.js.map +1 -1
- package/esm/utils/selections.d.ts +1 -1
- package/esm/utils/selections.d.ts.map +1 -1
- package/esm/utils/selections.js +11 -16
- package/esm/utils/selections.js.map +1 -1
- package/lib/connection-helpers.js +2 -2
- package/lib/connection-helpers.js.map +1 -1
- package/lib/drizzle-field-builder.js +13 -17
- package/lib/drizzle-field-builder.js.map +1 -1
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/model-loader.js +2 -2
- package/lib/model-loader.js.map +1 -1
- package/lib/schema-builder.js +16 -10
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/config.js +16 -20
- package/lib/utils/config.js.map +1 -1
- package/lib/utils/cursors.js +17 -14
- package/lib/utils/cursors.js.map +1 -1
- package/lib/utils/selections.js +11 -15
- package/lib/utils/selections.js.map +1 -1
- package/package.json +7 -7
- package/src/connection-helpers.ts +13 -12
- package/src/drizzle-field-builder.ts +16 -24
- package/src/global-types.ts +62 -88
- package/src/index.ts +9 -4
- package/src/interface-ref.ts +3 -3
- package/src/model-loader.ts +4 -3
- package/src/node-ref.ts +1 -1
- package/src/object-ref.ts +2 -2
- package/src/schema-builder.ts +12 -10
- package/src/types.ts +49 -48
- package/src/utils/config.ts +21 -32
- package/src/utils/cursors.ts +31 -18
- package/src/utils/selections.ts +10 -20
|
@@ -2,7 +2,6 @@ import type { InputFieldMap, InputShapeFromFields, SchemaTypes } from '@pothos/c
|
|
|
2
2
|
import type {
|
|
3
3
|
BuildQueryResult,
|
|
4
4
|
DBQueryConfig,
|
|
5
|
-
ExtractTablesWithRelations,
|
|
6
5
|
RelationsFilter,
|
|
7
6
|
TableRelationalConfig,
|
|
8
7
|
} from 'drizzle-orm';
|
|
@@ -21,9 +20,9 @@ import { createState, mergeSelection, selectionToQuery } from './utils/selection
|
|
|
21
20
|
|
|
22
21
|
export function drizzleConnectionHelpers<
|
|
23
22
|
Types extends SchemaTypes,
|
|
24
|
-
Type extends DrizzleRef<Types> | keyof Types['
|
|
25
|
-
Selection extends DBQueryConfig<'one', Types['
|
|
26
|
-
|
|
23
|
+
Type extends DrizzleRef<Types> | keyof Types['DrizzleRelations'],
|
|
24
|
+
Selection extends DBQueryConfig<'one', Types['DrizzleRelations'], TableConfig> | true,
|
|
25
|
+
TableConfig extends TableRelationalConfig = Types['DrizzleRelations'][Type extends DrizzleRef<
|
|
27
26
|
Types,
|
|
28
27
|
infer T
|
|
29
28
|
>
|
|
@@ -32,14 +31,14 @@ export function drizzleConnectionHelpers<
|
|
|
32
31
|
Shape = Type extends DrizzleRef<
|
|
33
32
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
34
33
|
any,
|
|
35
|
-
keyof Types['
|
|
34
|
+
keyof Types['DrizzleRelations'],
|
|
36
35
|
infer S
|
|
37
36
|
>
|
|
38
37
|
? S
|
|
39
|
-
: BuildQueryResult<Types['
|
|
38
|
+
: BuildQueryResult<Types['DrizzleRelations'], TableConfig, true>,
|
|
40
39
|
EdgeShape = true extends Selection
|
|
41
40
|
? Shape
|
|
42
|
-
: BuildQueryResult<Types['
|
|
41
|
+
: BuildQueryResult<Types['DrizzleRelations'], TableConfig, Selection>,
|
|
43
42
|
NodeShape = EdgeShape,
|
|
44
43
|
ExtraArgs extends InputFieldMap = {},
|
|
45
44
|
>(
|
|
@@ -59,7 +58,7 @@ export function drizzleConnectionHelpers<
|
|
|
59
58
|
args: InputShapeFromFields<ExtraArgs> & PothosSchemaTypes.DefaultConnectionArguments,
|
|
60
59
|
ctx: Types['Context'],
|
|
61
60
|
) => Selection;
|
|
62
|
-
query?: QueryForDrizzleConnection<Types,
|
|
61
|
+
query?: QueryForDrizzleConnection<Types, TableConfig> extends infer QueryConfig
|
|
63
62
|
?
|
|
64
63
|
| QueryConfig
|
|
65
64
|
| ((args: InputShapeFromFields<ExtraArgs>, context: Types['Context']) => QueryConfig)
|
|
@@ -116,7 +115,7 @@ export function drizzleConnectionHelpers<
|
|
|
116
115
|
) => {
|
|
117
116
|
const { limit, orderBy, where, ...fieldQuery } =
|
|
118
117
|
(typeof query === 'function' ? query(args, ctx) : query) ?? {};
|
|
119
|
-
const table = config.relations
|
|
118
|
+
const table = config.relations[tableName];
|
|
120
119
|
|
|
121
120
|
const { cursorColumns, columns, ...connectionQuery } = drizzleCursorConnectionQuery({
|
|
122
121
|
ctx,
|
|
@@ -169,7 +168,7 @@ export function drizzleConnectionHelpers<
|
|
|
169
168
|
const queryArgs = getQueryArgs(args, ctx);
|
|
170
169
|
|
|
171
170
|
const selectState = createState(
|
|
172
|
-
config.relations
|
|
171
|
+
config.relations[tableName],
|
|
173
172
|
builder.options.drizzle?.skipDeferredFragments ?? true,
|
|
174
173
|
);
|
|
175
174
|
|
|
@@ -187,9 +186,11 @@ export function drizzleConnectionHelpers<
|
|
|
187
186
|
...queryResult,
|
|
188
187
|
} as unknown as Omit<Selection, 'orderBy'> & {
|
|
189
188
|
orderBy: {
|
|
190
|
-
[K in
|
|
189
|
+
[K in TableConfig['table']['_'] extends { columns: infer Columns }
|
|
190
|
+
? keyof Columns
|
|
191
|
+
: never]?: 'asc' | 'desc' | undefined;
|
|
191
192
|
};
|
|
192
|
-
where: RelationsFilter<
|
|
193
|
+
where: RelationsFilter<TableConfig, Types['DrizzleRelations']>;
|
|
193
194
|
};
|
|
194
195
|
}
|
|
195
196
|
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
type TypeParam,
|
|
19
19
|
} from '@pothos/core';
|
|
20
20
|
import {
|
|
21
|
-
|
|
21
|
+
getTableName,
|
|
22
22
|
type InferSelectModel,
|
|
23
23
|
Many,
|
|
24
24
|
type Table,
|
|
@@ -197,13 +197,11 @@ export class DrizzleObjectFieldBuilder<
|
|
|
197
197
|
edgeOptions = {},
|
|
198
198
|
) {
|
|
199
199
|
const schemaConfig = getSchemaConfig(this.builder);
|
|
200
|
-
const relationField =
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
const tableName = schemaConfig.relations.tableNamesMap[tableUniqueName];
|
|
204
|
-
const relatedModel = schemaConfig.relations.tables[tableName] as Table;
|
|
200
|
+
const relationField = schemaConfig.relations?.[this.table].relations[name as string];
|
|
201
|
+
const tableName = getTableName(relationField.targetTable as Table);
|
|
202
|
+
const relatedTable = schemaConfig.relations[tableName];
|
|
205
203
|
|
|
206
|
-
if (!
|
|
204
|
+
if (!relatedTable) {
|
|
207
205
|
throw new PothosSchemaError(
|
|
208
206
|
`Could not find relation ${name as string} on table ${this.table}`,
|
|
209
207
|
);
|
|
@@ -216,20 +214,17 @@ export class DrizzleObjectFieldBuilder<
|
|
|
216
214
|
const { limit, orderBy, where, ...fieldQuery } =
|
|
217
215
|
(typeof query === 'function' ? query(args, ctx) : query) ?? {};
|
|
218
216
|
|
|
219
|
-
const tableUniqueName = getTableUniqueName(relatedModel as Table);
|
|
220
|
-
const tableName = schemaConfig.relations.tableNamesMap[tableUniqueName];
|
|
221
|
-
|
|
222
217
|
const { cursorColumns, columns, ...connectionQuery } = drizzleCursorConnectionQuery({
|
|
223
218
|
ctx,
|
|
224
219
|
maxSize,
|
|
225
220
|
defaultSize,
|
|
226
221
|
args,
|
|
227
222
|
orderBy:
|
|
228
|
-
(typeof orderBy === 'function' ? orderBy(
|
|
223
|
+
(typeof orderBy === 'function' ? orderBy(relatedTable.table) : orderBy) ??
|
|
229
224
|
getSchemaConfig(this.builder).getPrimaryKey(tableName),
|
|
230
225
|
where,
|
|
231
226
|
config: schemaConfig,
|
|
232
|
-
table:
|
|
227
|
+
table: relatedTable,
|
|
233
228
|
});
|
|
234
229
|
|
|
235
230
|
return {
|
|
@@ -315,7 +310,7 @@ export class DrizzleObjectFieldBuilder<
|
|
|
315
310
|
}
|
|
316
311
|
|
|
317
312
|
variant<
|
|
318
|
-
Variant extends DrizzleRef<Types, TableConfig['
|
|
313
|
+
Variant extends DrizzleRef<Types, TableConfig['name']> | TableConfig['name'],
|
|
319
314
|
Args extends InputFieldMap,
|
|
320
315
|
Nullable,
|
|
321
316
|
ResolveShape,
|
|
@@ -326,7 +321,7 @@ export class DrizzleObjectFieldBuilder<
|
|
|
326
321
|
[
|
|
327
322
|
options: VariantFieldOptions<
|
|
328
323
|
Types,
|
|
329
|
-
TableConfig['
|
|
324
|
+
TableConfig['name'] & keyof Types['DrizzleRelations'],
|
|
330
325
|
Variant,
|
|
331
326
|
Args,
|
|
332
327
|
Nullable,
|
|
@@ -393,19 +388,16 @@ export class DrizzleObjectFieldBuilder<
|
|
|
393
388
|
): FieldRef<Types, TypesForRelation<Types, TableConfig['relations'][Field]>, 'Object'> {
|
|
394
389
|
const [options = {} as never] = allArgs;
|
|
395
390
|
const schemaConfig = getSchemaConfig(this.builder);
|
|
396
|
-
const relationField =
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
const tableUniqueName = getTableUniqueName(relationField.targetTable as Table);
|
|
400
|
-
const tableName = schemaConfig.relations.tableNamesMap[tableUniqueName];
|
|
401
|
-
const relatedModel = schemaConfig.relations.tables[tableName];
|
|
391
|
+
const relationField = schemaConfig.relations?.[this.table].relations[name as string];
|
|
392
|
+
const tableName = getTableName(relationField.targetTable as Table);
|
|
393
|
+
const relatedTable = schemaConfig.relations[tableName];
|
|
402
394
|
|
|
403
|
-
if (!
|
|
395
|
+
if (!relatedTable) {
|
|
404
396
|
throw new PothosSchemaError(
|
|
405
397
|
`Could not find relation ${name as string} on table ${this.table}`,
|
|
406
398
|
);
|
|
407
399
|
}
|
|
408
|
-
const ref = options.type ?? getRefFromModel(
|
|
400
|
+
const ref = options.type ?? getRefFromModel(relatedTable.name, this.builder);
|
|
409
401
|
|
|
410
402
|
const { query = {}, extensions, ...rest } = options;
|
|
411
403
|
|
|
@@ -459,13 +451,13 @@ export class DrizzleObjectFieldBuilder<
|
|
|
459
451
|
>,
|
|
460
452
|
]
|
|
461
453
|
>
|
|
462
|
-
) {
|
|
454
|
+
): FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>, 'DrizzleObject'> {
|
|
463
455
|
const [name, options = {} as never] = args;
|
|
464
456
|
|
|
465
457
|
const typeConfig = this.builder.configStore.getTypeConfig(this.typename, this.graphqlKind);
|
|
466
458
|
const usingSelect = !!typeConfig.extensions?.pothosDrizzleSelect;
|
|
467
459
|
|
|
468
|
-
return this.exposeField(name as never, {
|
|
460
|
+
return this.exposeField<Type, Nullable, never>(name as never, {
|
|
469
461
|
...options,
|
|
470
462
|
extensions: {
|
|
471
463
|
...options.extensions,
|
package/src/global-types.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type {
|
|
|
2
2
|
FieldKind,
|
|
3
3
|
FieldMap,
|
|
4
4
|
FieldNullability,
|
|
5
|
-
FieldRef,
|
|
6
5
|
InputFieldMap,
|
|
7
6
|
InterfaceParam,
|
|
8
7
|
NormalizeArgs,
|
|
@@ -13,10 +12,8 @@ import type {
|
|
|
13
12
|
TypeParam,
|
|
14
13
|
} from '@pothos/core';
|
|
15
14
|
import type {
|
|
16
|
-
AnyRelations,
|
|
17
15
|
BuildQueryResult,
|
|
18
16
|
DBQueryConfig,
|
|
19
|
-
ExtractTablesWithRelations,
|
|
20
17
|
TableRelationalConfig,
|
|
21
18
|
TablesRelationalConfig,
|
|
22
19
|
} from 'drizzle-orm';
|
|
@@ -55,30 +52,24 @@ declare global {
|
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
export interface UserSchemaTypes {
|
|
58
|
-
DrizzleRelations:
|
|
59
|
-
DrizzleRelationsConfig: TablesRelationalConfig;
|
|
55
|
+
DrizzleRelations: TablesRelationalConfig;
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
export interface ExtendDefaultTypes<PartialTypes extends Partial<UserSchemaTypes>> {
|
|
63
59
|
DrizzleRelations: PartialTypes['DrizzleRelations'] & {};
|
|
64
|
-
DrizzleRelationsConfig: ExtractTablesWithRelations<PartialTypes['DrizzleRelations'] & {}>;
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
export interface SchemaBuilder<Types extends SchemaTypes> {
|
|
68
63
|
drizzleObject: <
|
|
69
64
|
const Interfaces extends InterfaceParam<Types>[],
|
|
70
|
-
Table extends keyof Types['DrizzleRelations']
|
|
65
|
+
Table extends keyof Types['DrizzleRelations'],
|
|
71
66
|
Selection extends
|
|
72
|
-
| DBQueryConfig<
|
|
73
|
-
'one',
|
|
74
|
-
Types['DrizzleRelationsConfig'],
|
|
75
|
-
Types['DrizzleRelationsConfig'][Table]
|
|
76
|
-
>
|
|
67
|
+
| DBQueryConfig<'one', Types['DrizzleRelations'], Types['DrizzleRelations'][Table]>
|
|
77
68
|
| true,
|
|
78
69
|
Shape = BuildQueryResult<
|
|
79
|
-
Types['
|
|
80
|
-
Types['
|
|
81
|
-
Selection
|
|
70
|
+
Types['DrizzleRelations'],
|
|
71
|
+
Types['DrizzleRelations'][Table],
|
|
72
|
+
true extends Selection ? true : Selection & { columns: {} }
|
|
82
73
|
>,
|
|
83
74
|
>(
|
|
84
75
|
table: Table,
|
|
@@ -87,18 +78,14 @@ declare global {
|
|
|
87
78
|
|
|
88
79
|
drizzleInterface: <
|
|
89
80
|
const Interfaces extends InterfaceParam<Types>[],
|
|
90
|
-
Table extends keyof Types['
|
|
81
|
+
Table extends keyof Types['DrizzleRelations'],
|
|
91
82
|
Selection extends
|
|
92
|
-
| DBQueryConfig<
|
|
93
|
-
'one',
|
|
94
|
-
Types['DrizzleRelationsConfig'],
|
|
95
|
-
Types['DrizzleRelationsConfig'][Table]
|
|
96
|
-
>
|
|
83
|
+
| DBQueryConfig<'one', Types['DrizzleRelations'], Types['DrizzleRelations'][Table]>
|
|
97
84
|
| true,
|
|
98
85
|
Shape = BuildQueryResult<
|
|
99
|
-
Types['
|
|
100
|
-
Types['
|
|
101
|
-
Selection
|
|
86
|
+
Types['DrizzleRelations'],
|
|
87
|
+
Types['DrizzleRelations'][Table],
|
|
88
|
+
true extends Selection ? true : Selection & { columns: {} }
|
|
102
89
|
>,
|
|
103
90
|
>(
|
|
104
91
|
table: Table,
|
|
@@ -108,19 +95,15 @@ declare global {
|
|
|
108
95
|
drizzleNode: 'relay' extends PluginName
|
|
109
96
|
? <
|
|
110
97
|
const Interfaces extends InterfaceParam<Types>[],
|
|
111
|
-
Table extends keyof Types['
|
|
98
|
+
Table extends keyof Types['DrizzleRelations'],
|
|
112
99
|
Selection extends
|
|
113
|
-
| DBQueryConfig<
|
|
114
|
-
'one',
|
|
115
|
-
Types['DrizzleRelationsConfig'],
|
|
116
|
-
Types['DrizzleRelationsConfig'][Table]
|
|
117
|
-
>
|
|
100
|
+
| DBQueryConfig<'one', Types['DrizzleRelations'], Types['DrizzleRelations'][Table]>
|
|
118
101
|
| true,
|
|
119
102
|
IDColumns,
|
|
120
103
|
Shape = BuildQueryResult<
|
|
121
|
-
Types['
|
|
122
|
-
Types['
|
|
123
|
-
Selection
|
|
104
|
+
Types['DrizzleRelations'],
|
|
105
|
+
Types['DrizzleRelations'][Table],
|
|
106
|
+
true extends Selection ? true : Selection & { columns: {} }
|
|
124
107
|
>,
|
|
125
108
|
>(
|
|
126
109
|
table: Table,
|
|
@@ -129,17 +112,17 @@ declare global {
|
|
|
129
112
|
: '@pothos/plugin-relay is required to use this method';
|
|
130
113
|
|
|
131
114
|
drizzleObjectField: <
|
|
132
|
-
Type extends DrizzleObjectRef<Types> | keyof Types['
|
|
115
|
+
Type extends DrizzleObjectRef<Types> | keyof Types['DrizzleRelations'],
|
|
133
116
|
TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
|
|
134
117
|
? Type[typeof drizzleTableKey]
|
|
135
|
-
: Types['
|
|
118
|
+
: Types['DrizzleRelations'][Type & keyof Types['DrizzleRelations']],
|
|
136
119
|
Shape extends {} = Type extends DrizzleObjectRef<
|
|
137
120
|
Types,
|
|
138
|
-
keyof Types['
|
|
121
|
+
keyof Types['DrizzleRelations'],
|
|
139
122
|
infer S
|
|
140
123
|
>
|
|
141
|
-
? S & { [drizzleTableName]?: TableConfig['
|
|
142
|
-
: BuildQueryResult<Types['
|
|
124
|
+
? S & { [drizzleTableName]?: TableConfig['name'] }
|
|
125
|
+
: BuildQueryResult<Types['DrizzleRelations'], TableConfig, true> & {
|
|
143
126
|
[drizzleTableName]?: Type;
|
|
144
127
|
},
|
|
145
128
|
>(
|
|
@@ -149,17 +132,17 @@ declare global {
|
|
|
149
132
|
) => void;
|
|
150
133
|
|
|
151
134
|
drizzleInterfaceField: <
|
|
152
|
-
Type extends DrizzleInterfaceRef<Types> | keyof Types['
|
|
135
|
+
Type extends DrizzleInterfaceRef<Types> | keyof Types['DrizzleRelations'],
|
|
153
136
|
TableConfig extends TableRelationalConfig = Type extends DrizzleInterfaceRef<Types>
|
|
154
137
|
? Type[typeof drizzleTableKey]
|
|
155
|
-
: Types['
|
|
138
|
+
: Types['DrizzleRelations'][Type & keyof Types['DrizzleRelations']],
|
|
156
139
|
Shape extends {} = Type extends DrizzleInterfaceRef<
|
|
157
140
|
Types,
|
|
158
|
-
keyof Types['
|
|
141
|
+
keyof Types['DrizzleRelations'],
|
|
159
142
|
infer S
|
|
160
143
|
>
|
|
161
|
-
? S & { [drizzleTableName]?: TableConfig['
|
|
162
|
-
: BuildQueryResult<Types['
|
|
144
|
+
? S & { [drizzleTableName]?: TableConfig['name'] }
|
|
145
|
+
: BuildQueryResult<Types['DrizzleRelations'], TableConfig, true> & {
|
|
163
146
|
[drizzleTableName]?: Type;
|
|
164
147
|
},
|
|
165
148
|
>(
|
|
@@ -169,17 +152,17 @@ declare global {
|
|
|
169
152
|
) => void;
|
|
170
153
|
|
|
171
154
|
drizzleObjectFields: <
|
|
172
|
-
Type extends DrizzleObjectRef<Types> | keyof Types['
|
|
155
|
+
Type extends DrizzleObjectRef<Types> | keyof Types['DrizzleRelations'],
|
|
173
156
|
TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
|
|
174
157
|
? Type[typeof drizzleTableKey]
|
|
175
|
-
: Types['
|
|
158
|
+
: Types['DrizzleRelations'][Type & keyof Types['DrizzleRelations']],
|
|
176
159
|
Shape extends {} = Type extends DrizzleObjectRef<
|
|
177
160
|
Types,
|
|
178
|
-
keyof Types['
|
|
161
|
+
keyof Types['DrizzleRelations'],
|
|
179
162
|
infer S
|
|
180
163
|
>
|
|
181
|
-
? S & { [drizzleTableName]?: TableConfig['
|
|
182
|
-
: BuildQueryResult<Types['
|
|
164
|
+
? S & { [drizzleTableName]?: TableConfig['name'] }
|
|
165
|
+
: BuildQueryResult<Types['DrizzleRelations'], TableConfig, true> & {
|
|
183
166
|
[drizzleTableName]?: Type;
|
|
184
167
|
},
|
|
185
168
|
>(
|
|
@@ -188,17 +171,17 @@ declare global {
|
|
|
188
171
|
) => void;
|
|
189
172
|
|
|
190
173
|
drizzleInterfaceFields: <
|
|
191
|
-
Type extends DrizzleInterfaceRef<Types> | keyof Types['
|
|
174
|
+
Type extends DrizzleInterfaceRef<Types> | keyof Types['DrizzleRelations'],
|
|
192
175
|
TableConfig extends TableRelationalConfig = Type extends DrizzleInterfaceRef<Types>
|
|
193
176
|
? Type[typeof drizzleTableKey]
|
|
194
|
-
: Types['
|
|
177
|
+
: Types['DrizzleRelations'][Type & keyof Types['DrizzleRelations']],
|
|
195
178
|
Shape extends {} = Type extends DrizzleInterfaceRef<
|
|
196
179
|
Types,
|
|
197
|
-
keyof Types['
|
|
180
|
+
keyof Types['DrizzleRelations'],
|
|
198
181
|
infer S
|
|
199
182
|
>
|
|
200
|
-
? S & { [drizzleTableName]?: TableConfig['
|
|
201
|
-
: BuildQueryResult<Types['
|
|
183
|
+
? S & { [drizzleTableName]?: TableConfig['name'] }
|
|
184
|
+
: BuildQueryResult<Types['DrizzleRelations'], TableConfig, true> & {
|
|
202
185
|
[drizzleTableName]?: Type;
|
|
203
186
|
},
|
|
204
187
|
>(
|
|
@@ -207,7 +190,7 @@ declare global {
|
|
|
207
190
|
) => void;
|
|
208
191
|
|
|
209
192
|
// drizzleGraphQLOrderBy: 'addGraphQL' extends PluginName
|
|
210
|
-
// ? <Table extends keyof Types['
|
|
193
|
+
// ? <Table extends keyof Types['DrizzleRelations']>(
|
|
211
194
|
// table: Table,
|
|
212
195
|
// type: GraphQLInputObjectType,
|
|
213
196
|
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
@@ -215,7 +198,7 @@ declare global {
|
|
|
215
198
|
// : '@pothos/plugin-add-graphql is required to use this method';
|
|
216
199
|
|
|
217
200
|
// drizzleGraphQLFilters: 'addGraphQL' extends PluginName
|
|
218
|
-
// ? <Table extends keyof Types['
|
|
201
|
+
// ? <Table extends keyof Types['DrizzleRelations']>(
|
|
219
202
|
// table: Table,
|
|
220
203
|
// type: GraphQLInputObjectType,
|
|
221
204
|
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
@@ -223,7 +206,7 @@ declare global {
|
|
|
223
206
|
// : '@pothos/plugin-add-graphql is required to use this method';
|
|
224
207
|
|
|
225
208
|
// drizzleGraphQLInsert: 'addGraphQL' extends PluginName
|
|
226
|
-
// ? <Table extends keyof Types['
|
|
209
|
+
// ? <Table extends keyof Types['DrizzleRelations']>(
|
|
227
210
|
// table: Table,
|
|
228
211
|
// type: GraphQLInputObjectType,
|
|
229
212
|
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
@@ -231,7 +214,7 @@ declare global {
|
|
|
231
214
|
// : '@pothos/plugin-add-graphql is required to use this method';
|
|
232
215
|
|
|
233
216
|
// drizzleGraphQLUpdate: 'addGraphQL' extends PluginName
|
|
234
|
-
// ? <Table extends keyof Types['
|
|
217
|
+
// ? <Table extends keyof Types['DrizzleRelations']>(
|
|
235
218
|
// table: Table,
|
|
236
219
|
// type: GraphQLInputObjectType,
|
|
237
220
|
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
@@ -271,8 +254,8 @@ declare global {
|
|
|
271
254
|
drizzleField: <
|
|
272
255
|
Args extends InputFieldMap,
|
|
273
256
|
Param extends
|
|
274
|
-
| keyof Types['
|
|
275
|
-
| [keyof Types['
|
|
257
|
+
| keyof Types['DrizzleRelations']
|
|
258
|
+
| [keyof Types['DrizzleRelations']]
|
|
276
259
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
277
260
|
| DrizzleRef<any>
|
|
278
261
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
@@ -281,16 +264,16 @@ declare global {
|
|
|
281
264
|
ResolveShape,
|
|
282
265
|
ResolveReturnShape,
|
|
283
266
|
Table extends
|
|
284
|
-
keyof Types['
|
|
267
|
+
keyof Types['DrizzleRelations'] = Param extends keyof Types['DrizzleRelations']
|
|
285
268
|
? Param
|
|
286
|
-
: Param extends [keyof Types['
|
|
269
|
+
: Param extends [keyof Types['DrizzleRelations']]
|
|
287
270
|
? Param[0]
|
|
288
271
|
: // biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
289
272
|
Param extends DrizzleRef<any, infer T>
|
|
290
|
-
? T & keyof Types['
|
|
273
|
+
? T & keyof Types['DrizzleRelations']
|
|
291
274
|
: // biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
292
275
|
Param extends [DrizzleRef<any, infer T>]
|
|
293
|
-
? T & keyof Types['
|
|
276
|
+
? T & keyof Types['DrizzleRelations']
|
|
294
277
|
: never,
|
|
295
278
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
296
279
|
Type extends TypeParam<Types> = Param extends DrizzleRef<any> | [DrizzleRef<any>]
|
|
@@ -300,19 +283,15 @@ declare global {
|
|
|
300
283
|
ObjectRef<
|
|
301
284
|
Types,
|
|
302
285
|
BuildQueryResult<
|
|
303
|
-
Types['
|
|
304
|
-
Types['
|
|
286
|
+
Types['DrizzleRelations'],
|
|
287
|
+
Types['DrizzleRelations'][Table],
|
|
305
288
|
true
|
|
306
289
|
>
|
|
307
290
|
>,
|
|
308
291
|
]
|
|
309
292
|
: ObjectRef<
|
|
310
293
|
Types,
|
|
311
|
-
BuildQueryResult<
|
|
312
|
-
Types['DrizzleRelationsConfig'],
|
|
313
|
-
Types['DrizzleRelationsConfig'][Table],
|
|
314
|
-
true
|
|
315
|
-
>
|
|
294
|
+
BuildQueryResult<Types['DrizzleRelations'], Types['DrizzleRelations'][Table], true>
|
|
316
295
|
>,
|
|
317
296
|
>(
|
|
318
297
|
options: DrizzleFieldOptions<
|
|
@@ -331,21 +310,20 @@ declare global {
|
|
|
331
310
|
drizzleConnection: 'relay' extends PluginName
|
|
332
311
|
? <
|
|
333
312
|
Type extends // biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
334
|
-
|
|
335
|
-
| keyof Types['DrizzleRelationsConfig'],
|
|
313
|
+
DrizzleRef<any, keyof Types['DrizzleRelations']> | keyof Types['DrizzleRelations'],
|
|
336
314
|
Nullable extends boolean,
|
|
337
315
|
ResolveReturnShape,
|
|
338
316
|
Args extends InputFieldMap = {},
|
|
339
317
|
Shape = Type extends DrizzleRef<
|
|
340
318
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
341
319
|
any,
|
|
342
|
-
keyof Types['
|
|
320
|
+
keyof Types['DrizzleRelations'],
|
|
343
321
|
infer S
|
|
344
322
|
>
|
|
345
323
|
? S
|
|
346
324
|
: BuildQueryResult<
|
|
347
|
-
Types['
|
|
348
|
-
Types['
|
|
325
|
+
Types['DrizzleRelations'],
|
|
326
|
+
Types['DrizzleRelations'][Type & keyof Types['DrizzleRelations']],
|
|
349
327
|
true
|
|
350
328
|
>,
|
|
351
329
|
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
|
|
@@ -356,9 +334,9 @@ declare global {
|
|
|
356
334
|
ParentShape,
|
|
357
335
|
Type,
|
|
358
336
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
359
|
-
Types['
|
|
337
|
+
Types['DrizzleRelations'][Type extends DrizzleRef<any, infer K>
|
|
360
338
|
? K
|
|
361
|
-
: Type & keyof Types['
|
|
339
|
+
: Type & keyof Types['DrizzleRelations']],
|
|
362
340
|
ObjectRef<Types, Shape>,
|
|
363
341
|
Nullable,
|
|
364
342
|
Args,
|
|
@@ -403,8 +381,8 @@ declare global {
|
|
|
403
381
|
drizzleFieldWithInput: 'withInput' extends PluginName
|
|
404
382
|
? <
|
|
405
383
|
Param extends
|
|
406
|
-
| keyof Types['
|
|
407
|
-
| [keyof Types['
|
|
384
|
+
| keyof Types['DrizzleRelations']
|
|
385
|
+
| [keyof Types['DrizzleRelations']]
|
|
408
386
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
409
387
|
| DrizzleRef<any>
|
|
410
388
|
// biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
@@ -417,24 +395,20 @@ declare global {
|
|
|
417
395
|
Args extends InputFieldMap = {},
|
|
418
396
|
InputName extends string = 'input',
|
|
419
397
|
Table extends
|
|
420
|
-
keyof Types['
|
|
398
|
+
keyof Types['DrizzleRelations'] = Param extends keyof Types['DrizzleRelations']
|
|
421
399
|
? Param
|
|
422
|
-
: Param extends [keyof Types['
|
|
400
|
+
: Param extends [keyof Types['DrizzleRelations']]
|
|
423
401
|
? Param[0]
|
|
424
402
|
: // biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
425
403
|
Param extends DrizzleRef<any, infer T>
|
|
426
|
-
? T & keyof Types['
|
|
404
|
+
? T & keyof Types['DrizzleRelations']
|
|
427
405
|
: // biome-ignore lint/suspicious/noExplicitAny: this is fine
|
|
428
406
|
Param extends [DrizzleRef<any, infer T>]
|
|
429
|
-
? T & keyof Types['
|
|
407
|
+
? T & keyof Types['DrizzleRelations']
|
|
430
408
|
: never,
|
|
431
409
|
Type extends TypeParam<Types> = ObjectRef<
|
|
432
410
|
Types,
|
|
433
|
-
BuildQueryResult<
|
|
434
|
-
Types['DrizzleRelationsConfig'],
|
|
435
|
-
Types['DrizzleRelationsConfig'][Table],
|
|
436
|
-
true
|
|
437
|
-
>
|
|
411
|
+
BuildQueryResult<Types['DrizzleRelations'], Types['DrizzleRelations'][Table], true>
|
|
438
412
|
>,
|
|
439
413
|
>(
|
|
440
414
|
options: DrizzleFieldWithInputOptions<
|
package/src/index.ts
CHANGED
|
@@ -121,13 +121,18 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
|
|
|
121
121
|
args: {},
|
|
122
122
|
ctx: Types['Context'],
|
|
123
123
|
nestedQuery: (query: unknown, path?: string[]) => never,
|
|
124
|
-
) =>
|
|
125
|
-
|
|
124
|
+
) => ({
|
|
125
|
+
columns: {},
|
|
126
|
+
...(select as (args: unknown, ctx: unknown, nestedQuery: unknown) => {})(
|
|
126
127
|
args,
|
|
127
128
|
ctx,
|
|
128
129
|
nestedQuery,
|
|
129
|
-
)
|
|
130
|
-
|
|
130
|
+
),
|
|
131
|
+
})
|
|
132
|
+
: {
|
|
133
|
+
columns: {},
|
|
134
|
+
...select,
|
|
135
|
+
},
|
|
131
136
|
},
|
|
132
137
|
};
|
|
133
138
|
}
|
package/src/interface-ref.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type DrizzleObjectRef, drizzleTableKey } from './object-ref';
|
|
|
4
4
|
|
|
5
5
|
export type DrizzleRef<
|
|
6
6
|
Types extends SchemaTypes,
|
|
7
|
-
Table extends keyof Types['
|
|
7
|
+
Table extends keyof Types['DrizzleRelations'] = keyof Types['DrizzleRelations'],
|
|
8
8
|
T = {},
|
|
9
9
|
> =
|
|
10
10
|
| DrizzleInterfaceRef<Types, Table, T>
|
|
@@ -13,10 +13,10 @@ export type DrizzleRef<
|
|
|
13
13
|
|
|
14
14
|
export class DrizzleInterfaceRef<
|
|
15
15
|
Types extends SchemaTypes,
|
|
16
|
-
Table extends keyof Types['
|
|
16
|
+
Table extends keyof Types['DrizzleRelations'] = keyof Types['DrizzleRelations'],
|
|
17
17
|
T = {},
|
|
18
18
|
> extends InterfaceRef<Types, T> {
|
|
19
|
-
[drizzleTableKey]!: Types['
|
|
19
|
+
[drizzleTableKey]!: Types['DrizzleRelations'][Table];
|
|
20
20
|
|
|
21
21
|
tableName: string;
|
|
22
22
|
|
package/src/model-loader.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { createContextCache, type SchemaTypes } from '@pothos/core';
|
|
|
2
2
|
import {
|
|
3
3
|
type AnyTable,
|
|
4
4
|
type Column,
|
|
5
|
+
getTableColumns,
|
|
5
6
|
inArray,
|
|
6
7
|
type SQL,
|
|
7
8
|
sql,
|
|
@@ -54,16 +55,16 @@ export class ModelLoader {
|
|
|
54
55
|
this.builder = builder;
|
|
55
56
|
this.modelName = modelName;
|
|
56
57
|
this.config = getSchemaConfig(builder);
|
|
57
|
-
this.table = this.config.relations
|
|
58
|
+
this.table = this.config.relations[modelName];
|
|
58
59
|
this.primaryKey = this.config.getPrimaryKey(modelName);
|
|
59
60
|
this.columns = columns ?? this.primaryKey;
|
|
60
61
|
this.selectSQL = (table) => {
|
|
61
62
|
const columns = this.columns.map((column) =>
|
|
62
|
-
Object.values(table).find(
|
|
63
|
+
Object.values(getTableColumns(table)).find(
|
|
63
64
|
(tblColumn) => 'columnType' in tblColumn && tblColumn.name === column.name,
|
|
64
65
|
),
|
|
65
66
|
);
|
|
66
|
-
return columns.length > 1 ? sql`(${sql.join(columns, sql`, `)})` : columns[0]
|
|
67
|
+
return columns.length > 1 ? sql`(${sql.join(columns, sql`, `)})` : columns[0]!.getSQL();
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
|
package/src/node-ref.ts
CHANGED
|
@@ -5,7 +5,7 @@ export const relayIDShapeKey = Symbol.for('Pothos.relayIDShapeKey');
|
|
|
5
5
|
|
|
6
6
|
export class DrizzleNodeRef<
|
|
7
7
|
Types extends SchemaTypes,
|
|
8
|
-
Table extends keyof Types['
|
|
8
|
+
Table extends keyof Types['DrizzleRelations'] = keyof Types['DrizzleRelations'],
|
|
9
9
|
T = {},
|
|
10
10
|
IDShape = string,
|
|
11
11
|
> extends DrizzleObjectRef<Types, Table, T> {
|
package/src/object-ref.ts
CHANGED
|
@@ -11,10 +11,10 @@ export const drizzleTableKey = Symbol.for('Pothos.drizzleTableKey');
|
|
|
11
11
|
|
|
12
12
|
export class DrizzleObjectRef<
|
|
13
13
|
Types extends SchemaTypes,
|
|
14
|
-
Table extends keyof Types['
|
|
14
|
+
Table extends keyof Types['DrizzleRelations'] = keyof Types['DrizzleRelations'],
|
|
15
15
|
T = {},
|
|
16
16
|
> extends ObjectRef<Types, T> {
|
|
17
|
-
[drizzleTableKey]!: Types['
|
|
17
|
+
[drizzleTableKey]!: Types['DrizzleRelations'][Table];
|
|
18
18
|
|
|
19
19
|
[abstractReturnShapeKey]!: WithBrand<T>;
|
|
20
20
|
|