@pothos/plugin-prisma 3.65.3 → 4.0.0-next.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.
- package/CHANGELOG.md +21 -4
- package/README.md +3 -5
- package/dts/connection-helpers.d.ts +10 -10
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/global-types.d.ts +25 -25
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts +2 -2
- 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 +6 -6
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/node-ref.d.ts +2 -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/prisma-field-builder.d.ts +69 -53
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +81 -55
- package/dts/types.d.ts.map +1 -1
- package/dts/util/cursors.d.ts.map +1 -1
- package/dts/util/datamodel.d.ts +5 -5
- package/dts/util/datamodel.d.ts.map +1 -1
- package/dts/util/map-query.d.ts.map +1 -1
- package/dts/util/relation-map.d.ts +1 -1
- package/dts/util/relation-map.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +7 -7
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/connection-helpers.js.map +1 -1
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +69 -29
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts +36 -36
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +13 -2
- 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/interface-ref.js.map +1 -1
- package/esm/model-loader.d.ts +6 -6
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +2 -1
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/node-ref.js.map +1 -1
- package/esm/object-ref.d.ts +2 -2
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/object-ref.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +74 -58
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +14 -5
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/schema-builder.js +3 -3
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +82 -58
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/util/cursors.d.ts.map +1 -1
- package/esm/util/cursors.js.map +1 -1
- package/esm/util/datamodel.d.ts +5 -5
- package/esm/util/datamodel.d.ts.map +1 -1
- package/esm/util/datamodel.js.map +1 -1
- package/esm/util/deep-equal.js.map +1 -1
- package/esm/util/description.js.map +1 -1
- package/esm/util/get-client.js.map +1 -1
- package/esm/util/loader-map.js.map +1 -1
- package/esm/util/map-query.d.ts.map +1 -1
- package/esm/util/map-query.js +3 -3
- package/esm/util/map-query.js.map +1 -1
- package/esm/util/relation-map.d.ts +1 -1
- package/esm/util/relation-map.d.ts.map +1 -1
- package/esm/util/relation-map.js.map +1 -1
- package/esm/util/selections.js.map +1 -1
- package/esm/util/usage.js.map +1 -1
- package/lib/connection-helpers.js.map +1 -1
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +68 -26
- package/lib/generator.js.map +1 -1
- package/lib/global-types.js.map +1 -1
- package/lib/index.js +16 -5
- package/lib/index.js.map +1 -1
- package/lib/interface-ref.js.map +1 -1
- package/lib/model-loader.js.map +1 -1
- package/lib/node-ref.js.map +1 -1
- package/lib/object-ref.js.map +1 -1
- package/lib/prisma-field-builder.js +14 -5
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +3 -3
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/util/cursors.js.map +1 -1
- package/lib/util/datamodel.js.map +1 -1
- package/lib/util/deep-equal.js.map +1 -1
- package/lib/util/description.js.map +1 -1
- package/lib/util/get-client.js.map +1 -1
- package/lib/util/loader-map.js.map +1 -1
- package/lib/util/map-query.js +1 -1
- package/lib/util/map-query.js.map +1 -1
- package/lib/util/relation-map.js.map +1 -1
- package/lib/util/selections.js.map +1 -1
- package/lib/util/usage.js.map +1 -1
- package/package.json +18 -16
- package/src/connection-helpers.ts +7 -6
- package/src/field-builder.ts +12 -11
- package/src/generator.ts +125 -25
- package/src/global-types.ts +61 -55
- package/src/index.ts +11 -5
- package/src/interface-ref.ts +9 -5
- package/src/model-loader.ts +6 -6
- package/src/node-ref.ts +6 -1
- package/src/object-ref.ts +12 -2
- package/src/prisma-field-builder.ts +101 -74
- package/src/schema-builder.ts +10 -7
- package/src/types.ts +186 -184
- package/src/util/datamodel.ts +5 -5
- package/src/util/map-query.ts +2 -3
package/src/types.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { FieldNode, GraphQLResolveInfo } from 'graphql';
|
|
2
2
|
import {
|
|
3
|
+
ArgumentRef,
|
|
3
4
|
FieldKind,
|
|
4
5
|
FieldMap,
|
|
5
6
|
FieldNullability,
|
|
6
7
|
FieldOptionsFromKind,
|
|
8
|
+
InferredResolveOptionsByKind,
|
|
9
|
+
InferredResolveOptionsKeys,
|
|
7
10
|
InputFieldMap,
|
|
8
|
-
InputFieldRef,
|
|
9
11
|
InputFieldsFromShape,
|
|
10
12
|
InputShapeFromFields,
|
|
11
13
|
InterfaceParam,
|
|
@@ -76,9 +78,7 @@ export type PrismaObjectFieldOptions<
|
|
|
76
78
|
Args extends InputFieldMap,
|
|
77
79
|
Select,
|
|
78
80
|
ResolveReturnShape,
|
|
79
|
-
|
|
80
|
-
Types,
|
|
81
|
-
unknown extends Select
|
|
81
|
+
Shape = unknown extends Select
|
|
82
82
|
? ParentShape
|
|
83
83
|
: ParentShape &
|
|
84
84
|
ShapeFromSelection<
|
|
@@ -86,41 +86,45 @@ export type PrismaObjectFieldOptions<
|
|
|
86
86
|
ExtractModel<Types, ParentShape>,
|
|
87
87
|
{ select: Select extends (...args: any[]) => infer S ? S : Select }
|
|
88
88
|
>,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
89
|
+
> = PothosSchemaTypes.ObjectFieldOptions<Types, Shape, Type, Nullable, Args, ResolveReturnShape> &
|
|
90
|
+
InferredResolveOptionsByKind<
|
|
91
|
+
Types,
|
|
92
|
+
Types['InferredResolveOptionsKind'],
|
|
93
|
+
Shape,
|
|
94
|
+
Type,
|
|
95
|
+
Nullable,
|
|
96
|
+
Args,
|
|
97
|
+
ResolveReturnShape
|
|
98
|
+
> & {
|
|
99
|
+
select?: Select &
|
|
100
|
+
(
|
|
101
|
+
| ExtractModel<Types, ParentShape>['Select']
|
|
102
|
+
| ((
|
|
103
|
+
args: InputShapeFromFields<Args>,
|
|
104
|
+
ctx: Types['Context'],
|
|
105
|
+
nestedSelection: <Selection extends boolean | {}>(
|
|
106
|
+
selection?: Selection,
|
|
107
|
+
path?: string[],
|
|
108
|
+
type?: string,
|
|
109
|
+
) => Selection,
|
|
110
|
+
) => ExtractModel<Types, ParentShape>['Select'])
|
|
111
|
+
);
|
|
112
|
+
};
|
|
108
113
|
|
|
109
114
|
type PrismaObjectFieldsShape<
|
|
110
115
|
Types extends SchemaTypes,
|
|
111
116
|
Model extends PrismaModelTypes,
|
|
112
|
-
NeedsResolve extends boolean,
|
|
113
117
|
Shape extends object,
|
|
114
118
|
Select,
|
|
115
119
|
> = Model['Select'] extends Select
|
|
116
|
-
? (t: PrismaObjectFieldBuilder<Types, Model,
|
|
120
|
+
? (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldMap
|
|
117
121
|
: (t: PrismaSelectionFieldBuilder<Types, Model, Shape>) => FieldMap;
|
|
118
122
|
|
|
119
123
|
type PrismaSelectionFieldBuilder<
|
|
120
124
|
Types extends SchemaTypes,
|
|
121
125
|
Model extends PrismaModelTypes,
|
|
122
126
|
Shape extends object,
|
|
123
|
-
> = PrismaObjectFieldBuilder<Types, Model,
|
|
127
|
+
> = PrismaObjectFieldBuilder<Types, Model, Shape>;
|
|
124
128
|
|
|
125
129
|
interface BaseSelection {
|
|
126
130
|
include?: unknown;
|
|
@@ -180,7 +184,6 @@ type RelationShapeFromInclude<
|
|
|
180
184
|
export type PrismaObjectRefOptions<
|
|
181
185
|
Types extends SchemaTypes,
|
|
182
186
|
Model extends PrismaModelTypes,
|
|
183
|
-
FindUnique,
|
|
184
187
|
Include,
|
|
185
188
|
Select,
|
|
186
189
|
Shape extends object,
|
|
@@ -189,8 +192,7 @@ export type PrismaObjectRefOptions<
|
|
|
189
192
|
| {
|
|
190
193
|
include?: Include & Model['Include'];
|
|
191
194
|
select?: never;
|
|
192
|
-
findUnique?:
|
|
193
|
-
(((parent: Shape, context: Types['Context']) => Model['WhereUnique']) | null);
|
|
195
|
+
findUnique?: ((parent: Shape, context: Types['Context']) => Model['WhereUnique']) | null;
|
|
194
196
|
}
|
|
195
197
|
| {
|
|
196
198
|
select: Model['Select'] & Select;
|
|
@@ -203,7 +205,6 @@ export type PrismaObjectImplementationOptions<
|
|
|
203
205
|
Types extends SchemaTypes,
|
|
204
206
|
Model extends PrismaModelTypes,
|
|
205
207
|
Interfaces extends InterfaceParam<Types>[],
|
|
206
|
-
FindUnique,
|
|
207
208
|
Select,
|
|
208
209
|
Shape extends object,
|
|
209
210
|
> = Omit<
|
|
@@ -215,8 +216,7 @@ export type PrismaObjectImplementationOptions<
|
|
|
215
216
|
fields?: PrismaObjectFieldsShape<
|
|
216
217
|
Types,
|
|
217
218
|
Model,
|
|
218
|
-
|
|
219
|
-
Shape & (FindUnique extends null ? {} : { [prismaModelName]?: Model['Name'] }),
|
|
219
|
+
Shape & { [prismaModelName]?: Model['Name'] },
|
|
220
220
|
Select
|
|
221
221
|
>;
|
|
222
222
|
};
|
|
@@ -225,17 +225,15 @@ export type PrismaObjectTypeOptions<
|
|
|
225
225
|
Types extends SchemaTypes,
|
|
226
226
|
Model extends PrismaModelTypes,
|
|
227
227
|
Interfaces extends InterfaceParam<Types>[],
|
|
228
|
-
FindUnique,
|
|
229
228
|
Include,
|
|
230
229
|
Select,
|
|
231
230
|
Shape extends object,
|
|
232
|
-
> = PrismaObjectImplementationOptions<Types, Model, Interfaces,
|
|
233
|
-
PrismaObjectRefOptions<Types, Model,
|
|
231
|
+
> = PrismaObjectImplementationOptions<Types, Model, Interfaces, Select, Shape> &
|
|
232
|
+
PrismaObjectRefOptions<Types, Model, Include, Select, Shape>;
|
|
234
233
|
|
|
235
234
|
export type PrismaInterfaceRefOptions<
|
|
236
235
|
Types extends SchemaTypes,
|
|
237
236
|
Model extends PrismaModelTypes,
|
|
238
|
-
FindUnique,
|
|
239
237
|
Include,
|
|
240
238
|
Select,
|
|
241
239
|
Shape extends object,
|
|
@@ -244,8 +242,7 @@ export type PrismaInterfaceRefOptions<
|
|
|
244
242
|
| {
|
|
245
243
|
include?: Include & Model['Include'];
|
|
246
244
|
select?: never;
|
|
247
|
-
findUnique?:
|
|
248
|
-
(((parent: Shape, context: Types['Context']) => Model['WhereUnique']) | null);
|
|
245
|
+
findUnique?: ((parent: Shape, context: Types['Context']) => Model['WhereUnique']) | null;
|
|
249
246
|
}
|
|
250
247
|
| {
|
|
251
248
|
select: Model['Select'] & Select;
|
|
@@ -258,7 +255,6 @@ export type PrismaInterfaceImplementationOptions<
|
|
|
258
255
|
Types extends SchemaTypes,
|
|
259
256
|
Model extends PrismaModelTypes,
|
|
260
257
|
Interfaces extends InterfaceParam<Types>[],
|
|
261
|
-
FindUnique,
|
|
262
258
|
Select,
|
|
263
259
|
Shape extends object,
|
|
264
260
|
> = Omit<
|
|
@@ -269,8 +265,7 @@ export type PrismaInterfaceImplementationOptions<
|
|
|
269
265
|
fields?: PrismaObjectFieldsShape<
|
|
270
266
|
Types,
|
|
271
267
|
Model,
|
|
272
|
-
|
|
273
|
-
Shape & (FindUnique extends null ? {} : { [prismaModelName]?: Model['Name'] }),
|
|
268
|
+
Shape & { [prismaModelName]?: Model['Name'] },
|
|
274
269
|
Select
|
|
275
270
|
>;
|
|
276
271
|
};
|
|
@@ -279,12 +274,11 @@ export type PrismaInterfaceTypeOptions<
|
|
|
279
274
|
Types extends SchemaTypes,
|
|
280
275
|
Model extends PrismaModelTypes,
|
|
281
276
|
Interfaces extends InterfaceParam<Types>[],
|
|
282
|
-
FindUnique,
|
|
283
277
|
Include,
|
|
284
278
|
Select,
|
|
285
279
|
Shape extends object,
|
|
286
|
-
> = PrismaInterfaceImplementationOptions<Types, Model, Interfaces,
|
|
287
|
-
PrismaInterfaceRefOptions<Types, Model,
|
|
280
|
+
> = PrismaInterfaceImplementationOptions<Types, Model, Interfaces, Select, Shape> &
|
|
281
|
+
PrismaInterfaceRefOptions<Types, Model, Include, Select, Shape>;
|
|
288
282
|
|
|
289
283
|
type NameOrVariant =
|
|
290
284
|
| {
|
|
@@ -328,7 +322,7 @@ export type PrismaNodeOptions<
|
|
|
328
322
|
OutputShape<Types, 'ID'>,
|
|
329
323
|
MaybePromise<OutputShape<Types, 'ID'>>
|
|
330
324
|
>,
|
|
331
|
-
'args' | 'nullable' | '
|
|
325
|
+
'args' | 'nullable' | 'type' | InferredResolveOptionsKeys
|
|
332
326
|
> &
|
|
333
327
|
(
|
|
334
328
|
| {
|
|
@@ -348,7 +342,6 @@ export type PrismaNodeOptions<
|
|
|
348
342
|
fields?: PrismaObjectFieldsShape<
|
|
349
343
|
Types,
|
|
350
344
|
Model,
|
|
351
|
-
false,
|
|
352
345
|
Shape & { [prismaModelName]?: Model['Name'] },
|
|
353
346
|
Select
|
|
354
347
|
>;
|
|
@@ -405,11 +398,12 @@ type CursorFromRelation<
|
|
|
405
398
|
: never;
|
|
406
399
|
|
|
407
400
|
type RefForRelation<
|
|
401
|
+
Types extends SchemaTypes,
|
|
408
402
|
Model extends PrismaModelTypes,
|
|
409
403
|
Field extends keyof Model['Relations'],
|
|
410
404
|
> = Model['Relations'][Field] extends unknown[]
|
|
411
|
-
? [ObjectRef<Model['Relations'][Field]>]
|
|
412
|
-
: ObjectRef<Model['Relations'][Field]>;
|
|
405
|
+
? [ObjectRef<Types, Model['Relations'][Field]>]
|
|
406
|
+
: ObjectRef<Types, Model['Relations'][Field]>;
|
|
413
407
|
|
|
414
408
|
export type RelatedFieldOptions<
|
|
415
409
|
Types extends SchemaTypes,
|
|
@@ -418,51 +412,49 @@ export type RelatedFieldOptions<
|
|
|
418
412
|
Nullable extends boolean,
|
|
419
413
|
Args extends InputFieldMap,
|
|
420
414
|
ResolveReturnShape,
|
|
421
|
-
NeedsResolve extends boolean,
|
|
422
415
|
Shape,
|
|
423
416
|
> = Omit<
|
|
424
417
|
PothosSchemaTypes.ObjectFieldOptions<
|
|
425
418
|
Types,
|
|
426
419
|
Shape,
|
|
427
|
-
RefForRelation<Model, Field>,
|
|
420
|
+
RefForRelation<Types, Model, Field>,
|
|
428
421
|
Nullable,
|
|
429
422
|
Args,
|
|
430
423
|
ResolveReturnShape
|
|
431
424
|
>,
|
|
432
|
-
'description' | '
|
|
433
|
-
> &
|
|
434
|
-
(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
};
|
|
425
|
+
'description' | 'type' | InferredResolveOptionsKeys
|
|
426
|
+
> & {
|
|
427
|
+
resolve?: (
|
|
428
|
+
query: QueryFromRelation<Model, Field & keyof Model['Include']>,
|
|
429
|
+
parent: Shape,
|
|
430
|
+
args: InputShapeFromFields<Args>,
|
|
431
|
+
context: Types['Context'],
|
|
432
|
+
info: GraphQLResolveInfo,
|
|
433
|
+
) => MaybePromise<ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>>;
|
|
434
|
+
description?: string | false;
|
|
435
|
+
type?: PrismaRef<Types, TypesForRelation<Types, Model, Field>>;
|
|
436
|
+
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
437
|
+
onNull?:
|
|
438
|
+
| 'error'
|
|
439
|
+
| ((
|
|
440
|
+
parent: Shape,
|
|
441
|
+
args: InputShapeFromFields<Args>,
|
|
442
|
+
context: Types['Context'],
|
|
443
|
+
info: GraphQLResolveInfo,
|
|
444
|
+
) => MaybePromise<
|
|
445
|
+
Error | ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>
|
|
446
|
+
>);
|
|
447
|
+
} & ({
|
|
448
|
+
field: boolean extends Nullable ? Types['DefaultFieldNullability'] : Nullable;
|
|
449
|
+
relation: Model['Relations'][Field]['Nullable'];
|
|
450
|
+
} extends { field: false; relation: true }
|
|
451
|
+
? { onNull: {} }
|
|
452
|
+
: {});
|
|
461
453
|
|
|
462
454
|
export type VariantFieldOptions<
|
|
463
455
|
Types extends SchemaTypes,
|
|
464
456
|
Model extends PrismaModelTypes,
|
|
465
|
-
Variant extends PrismaRef<Model>,
|
|
457
|
+
Variant extends PrismaRef<Types, Model>,
|
|
466
458
|
Args extends InputFieldMap,
|
|
467
459
|
isNull,
|
|
468
460
|
Shape,
|
|
@@ -475,7 +467,7 @@ export type VariantFieldOptions<
|
|
|
475
467
|
Args,
|
|
476
468
|
Model['Shape']
|
|
477
469
|
>,
|
|
478
|
-
|
|
470
|
+
InferredResolveOptionsKeys | 'type'
|
|
479
471
|
> & {
|
|
480
472
|
isNull?: isNull &
|
|
481
473
|
((
|
|
@@ -489,41 +481,29 @@ export type VariantFieldOptions<
|
|
|
489
481
|
export type RelationCountOptions<
|
|
490
482
|
Types extends SchemaTypes,
|
|
491
483
|
Shape,
|
|
492
|
-
NeedsResolve extends boolean,
|
|
493
484
|
Where,
|
|
494
485
|
Args extends InputFieldMap,
|
|
495
486
|
> = Omit<
|
|
496
487
|
PothosSchemaTypes.ObjectFieldOptions<Types, Shape, 'Int', false, Args, number>,
|
|
497
|
-
'
|
|
498
|
-
> &
|
|
499
|
-
(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
: {
|
|
509
|
-
resolve: (
|
|
510
|
-
parent: Shape,
|
|
511
|
-
args: InputShapeFromFields<Args>,
|
|
512
|
-
context: Types['Context'],
|
|
513
|
-
info: GraphQLResolveInfo,
|
|
514
|
-
) => MaybePromise<number>;
|
|
515
|
-
}) & {
|
|
516
|
-
where?: Where | ((args: InputShapeFromFields<Args>, context: Types['Context']) => Where);
|
|
517
|
-
};
|
|
488
|
+
'type' | InferredResolveOptionsKeys
|
|
489
|
+
> & {
|
|
490
|
+
resolve?: (
|
|
491
|
+
parent: Shape,
|
|
492
|
+
args: InputShapeFromFields<Args>,
|
|
493
|
+
context: Types['Context'],
|
|
494
|
+
info: GraphQLResolveInfo,
|
|
495
|
+
) => MaybePromise<number>;
|
|
496
|
+
where?: Where | ((args: InputShapeFromFields<Args>, context: Types['Context']) => Where);
|
|
497
|
+
};
|
|
518
498
|
|
|
519
499
|
export type PrismaFieldOptions<
|
|
520
500
|
Types extends SchemaTypes,
|
|
521
501
|
ParentShape,
|
|
522
502
|
Type extends
|
|
523
|
-
| PrismaRef<PrismaModelTypes>
|
|
503
|
+
| PrismaRef<Types, PrismaModelTypes>
|
|
524
504
|
| keyof Types['PrismaTypes']
|
|
525
505
|
| [keyof Types['PrismaTypes']]
|
|
526
|
-
| [PrismaRef<PrismaModelTypes>],
|
|
506
|
+
| [PrismaRef<Types, PrismaModelTypes>],
|
|
527
507
|
Model extends PrismaModelTypes,
|
|
528
508
|
Param extends TypeParam<Types>,
|
|
529
509
|
Args extends InputFieldMap,
|
|
@@ -531,35 +511,46 @@ export type PrismaFieldOptions<
|
|
|
531
511
|
ResolveShape,
|
|
532
512
|
ResolveReturnShape,
|
|
533
513
|
Kind extends FieldKind = FieldKind,
|
|
534
|
-
> =
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
514
|
+
> =
|
|
515
|
+
FieldOptionsFromKind<
|
|
516
|
+
Types,
|
|
517
|
+
ParentShape,
|
|
518
|
+
Param,
|
|
519
|
+
Nullable,
|
|
520
|
+
Args,
|
|
521
|
+
Kind,
|
|
522
|
+
ResolveShape,
|
|
523
|
+
ResolveReturnShape
|
|
524
|
+
> extends infer FieldOptions
|
|
525
|
+
? Omit<FieldOptions, InferredResolveOptionsKeys | 'type'> & {
|
|
526
|
+
type: Type;
|
|
527
|
+
resolve: FieldOptions extends {
|
|
528
|
+
resolve?: (parent: infer Parent, ...args: any[]) => unknown;
|
|
529
|
+
}
|
|
530
|
+
? PrismaFieldResolver<Types, Model, Parent, Param, Args, Nullable, ResolveReturnShape>
|
|
531
|
+
: PrismaFieldResolver<
|
|
532
|
+
Types,
|
|
533
|
+
Model,
|
|
534
|
+
ParentShape,
|
|
535
|
+
Param,
|
|
536
|
+
Args,
|
|
537
|
+
Nullable,
|
|
538
|
+
ResolveReturnShape
|
|
539
|
+
>;
|
|
540
|
+
}
|
|
541
|
+
: never;
|
|
551
542
|
|
|
552
543
|
export type PrismaFieldWithInputOptions<
|
|
553
544
|
Types extends SchemaTypes,
|
|
554
545
|
ParentShape,
|
|
555
546
|
Kind extends FieldKind,
|
|
556
|
-
Args extends
|
|
557
|
-
Fields extends
|
|
547
|
+
Args extends InputFieldMap,
|
|
548
|
+
Fields extends InputFieldMap,
|
|
558
549
|
Type extends
|
|
559
|
-
| PrismaRef<PrismaModelTypes>
|
|
550
|
+
| PrismaRef<Types, PrismaModelTypes>
|
|
560
551
|
| keyof Types['PrismaTypes']
|
|
561
552
|
| [keyof Types['PrismaTypes']]
|
|
562
|
-
| [PrismaRef<PrismaModelTypes>],
|
|
553
|
+
| [PrismaRef<Types, PrismaModelTypes>],
|
|
563
554
|
Model extends PrismaModelTypes,
|
|
564
555
|
Param extends TypeParam<Types>,
|
|
565
556
|
Nullable extends FieldNullability<Param>,
|
|
@@ -575,7 +566,8 @@ export type PrismaFieldWithInputOptions<
|
|
|
575
566
|
Model,
|
|
576
567
|
Param,
|
|
577
568
|
Args & {
|
|
578
|
-
[K in InputName]:
|
|
569
|
+
[K in InputName]: ArgumentRef<
|
|
570
|
+
Types,
|
|
579
571
|
InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
|
|
580
572
|
>;
|
|
581
573
|
},
|
|
@@ -589,7 +581,8 @@ export type PrismaFieldWithInputOptions<
|
|
|
589
581
|
PothosSchemaTypes.FieldWithInputBaseOptions<
|
|
590
582
|
Types,
|
|
591
583
|
Args & {
|
|
592
|
-
[K in InputName]:
|
|
584
|
+
[K in InputName]: ArgumentRef<
|
|
585
|
+
Types,
|
|
593
586
|
InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
|
|
594
587
|
>;
|
|
595
588
|
},
|
|
@@ -625,8 +618,8 @@ export type PrismaConnectionFieldOptions<
|
|
|
625
618
|
Types extends SchemaTypes,
|
|
626
619
|
ParentShape,
|
|
627
620
|
Type extends
|
|
628
|
-
| PrismaInterfaceRef<PrismaModelTypes>
|
|
629
|
-
| PrismaRef<PrismaModelTypes>
|
|
621
|
+
| PrismaInterfaceRef<Types, PrismaModelTypes>
|
|
622
|
+
| PrismaRef<Types, PrismaModelTypes>
|
|
630
623
|
| keyof Types['PrismaTypes'],
|
|
631
624
|
Model extends PrismaModelTypes,
|
|
632
625
|
Param extends OutputType<Types>,
|
|
@@ -641,13 +634,13 @@ export type PrismaConnectionFieldOptions<
|
|
|
641
634
|
ParentShape,
|
|
642
635
|
Param,
|
|
643
636
|
Nullable,
|
|
644
|
-
InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments> &
|
|
637
|
+
InputFieldsFromShape<Types, PothosSchemaTypes.DefaultConnectionArguments, 'Arg'> &
|
|
645
638
|
(InputFieldMap extends Args ? {} : Args),
|
|
646
639
|
Kind,
|
|
647
640
|
ParentShape,
|
|
648
641
|
ResolveReturnShape
|
|
649
642
|
>,
|
|
650
|
-
'args' |
|
|
643
|
+
'args' | InferredResolveOptionsKeys | 'type'
|
|
651
644
|
> &
|
|
652
645
|
Omit<
|
|
653
646
|
PothosSchemaTypes.ConnectionFieldOptions<
|
|
@@ -660,7 +653,7 @@ export type PrismaConnectionFieldOptions<
|
|
|
660
653
|
Args,
|
|
661
654
|
ResolveReturnShape
|
|
662
655
|
>,
|
|
663
|
-
|
|
656
|
+
InferredResolveOptionsKeys | 'type'
|
|
664
657
|
> &
|
|
665
658
|
(InputShapeFromFields<Args> &
|
|
666
659
|
PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
|
|
@@ -700,83 +693,61 @@ export type RelatedConnectionOptions<
|
|
|
700
693
|
Field extends Model['ListRelations'],
|
|
701
694
|
Nullable extends boolean,
|
|
702
695
|
Args extends InputFieldMap,
|
|
703
|
-
NeedsResolve extends boolean,
|
|
704
696
|
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
705
697
|
> = Omit<
|
|
706
698
|
PothosSchemaTypes.ObjectFieldOptions<
|
|
707
699
|
Types,
|
|
708
700
|
Model['Shape'],
|
|
709
|
-
ObjectRef<unknown>,
|
|
701
|
+
ObjectRef<Types, unknown>,
|
|
710
702
|
Nullable,
|
|
711
|
-
InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments> &
|
|
703
|
+
InputFieldsFromShape<Types, PothosSchemaTypes.DefaultConnectionArguments, 'InputObject'> &
|
|
712
704
|
(InputFieldMap extends Args ? {} : Args),
|
|
713
705
|
unknown
|
|
714
706
|
>,
|
|
715
|
-
'args' | 'description' |
|
|
707
|
+
'args' | 'description' | InferredResolveOptionsKeys | 'type'
|
|
716
708
|
> &
|
|
717
709
|
Omit<
|
|
718
710
|
PothosSchemaTypes.ConnectionFieldOptions<
|
|
719
711
|
Types,
|
|
720
712
|
Model['Shape'],
|
|
721
|
-
ObjectRef<unknown>,
|
|
713
|
+
ObjectRef<Types, unknown>,
|
|
722
714
|
false,
|
|
723
715
|
false,
|
|
724
716
|
Nullable,
|
|
725
717
|
Args,
|
|
726
718
|
unknown
|
|
727
719
|
>,
|
|
728
|
-
|
|
720
|
+
InferredResolveOptionsKeys | 'type'
|
|
729
721
|
> &
|
|
730
722
|
(InputShapeFromFields<Args> &
|
|
731
723
|
PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
|
|
732
|
-
?
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
: {
|
|
754
|
-
resolve: (
|
|
755
|
-
query: {
|
|
756
|
-
include?: Model['Include'];
|
|
757
|
-
cursor?: Model['WhereUnique'];
|
|
758
|
-
take: number;
|
|
759
|
-
skip: number;
|
|
760
|
-
},
|
|
761
|
-
parent: Model['Shape'],
|
|
762
|
-
args: ConnectionArgs,
|
|
763
|
-
context: Types['Context'],
|
|
764
|
-
info: GraphQLResolveInfo,
|
|
765
|
-
) => MaybePromise<
|
|
766
|
-
ShapeFromTypeParam<
|
|
767
|
-
Types,
|
|
768
|
-
[ObjectRef<Model['Relations'][Field & keyof Model['Relations']]['Shape']>],
|
|
769
|
-
Nullable
|
|
770
|
-
>
|
|
771
|
-
>;
|
|
772
|
-
}) & {
|
|
724
|
+
? {
|
|
725
|
+
resolve?: (
|
|
726
|
+
query: {
|
|
727
|
+
include?: Model['Include'];
|
|
728
|
+
cursor?: Model['WhereUnique'];
|
|
729
|
+
take: number;
|
|
730
|
+
skip: number;
|
|
731
|
+
},
|
|
732
|
+
parent: Model['Shape'],
|
|
733
|
+
args: ConnectionArgs,
|
|
734
|
+
context: Types['Context'],
|
|
735
|
+
info: GraphQLResolveInfo,
|
|
736
|
+
) => MaybePromise<
|
|
737
|
+
ShapeFromTypeParam<
|
|
738
|
+
Types,
|
|
739
|
+
[ObjectRef<Types, Model['Relations'][Field & keyof Model['Relations']]['Shape']>],
|
|
740
|
+
Nullable
|
|
741
|
+
>
|
|
742
|
+
>;
|
|
743
|
+
} & {
|
|
773
744
|
description?: string | false;
|
|
774
745
|
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
775
|
-
type?: PrismaRef<TypesForRelation<Types, Model, Field>>;
|
|
746
|
+
type?: PrismaRef<Types, TypesForRelation<Types, Model, Field>>;
|
|
776
747
|
cursor: CursorFromRelation<Model, Field>;
|
|
777
748
|
defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
778
749
|
maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
779
|
-
totalCount?:
|
|
750
|
+
totalCount?: boolean;
|
|
780
751
|
}
|
|
781
752
|
: never);
|
|
782
753
|
|
|
@@ -834,8 +805,10 @@ export type PrismaConnectionShape<
|
|
|
834
805
|
}
|
|
835
806
|
: never
|
|
836
807
|
) extends infer C
|
|
837
|
-
? [C] extends [
|
|
838
|
-
|
|
808
|
+
? [C] extends [
|
|
809
|
+
{ edges: MaybePromise<readonly (infer Edge | null | undefined)[] | null | undefined> },
|
|
810
|
+
]
|
|
811
|
+
? Omit<C, 'edges'> & { edges: (Edge & { connection: C })[] }
|
|
839
812
|
: C
|
|
840
813
|
: never;
|
|
841
814
|
|
|
@@ -853,3 +826,32 @@ export type UniqueFieldsFromWhereUnique<T> = string &
|
|
|
853
826
|
? keyof T
|
|
854
827
|
: K
|
|
855
828
|
: never);
|
|
829
|
+
|
|
830
|
+
interface DMMFField {
|
|
831
|
+
type: string;
|
|
832
|
+
kind: string;
|
|
833
|
+
name: string;
|
|
834
|
+
isRequired: boolean;
|
|
835
|
+
isList: boolean;
|
|
836
|
+
hasDefaultValue: boolean;
|
|
837
|
+
isUnique: boolean;
|
|
838
|
+
isId: boolean;
|
|
839
|
+
documentation?: string;
|
|
840
|
+
relationName?: string;
|
|
841
|
+
relationFromFields?: readonly string[];
|
|
842
|
+
isUpdatedAt?: boolean;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
export interface PothosPrismaDatamodel {
|
|
846
|
+
datamodel: {
|
|
847
|
+
models: Record<
|
|
848
|
+
string,
|
|
849
|
+
{
|
|
850
|
+
fields: readonly DMMFField[];
|
|
851
|
+
primaryKey: { name: string | null; fields: readonly string[] } | null;
|
|
852
|
+
uniqueIndexes: { name: string | null; fields: readonly string[] }[];
|
|
853
|
+
documentation?: string;
|
|
854
|
+
}
|
|
855
|
+
>;
|
|
856
|
+
};
|
|
857
|
+
}
|
package/src/util/datamodel.ts
CHANGED
|
@@ -4,22 +4,22 @@ import { PrismaObjectRef } from '../object-ref';
|
|
|
4
4
|
import { PrismaClient, PrismaDelegate, PrismaModelTypes } from '../types';
|
|
5
5
|
import { getDMMF } from './get-client';
|
|
6
6
|
|
|
7
|
-
export const refMap = new WeakMap<object, Map<string, PrismaRef<PrismaModelTypes>>>();
|
|
7
|
+
export const refMap = new WeakMap<object, Map<string, PrismaRef<never, PrismaModelTypes>>>();
|
|
8
8
|
export const findUniqueMap = new WeakMap<
|
|
9
9
|
object,
|
|
10
|
-
Map<ObjectRef<unknown>, ((args: unknown, ctx: {}) => unknown) | null>
|
|
10
|
+
Map<ObjectRef<SchemaTypes, unknown>, ((args: unknown, ctx: {}) => unknown) | null>
|
|
11
11
|
>();
|
|
12
12
|
|
|
13
13
|
export const includeForRefMap = new WeakMap<
|
|
14
14
|
object,
|
|
15
|
-
Map<ObjectRef<unknown>, Record<string, unknown> | null>
|
|
15
|
+
Map<ObjectRef<SchemaTypes, unknown>, Record<string, unknown> | null>
|
|
16
16
|
>();
|
|
17
17
|
|
|
18
18
|
export function getRefFromModel<Types extends SchemaTypes>(
|
|
19
19
|
name: string,
|
|
20
20
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
21
21
|
type: 'interface' | 'object' = 'object',
|
|
22
|
-
): PrismaRef<PrismaModelTypes> {
|
|
22
|
+
): PrismaRef<Types, PrismaModelTypes> {
|
|
23
23
|
if (!refMap.has(builder)) {
|
|
24
24
|
refMap.set(builder, new Map());
|
|
25
25
|
}
|
|
@@ -32,7 +32,7 @@ export function getRefFromModel<Types extends SchemaTypes>(
|
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
return cache.get(name)
|
|
35
|
+
return cache.get(name)! as never;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function getRelation<Types extends SchemaTypes>(
|