@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.
- package/CHANGELOG.md +6 -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 +2 -2
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/global-types.d.ts +23 -24
- package/dts/global-types.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 +33 -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 +34 -35
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.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 +8 -8
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +33 -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 +6 -13
- 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/model-loader.js +2 -2
- package/lib/model-loader.js.map +1 -1
- package/lib/schema-builder.js +8 -8
- 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 +6 -12
- 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 +14 -22
- package/src/global-types.ts +59 -85
- 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 +8 -8
- package/src/types.ts +41 -45
- package/src/utils/config.ts +21 -32
- package/src/utils/cursors.ts +31 -18
- package/src/utils/selections.ts +7 -17
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,29 +52,23 @@ 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['
|
|
70
|
+
Types['DrizzleRelations'],
|
|
71
|
+
Types['DrizzleRelations'][Table],
|
|
81
72
|
true extends Selection ? true : Selection & { columns: {} }
|
|
82
73
|
>,
|
|
83
74
|
>(
|
|
@@ -87,17 +78,13 @@ 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['
|
|
86
|
+
Types['DrizzleRelations'],
|
|
87
|
+
Types['DrizzleRelations'][Table],
|
|
101
88
|
true extends Selection ? true : Selection & { columns: {} }
|
|
102
89
|
>,
|
|
103
90
|
>(
|
|
@@ -108,18 +95,14 @@ 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['
|
|
104
|
+
Types['DrizzleRelations'],
|
|
105
|
+
Types['DrizzleRelations'][Table],
|
|
123
106
|
true extends Selection ? true : Selection & { columns: {} }
|
|
124
107
|
>,
|
|
125
108
|
>(
|
|
@@ -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/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
|
|
package/src/schema-builder.ts
CHANGED
|
@@ -36,7 +36,7 @@ schemaBuilderProto.drizzleObject = function drizzleObject(table, { select, field
|
|
|
36
36
|
extensions: {
|
|
37
37
|
...options.extensions,
|
|
38
38
|
pothosDrizzleModel: table,
|
|
39
|
-
pothosDrizzleTable: getSchemaConfig(this).relations
|
|
39
|
+
pothosDrizzleTable: getSchemaConfig(this).relations[table],
|
|
40
40
|
pothosDrizzleSelect:
|
|
41
41
|
typeof select === 'object' ? { columns: {}, ...select } : (select ?? true),
|
|
42
42
|
pothosDrizzleLoader: ModelLoader.forModel(table, this),
|
|
@@ -65,7 +65,7 @@ schemaBuilderProto.drizzleInterface = function drizzleInterface(
|
|
|
65
65
|
extensions: {
|
|
66
66
|
...options.extensions,
|
|
67
67
|
pothosDrizzleModel: table,
|
|
68
|
-
pothosDrizzleTable: getSchemaConfig(this).relations
|
|
68
|
+
pothosDrizzleTable: getSchemaConfig(this).relations[table],
|
|
69
69
|
pothosDrizzleSelect:
|
|
70
70
|
typeof select === 'object' ? { columns: {}, ...select } : (select ?? true),
|
|
71
71
|
pothosDrizzleLoader: ModelLoader.forModel(table, this),
|
|
@@ -99,8 +99,8 @@ schemaBuilderProto.drizzleNode = function drizzleNode(
|
|
|
99
99
|
>,
|
|
100
100
|
) {
|
|
101
101
|
const schemaConfig = getSchemaConfig(this);
|
|
102
|
-
const tableConfig = schemaConfig.relations
|
|
103
|
-
const idColumn = typeof column === 'function' ? column(tableConfig.
|
|
102
|
+
const tableConfig = schemaConfig.relations[table];
|
|
103
|
+
const idColumn = typeof column === 'function' ? column(tableConfig.table) : column;
|
|
104
104
|
const idColumns = Array.isArray(idColumn) ? idColumn : [idColumn];
|
|
105
105
|
const interfaceRef = this.nodeInterfaceRef?.();
|
|
106
106
|
const resolve = getIDSerializer(idColumns, schemaConfig);
|
|
@@ -232,7 +232,7 @@ schemaBuilderProto.drizzleInterfaceFields = function drizzleInterfaceFields(type
|
|
|
232
232
|
// drizzleGraphQL: {
|
|
233
233
|
// inputType: 'orderBy',
|
|
234
234
|
// table,
|
|
235
|
-
// tableConfig: getSchemaConfig(this).relations
|
|
235
|
+
// tableConfig: getSchemaConfig(this).relations[table],
|
|
236
236
|
// } satisfies DrizzleGraphQLInputExtensions,
|
|
237
237
|
// },
|
|
238
238
|
// });
|
|
@@ -258,7 +258,7 @@ schemaBuilderProto.drizzleInterfaceFields = function drizzleInterfaceFields(type
|
|
|
258
258
|
// drizzleGraphQL: {
|
|
259
259
|
// inputType: 'filters',
|
|
260
260
|
// table,
|
|
261
|
-
// tableConfig: getSchemaConfig(this).relations
|
|
261
|
+
// tableConfig: getSchemaConfig(this).relations[table],
|
|
262
262
|
// } satisfies DrizzleGraphQLInputExtensions,
|
|
263
263
|
// },
|
|
264
264
|
// });
|
|
@@ -284,7 +284,7 @@ schemaBuilderProto.drizzleInterfaceFields = function drizzleInterfaceFields(type
|
|
|
284
284
|
// drizzleGraphQL: {
|
|
285
285
|
// inputType: 'insert',
|
|
286
286
|
// table,
|
|
287
|
-
// tableConfig: getSchemaConfig(this).relations
|
|
287
|
+
// tableConfig: getSchemaConfig(this).relations[table],
|
|
288
288
|
// } satisfies DrizzleGraphQLInputExtensions,
|
|
289
289
|
// },
|
|
290
290
|
// });
|
|
@@ -310,7 +310,7 @@ schemaBuilderProto.drizzleInterfaceFields = function drizzleInterfaceFields(type
|
|
|
310
310
|
// drizzleGraphQL: {
|
|
311
311
|
// inputType: 'update',
|
|
312
312
|
// table,
|
|
313
|
-
// tableConfig: getSchemaConfig(this).relations
|
|
313
|
+
// tableConfig: getSchemaConfig(this).relations[table],
|
|
314
314
|
// } satisfies DrizzleGraphQLInputExtensions,
|
|
315
315
|
// },
|
|
316
316
|
// });
|