@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
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
ExposeNullability,
|
|
14
14
|
FieldKind,
|
|
15
15
|
FieldRef,
|
|
16
|
+
InferredResolveOptionsKeys,
|
|
16
17
|
InputFieldMap,
|
|
17
18
|
InterfaceParam,
|
|
18
19
|
isThenable,
|
|
@@ -52,38 +53,31 @@ import { FieldMap } from './util/relation-map';
|
|
|
52
53
|
const RootBuilder: {
|
|
53
54
|
// eslint-disable-next-line @typescript-eslint/prefer-function-type
|
|
54
55
|
new <Types extends SchemaTypes, Shape, Kind extends FieldKind>(
|
|
55
|
-
name: string,
|
|
56
56
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
57
57
|
kind: FieldKind,
|
|
58
58
|
graphqlKind: PothosSchemaTypes.PothosKindToGraphQLType[FieldKind],
|
|
59
59
|
): PothosSchemaTypes.RootFieldBuilder<Types, Shape, Kind>;
|
|
60
60
|
} = RootFieldBuilder as never;
|
|
61
61
|
|
|
62
|
-
type ContextForAuth<
|
|
63
|
-
Types extends
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
type ContextForAuth<Types extends SchemaTypes, Scopes extends {} = {}> =
|
|
63
|
+
PothosSchemaTypes.ScopeAuthContextForAuth<Types, Scopes> extends {
|
|
64
|
+
Context: infer T;
|
|
65
|
+
}
|
|
66
|
+
? T extends object
|
|
67
|
+
? T
|
|
68
|
+
: object
|
|
69
|
+
: object;
|
|
70
|
+
|
|
71
|
+
type FieldAuthScopes<Types extends SchemaTypes, Parent, Args extends {} = {}> =
|
|
72
|
+
PothosSchemaTypes.ScopeAuthFieldAuthScopes<Types, Parent, Args> extends {
|
|
73
|
+
Scopes: infer T;
|
|
74
|
+
}
|
|
69
75
|
? T
|
|
70
|
-
:
|
|
71
|
-
: object;
|
|
72
|
-
|
|
73
|
-
type FieldAuthScopes<
|
|
74
|
-
Types extends SchemaTypes,
|
|
75
|
-
Parent,
|
|
76
|
-
Args extends {} = {},
|
|
77
|
-
> = PothosSchemaTypes.ScopeAuthFieldAuthScopes<Types, Parent, Args> extends {
|
|
78
|
-
Scopes: infer T;
|
|
79
|
-
}
|
|
80
|
-
? T
|
|
81
|
-
: never;
|
|
76
|
+
: never;
|
|
82
77
|
|
|
83
78
|
export class PrismaObjectFieldBuilder<
|
|
84
79
|
Types extends SchemaTypes,
|
|
85
80
|
Model extends PrismaModelTypes,
|
|
86
|
-
NeedsResolve extends boolean,
|
|
87
81
|
Shape extends object = Model['Shape'],
|
|
88
82
|
> extends RootBuilder<Types, Shape, 'PrismaObject'> {
|
|
89
83
|
model: string;
|
|
@@ -116,7 +110,6 @@ export class PrismaObjectFieldBuilder<
|
|
|
116
110
|
) => PothosSchemaTypes.PrismaObjectFieldBuilder<
|
|
117
111
|
Omit<Types, 'Context'> & { Context: ContextForAuth<Types, Scopes> },
|
|
118
112
|
Model,
|
|
119
|
-
NeedsResolve,
|
|
120
113
|
Shape
|
|
121
114
|
>
|
|
122
115
|
: '@pothos/plugin-scope-auth is required to use this method' = withAuth as never;
|
|
@@ -130,19 +123,31 @@ export class PrismaObjectFieldBuilder<
|
|
|
130
123
|
EdgeInterfaces extends InterfaceParam<Types>[] = [],
|
|
131
124
|
>(
|
|
132
125
|
field: Field,
|
|
133
|
-
options: RelatedConnectionOptions<Types, Model, Field, Nullable, Args
|
|
126
|
+
options: RelatedConnectionOptions<Types, Model, Field, Nullable, Args>,
|
|
134
127
|
...args: NormalizeArgs<
|
|
135
128
|
[
|
|
136
129
|
connectionOptions:
|
|
137
130
|
| ObjectRef<
|
|
131
|
+
Types,
|
|
132
|
+
ShapeFromConnection<
|
|
133
|
+
PothosSchemaTypes.ConnectionShapeHelper<
|
|
134
|
+
Types,
|
|
135
|
+
TypesForRelation<Types, Model, Field>['Shape'],
|
|
136
|
+
false
|
|
137
|
+
>
|
|
138
|
+
>
|
|
139
|
+
>
|
|
140
|
+
| ObjectRef<
|
|
141
|
+
Types,
|
|
138
142
|
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, false>>
|
|
139
143
|
>
|
|
140
144
|
| PothosSchemaTypes.ConnectionObjectOptions<
|
|
141
145
|
Types,
|
|
142
146
|
ObjectRef<
|
|
147
|
+
Types,
|
|
143
148
|
ShapeFromTypeParam<
|
|
144
149
|
Types,
|
|
145
|
-
[ObjectRef<
|
|
150
|
+
[ObjectRef<Types, TypesForRelation<Types, Model, Field>['Shape']>],
|
|
146
151
|
Nullable
|
|
147
152
|
>
|
|
148
153
|
>,
|
|
@@ -152,7 +157,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
152
157
|
Types,
|
|
153
158
|
ShapeFromTypeParam<
|
|
154
159
|
Types,
|
|
155
|
-
[ObjectRef<
|
|
160
|
+
[ObjectRef<Types, TypesForRelation<Types, Model, Field>['Shape']>],
|
|
156
161
|
Nullable
|
|
157
162
|
>,
|
|
158
163
|
Shape,
|
|
@@ -161,16 +166,25 @@ export class PrismaObjectFieldBuilder<
|
|
|
161
166
|
ConnectionInterfaces
|
|
162
167
|
>,
|
|
163
168
|
edgeOptions:
|
|
164
|
-
| ObjectRef<
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
| ObjectRef<
|
|
170
|
+
Types,
|
|
171
|
+
{
|
|
172
|
+
cursor: string;
|
|
173
|
+
node?: ShapeFromTypeParam<Types, Model['Shape'], false>;
|
|
174
|
+
}
|
|
175
|
+
>
|
|
168
176
|
| PothosSchemaTypes.ConnectionEdgeObjectOptions<
|
|
169
177
|
Types,
|
|
170
178
|
ObjectRef<
|
|
179
|
+
Types,
|
|
171
180
|
ShapeFromTypeParam<
|
|
172
181
|
Types,
|
|
173
|
-
[
|
|
182
|
+
[
|
|
183
|
+
ObjectRef<
|
|
184
|
+
Types,
|
|
185
|
+
Model['Relations'][Field & keyof Model['Relations']]['Shape']
|
|
186
|
+
>,
|
|
187
|
+
],
|
|
174
188
|
Nullable
|
|
175
189
|
>
|
|
176
190
|
>,
|
|
@@ -179,7 +193,12 @@ export class PrismaObjectFieldBuilder<
|
|
|
179
193
|
Types,
|
|
180
194
|
ShapeFromTypeParam<
|
|
181
195
|
Types,
|
|
182
|
-
[
|
|
196
|
+
[
|
|
197
|
+
ObjectRef<
|
|
198
|
+
Types,
|
|
199
|
+
Model['Relations'][Field & keyof Model['Relations']]['Shape']
|
|
200
|
+
>,
|
|
201
|
+
],
|
|
183
202
|
Nullable
|
|
184
203
|
>,
|
|
185
204
|
Shape,
|
|
@@ -191,10 +210,11 @@ export class PrismaObjectFieldBuilder<
|
|
|
191
210
|
0
|
|
192
211
|
>
|
|
193
212
|
) => FieldRef<
|
|
213
|
+
Types,
|
|
194
214
|
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, Nullable>>
|
|
195
215
|
>
|
|
196
216
|
: '@pothos/plugin-relay is required to use this method' = function relatedConnection(
|
|
197
|
-
this: PrismaObjectFieldBuilder<SchemaTypes, Model
|
|
217
|
+
this: PrismaObjectFieldBuilder<SchemaTypes, Model>,
|
|
198
218
|
name: string,
|
|
199
219
|
{
|
|
200
220
|
maxSize = this.builder.options.prisma.maxConnectionSize,
|
|
@@ -207,7 +227,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
207
227
|
description,
|
|
208
228
|
...options
|
|
209
229
|
}: {
|
|
210
|
-
type?: ObjectRef<unknown, unknown>;
|
|
230
|
+
type?: ObjectRef<Types, unknown, unknown>;
|
|
211
231
|
totalCount?: boolean;
|
|
212
232
|
maxSize?: number | ((args: {}, ctx: {}) => number);
|
|
213
233
|
defaultSize?: number | ((args: {}, ctx: {}) => number);
|
|
@@ -260,7 +280,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
260
280
|
};
|
|
261
281
|
|
|
262
282
|
const cursorSelection = ModelLoader.getCursorSelection(
|
|
263
|
-
ref,
|
|
283
|
+
ref as never,
|
|
264
284
|
relationField.type,
|
|
265
285
|
cursorValue,
|
|
266
286
|
this.builder,
|
|
@@ -283,11 +303,12 @@ export class PrismaObjectFieldBuilder<
|
|
|
283
303
|
|
|
284
304
|
const totalCountOnly = selection.selectionSet?.selections.length === 1 && hasTotalCount;
|
|
285
305
|
|
|
286
|
-
const countSelect =
|
|
287
|
-
|
|
288
|
-
?
|
|
289
|
-
|
|
290
|
-
|
|
306
|
+
const countSelect =
|
|
307
|
+
this.builder.options.prisma.filterConnectionTotalCount !== false
|
|
308
|
+
? nested.where
|
|
309
|
+
? { where: nested.where }
|
|
310
|
+
: true
|
|
311
|
+
: true;
|
|
291
312
|
|
|
292
313
|
return {
|
|
293
314
|
select: {
|
|
@@ -309,7 +330,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
309
330
|
|
|
310
331
|
const fieldRef = (
|
|
311
332
|
this as unknown as {
|
|
312
|
-
connection: (...args: unknown[]) => FieldRef<unknown>;
|
|
333
|
+
connection: (...args: unknown[]) => FieldRef<Types, unknown>;
|
|
313
334
|
}
|
|
314
335
|
).connection(
|
|
315
336
|
{
|
|
@@ -402,17 +423,21 @@ export class PrismaObjectFieldBuilder<
|
|
|
402
423
|
return fieldRef;
|
|
403
424
|
} as never;
|
|
404
425
|
|
|
426
|
+
typename: string;
|
|
427
|
+
|
|
405
428
|
constructor(
|
|
406
|
-
|
|
429
|
+
typename: string,
|
|
407
430
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
408
431
|
model: string,
|
|
409
432
|
fieldMap: FieldMap,
|
|
410
433
|
graphqlKind: PothosSchemaTypes.PothosKindToGraphQLType[FieldKind] = 'Object',
|
|
411
434
|
) {
|
|
412
|
-
super(
|
|
435
|
+
super(builder, 'PrismaObject', graphqlKind);
|
|
413
436
|
|
|
414
437
|
this.model = model;
|
|
415
438
|
this.prismaFieldMap = fieldMap;
|
|
439
|
+
this.typename = typename;
|
|
440
|
+
this.builder = builder;
|
|
416
441
|
}
|
|
417
442
|
|
|
418
443
|
relation<
|
|
@@ -423,25 +448,14 @@ export class PrismaObjectFieldBuilder<
|
|
|
423
448
|
>(
|
|
424
449
|
name: Field,
|
|
425
450
|
...allArgs: NormalizeArgs<
|
|
426
|
-
[
|
|
427
|
-
options: RelatedFieldOptions<
|
|
428
|
-
Types,
|
|
429
|
-
Model,
|
|
430
|
-
Field,
|
|
431
|
-
Nullable,
|
|
432
|
-
Args,
|
|
433
|
-
ResolveReturnShape,
|
|
434
|
-
NeedsResolve,
|
|
435
|
-
Shape
|
|
436
|
-
>,
|
|
437
|
-
]
|
|
451
|
+
[options: RelatedFieldOptions<Types, Model, Field, Nullable, Args, ResolveReturnShape, Shape>]
|
|
438
452
|
>
|
|
439
|
-
): FieldRef<Model['Relations'][Field]['Shape'], 'Object'> {
|
|
453
|
+
): FieldRef<Types, Model['Relations'][Field]['Shape'], 'Object'> {
|
|
440
454
|
const [{ description, ...options } = {} as never] = allArgs;
|
|
441
455
|
const relationField = getRelation(this.model, this.builder, name);
|
|
442
456
|
const ref = options.type ?? getRefFromModel(relationField.type, this.builder);
|
|
443
457
|
|
|
444
|
-
const { query = {}, resolve, extensions, ...rest } = options;
|
|
458
|
+
const { query = {}, resolve, extensions, onNull, ...rest } = options;
|
|
445
459
|
|
|
446
460
|
const relationSelect = (
|
|
447
461
|
args: object,
|
|
@@ -468,8 +482,16 @@ export class PrismaObjectFieldBuilder<
|
|
|
468
482
|
info,
|
|
469
483
|
)),
|
|
470
484
|
},
|
|
471
|
-
resolve: (parent) =>
|
|
472
|
-
|
|
485
|
+
resolve: (parent) => {
|
|
486
|
+
const result = (parent as Record<string, never>)[name];
|
|
487
|
+
|
|
488
|
+
if (typeof onNull === 'function' && result == null) {
|
|
489
|
+
return onNull(parent, {} as never, {} as never, {} as never) as never;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return result;
|
|
493
|
+
},
|
|
494
|
+
}) as FieldRef<Types, Model['Relations'][Field]['Shape'], 'Object'>;
|
|
473
495
|
}
|
|
474
496
|
|
|
475
497
|
relationCount<Field extends Model['RelationName'], Args extends InputFieldMap>(
|
|
@@ -479,13 +501,12 @@ export class PrismaObjectFieldBuilder<
|
|
|
479
501
|
options: RelationCountOptions<
|
|
480
502
|
Types,
|
|
481
503
|
Shape,
|
|
482
|
-
NeedsResolve,
|
|
483
504
|
TypesForRelation<Types, Model, Field>['Where'],
|
|
484
505
|
Args
|
|
485
506
|
>,
|
|
486
507
|
]
|
|
487
508
|
>
|
|
488
|
-
): FieldRef<number, 'Object'> {
|
|
509
|
+
): FieldRef<Types, number, 'Object'> {
|
|
489
510
|
const [{ where, ...options } = {} as never] = allArgs;
|
|
490
511
|
|
|
491
512
|
const { resolve, ...rest } = options;
|
|
@@ -512,26 +533,30 @@ export class PrismaObjectFieldBuilder<
|
|
|
512
533
|
select: countSelect as never,
|
|
513
534
|
resolve: (parent, args, context, info) =>
|
|
514
535
|
(parent as unknown as { _count: Record<string, never> })._count?.[name],
|
|
515
|
-
}) as FieldRef<number, 'Object'>;
|
|
536
|
+
}) as FieldRef<Types, number, 'Object'>;
|
|
516
537
|
}
|
|
517
538
|
|
|
518
|
-
variant<
|
|
539
|
+
variant<
|
|
540
|
+
Variant extends Model['Name'] | PrismaRef<Types, Model>,
|
|
541
|
+
Args extends InputFieldMap,
|
|
542
|
+
Nullable,
|
|
543
|
+
>(
|
|
519
544
|
variant: Variant,
|
|
520
545
|
...allArgs: NormalizeArgs<
|
|
521
546
|
[
|
|
522
547
|
options: VariantFieldOptions<
|
|
523
548
|
Types,
|
|
524
549
|
Model,
|
|
525
|
-
Variant extends PrismaRef<Model> ? Variant : PrismaRef<Model>,
|
|
550
|
+
Variant extends PrismaRef<Types, Model> ? Variant : PrismaRef<Types, Model>,
|
|
526
551
|
Args,
|
|
527
552
|
Nullable,
|
|
528
553
|
Shape
|
|
529
554
|
>,
|
|
530
555
|
]
|
|
531
556
|
>
|
|
532
|
-
): FieldRef<Model['Shape'], 'Object'> {
|
|
557
|
+
): FieldRef<Types, Model['Shape'], 'Object'> {
|
|
533
558
|
const [{ isNull, nullable, ...options } = {} as never] = allArgs;
|
|
534
|
-
const ref: PrismaRef<PrismaModelTypes> =
|
|
559
|
+
const ref: PrismaRef<Types, PrismaModelTypes> =
|
|
535
560
|
typeof variant === 'string' ? getRefFromModel(variant, this.builder) : variant;
|
|
536
561
|
|
|
537
562
|
const selfSelect = (args: object, context: object, nestedQuery: (query: unknown) => unknown) =>
|
|
@@ -557,7 +582,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
557
582
|
return parent as never;
|
|
558
583
|
}
|
|
559
584
|
: (parent) => parent as never,
|
|
560
|
-
}) as FieldRef<Model['Shape'], 'Object'>;
|
|
585
|
+
}) as FieldRef<Types, Model['Shape'], 'Object'>;
|
|
561
586
|
}
|
|
562
587
|
|
|
563
588
|
expose<
|
|
@@ -579,7 +604,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
579
604
|
{},
|
|
580
605
|
ResolveReturnShape
|
|
581
606
|
>,
|
|
582
|
-
'description' | 'nullable' | '
|
|
607
|
+
'description' | 'nullable' | 'select' | InferredResolveOptionsKeys
|
|
583
608
|
> & {
|
|
584
609
|
description?: string | false;
|
|
585
610
|
},
|
|
@@ -613,7 +638,12 @@ export class PrismaObjectFieldBuilder<
|
|
|
613
638
|
return <
|
|
614
639
|
Nullable extends boolean,
|
|
615
640
|
ResolveReturnShape,
|
|
616
|
-
Name extends CompatibleTypes<
|
|
641
|
+
Name extends CompatibleTypes<
|
|
642
|
+
Types,
|
|
643
|
+
Model['Shape'],
|
|
644
|
+
Type,
|
|
645
|
+
Type extends [unknown] ? { list: true; items: true } : true
|
|
646
|
+
>,
|
|
617
647
|
>(
|
|
618
648
|
name: Name,
|
|
619
649
|
...args: NormalizeArgs<
|
|
@@ -628,13 +658,13 @@ export class PrismaObjectFieldBuilder<
|
|
|
628
658
|
{},
|
|
629
659
|
ResolveReturnShape
|
|
630
660
|
>,
|
|
631
|
-
'description' | 'nullable' | '
|
|
661
|
+
'description' | 'nullable' | 'select' | 'type' | InferredResolveOptionsKeys
|
|
632
662
|
> & {
|
|
633
663
|
description?: string | false;
|
|
634
664
|
},
|
|
635
665
|
]
|
|
636
666
|
>
|
|
637
|
-
): FieldRef<ShapeFromTypeParam<Types, Type, Nullable>, 'PrismaObject'> => {
|
|
667
|
+
): FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>, 'PrismaObject'> => {
|
|
638
668
|
const [options = {} as never] = args;
|
|
639
669
|
|
|
640
670
|
return this.expose<Type, Nullable, ResolveReturnShape, never>(
|
|
@@ -665,10 +695,7 @@ function addScopes(
|
|
|
665
695
|
return builder as never;
|
|
666
696
|
}
|
|
667
697
|
|
|
668
|
-
function withAuth(
|
|
669
|
-
this: PrismaObjectFieldBuilder<SchemaTypes, PrismaModelTypes, false, {}>,
|
|
670
|
-
scopes: {},
|
|
671
|
-
) {
|
|
698
|
+
function withAuth(this: PrismaObjectFieldBuilder<SchemaTypes, PrismaModelTypes, {}>, scopes: {}) {
|
|
672
699
|
return addScopes(
|
|
673
700
|
scopes,
|
|
674
701
|
new PrismaObjectFieldBuilder(
|
package/src/schema-builder.ts
CHANGED
|
@@ -30,7 +30,7 @@ schemaBuilderProto.prismaObject = function prismaObject(
|
|
|
30
30
|
) {
|
|
31
31
|
const ref = options.variant
|
|
32
32
|
? new PrismaObjectRef(options.variant, type)
|
|
33
|
-
: (getRefFromModel(type, this) as PrismaObjectRef<PrismaModelTypes>);
|
|
33
|
+
: (getRefFromModel(type, this) as PrismaObjectRef<SchemaTypes, PrismaModelTypes>);
|
|
34
34
|
const name = options.variant ?? options.name ?? type;
|
|
35
35
|
const fieldMap = getRelationMap(getDMMF(this)).get(type)!;
|
|
36
36
|
const idSelection = ModelLoader.getDefaultIDSelection(ref, type, this);
|
|
@@ -53,7 +53,7 @@ schemaBuilderProto.prismaObject = function prismaObject(
|
|
|
53
53
|
? () =>
|
|
54
54
|
fields(
|
|
55
55
|
new PrismaObjectFieldBuilder(
|
|
56
|
-
name,
|
|
56
|
+
ref.name,
|
|
57
57
|
this,
|
|
58
58
|
type,
|
|
59
59
|
getRelationMap(getDMMF(this)).get(type)!,
|
|
@@ -71,7 +71,10 @@ schemaBuilderProto.prismaInterface = function prismaInterface(
|
|
|
71
71
|
) {
|
|
72
72
|
const ref = options.variant
|
|
73
73
|
? new PrismaInterfaceRef(options.variant, type)
|
|
74
|
-
: (getRefFromModel(type, this, 'interface') as PrismaInterfaceRef<
|
|
74
|
+
: (getRefFromModel(type, this, 'interface') as PrismaInterfaceRef<
|
|
75
|
+
SchemaTypes,
|
|
76
|
+
PrismaModelTypes
|
|
77
|
+
>);
|
|
75
78
|
const name = options.variant ?? options.name ?? type;
|
|
76
79
|
const fieldMap = getRelationMap(getDMMF(this)).get(type)!;
|
|
77
80
|
const idSelection = ModelLoader.getDefaultIDSelection(ref, type, this);
|
|
@@ -109,7 +112,7 @@ schemaBuilderProto.prismaInterface = function prismaInterface(
|
|
|
109
112
|
|
|
110
113
|
schemaBuilderProto.prismaNode = function prismaNode(
|
|
111
114
|
this: PothosSchemaTypes.SchemaBuilder<SchemaTypes> & {
|
|
112
|
-
nodeInterfaceRef?: () => InterfaceRef<unknown>;
|
|
115
|
+
nodeInterfaceRef?: () => InterfaceRef<SchemaTypes, unknown>;
|
|
113
116
|
},
|
|
114
117
|
type: keyof SchemaTypes['PrismaTypes'],
|
|
115
118
|
{
|
|
@@ -170,7 +173,7 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
170
173
|
const ref = this.prismaObject(type, extendedOptions as never);
|
|
171
174
|
|
|
172
175
|
if (options.interfaces) {
|
|
173
|
-
|
|
176
|
+
ref.addInterfaces(options.interfaces);
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
this.configStore.onTypeConfig(ref, (nodeConfig) => {
|
|
@@ -181,7 +184,7 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
181
184
|
(t) =>
|
|
182
185
|
(
|
|
183
186
|
t as unknown as {
|
|
184
|
-
globalID: (options: Record<string, unknown>) => FieldRef<unknown>;
|
|
187
|
+
globalID: (options: Record<string, unknown>) => FieldRef<SchemaTypes, unknown>;
|
|
185
188
|
}
|
|
186
189
|
).globalID({
|
|
187
190
|
...(this.options as { relayOptions?: { idFieldOptions?: {} } }).relayOptions
|
|
@@ -198,7 +201,7 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
198
201
|
);
|
|
199
202
|
});
|
|
200
203
|
|
|
201
|
-
this.configStore.
|
|
204
|
+
this.configStore.associateParamWithRef(nodeRef, ref);
|
|
202
205
|
|
|
203
206
|
return nodeRef;
|
|
204
207
|
} as never;
|