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