@pothos/plugin-prisma 3.59.0 → 3.59.2
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 +12 -0
- package/dts/connection-helpers.d.ts +6 -6
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/global-types.d.ts +13 -13
- package/dts/global-types.d.ts.map +1 -1
- package/dts/interface-ref.d.ts +1 -1
- package/dts/interface-ref.d.ts.map +1 -1
- package/dts/model-loader.d.ts +8 -8
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/prisma-field-builder.d.ts +18 -18
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +30 -30
- package/dts/types.d.ts.map +1 -1
- package/dts/util/map-query.d.ts +2 -2
- package/dts/util/map-query.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +6 -6
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/global-types.d.ts +13 -13
- package/esm/global-types.d.ts.map +1 -1
- package/esm/interface-ref.d.ts +1 -1
- package/esm/interface-ref.d.ts.map +1 -1
- package/esm/interface-ref.js.map +1 -1
- package/esm/model-loader.d.ts +8 -8
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js.map +1 -1
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/object-ref.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +28 -28
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/types.d.ts +30 -30
- package/esm/types.d.ts.map +1 -1
- package/esm/util/map-query.d.ts +2 -2
- package/esm/util/map-query.d.ts.map +1 -1
- package/esm/util/map-query.js +18 -6
- package/esm/util/map-query.js.map +1 -1
- package/lib/interface-ref.js.map +1 -1
- package/lib/model-loader.js.map +1 -1
- package/lib/object-ref.js.map +1 -1
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/util/map-query.js +17 -5
- package/lib/util/map-query.js.map +1 -1
- package/package.json +6 -6
- package/src/connection-helpers.ts +5 -5
- package/src/global-types.ts +11 -11
- package/src/index.ts +4 -4
- package/src/interface-ref.ts +3 -2
- package/src/model-loader.ts +17 -10
- package/src/object-ref.ts +2 -0
- package/src/prisma-field-builder.ts +42 -32
- package/src/types.ts +52 -50
- package/src/util/map-query.ts +31 -10
package/src/model-loader.ts
CHANGED
|
@@ -25,15 +25,22 @@ interface ResolvablePromise<T> {
|
|
|
25
25
|
}
|
|
26
26
|
export class ModelLoader {
|
|
27
27
|
context: object;
|
|
28
|
+
|
|
28
29
|
builder: PothosSchemaTypes.SchemaBuilder<never>;
|
|
30
|
+
|
|
29
31
|
findUnique: (model: Record<string, unknown>, ctx: {}) => unknown;
|
|
32
|
+
|
|
30
33
|
modelName: string;
|
|
34
|
+
|
|
31
35
|
queryCache = new Map<string, { selection: SelectionState; query: SelectionMap }>();
|
|
36
|
+
|
|
32
37
|
staged = new Set<{
|
|
33
38
|
state: SelectionState;
|
|
34
39
|
models: Map<object, ResolvablePromise<Record<string, unknown> | null>>;
|
|
35
40
|
}>();
|
|
41
|
+
|
|
36
42
|
delegate: PrismaDelegate;
|
|
43
|
+
|
|
37
44
|
tick = Promise.resolve();
|
|
38
45
|
|
|
39
46
|
constructor(
|
|
@@ -53,7 +60,7 @@ export class ModelLoader {
|
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
static forRef<Types extends SchemaTypes>(
|
|
56
|
-
ref:
|
|
63
|
+
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
57
64
|
modelName: string,
|
|
58
65
|
findUnique: ((model: Record<string, unknown>, ctx: {}) => unknown) | undefined,
|
|
59
66
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
@@ -75,11 +82,11 @@ export class ModelLoader {
|
|
|
75
82
|
|
|
76
83
|
static getFindUnique(
|
|
77
84
|
findBy:
|
|
85
|
+
| string
|
|
78
86
|
| {
|
|
79
87
|
name: string | null;
|
|
80
88
|
fields: string[];
|
|
81
|
-
}
|
|
82
|
-
| string,
|
|
89
|
+
},
|
|
83
90
|
): (model: Record<string, unknown>) => {} {
|
|
84
91
|
if (typeof findBy === 'string') {
|
|
85
92
|
return (parent) => ({ [findBy]: parent[findBy] });
|
|
@@ -99,7 +106,7 @@ export class ModelLoader {
|
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
static getDefaultFindBy<Types extends SchemaTypes>(
|
|
102
|
-
ref:
|
|
109
|
+
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
103
110
|
modelName: string,
|
|
104
111
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
105
112
|
) {
|
|
@@ -111,11 +118,11 @@ export class ModelLoader {
|
|
|
111
118
|
);
|
|
112
119
|
|
|
113
120
|
let findBy:
|
|
121
|
+
| string
|
|
114
122
|
| {
|
|
115
123
|
name: string | null;
|
|
116
124
|
fields: string[];
|
|
117
125
|
}
|
|
118
|
-
| string
|
|
119
126
|
| undefined;
|
|
120
127
|
|
|
121
128
|
if (model.primaryKey) {
|
|
@@ -136,7 +143,7 @@ export class ModelLoader {
|
|
|
136
143
|
}
|
|
137
144
|
|
|
138
145
|
static getDefaultFindUnique<Types extends SchemaTypes>(
|
|
139
|
-
ref:
|
|
146
|
+
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
140
147
|
modelName: string,
|
|
141
148
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
142
149
|
): (model: Record<string, unknown>) => {} {
|
|
@@ -146,7 +153,7 @@ export class ModelLoader {
|
|
|
146
153
|
}
|
|
147
154
|
|
|
148
155
|
static getDefaultIDSelection<Types extends SchemaTypes>(
|
|
149
|
-
ref:
|
|
156
|
+
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
150
157
|
modelName: string,
|
|
151
158
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
152
159
|
): Record<string, boolean> {
|
|
@@ -166,7 +173,7 @@ export class ModelLoader {
|
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
static getCursorSelection<Types extends SchemaTypes>(
|
|
169
|
-
ref:
|
|
176
|
+
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
170
177
|
modelName: string,
|
|
171
178
|
cursor: string,
|
|
172
179
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
@@ -195,7 +202,7 @@ export class ModelLoader {
|
|
|
195
202
|
}
|
|
196
203
|
|
|
197
204
|
static getFindUniqueForField<Types extends SchemaTypes>(
|
|
198
|
-
ref:
|
|
205
|
+
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
199
206
|
modelName: string,
|
|
200
207
|
fieldName: string,
|
|
201
208
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
@@ -207,11 +214,11 @@ export class ModelLoader {
|
|
|
207
214
|
);
|
|
208
215
|
|
|
209
216
|
let findBy:
|
|
217
|
+
| string
|
|
210
218
|
| {
|
|
211
219
|
name: string | null;
|
|
212
220
|
fields: string[];
|
|
213
221
|
}
|
|
214
|
-
| string
|
|
215
222
|
| undefined;
|
|
216
223
|
|
|
217
224
|
if (model.fields.some((field) => field.name === fieldName)) {
|
package/src/object-ref.ts
CHANGED
|
@@ -5,7 +5,9 @@ export const prismaModelKey = Symbol.for('Pothos.prismaModelKey');
|
|
|
5
5
|
|
|
6
6
|
export class PrismaObjectRef<Model extends PrismaModelTypes, T = {}> extends ObjectRef<T> {
|
|
7
7
|
[prismaModelKey]!: Model;
|
|
8
|
+
|
|
8
9
|
[abstractReturnShapeKey]!: WithBrand<T>;
|
|
10
|
+
|
|
9
11
|
modelName: string;
|
|
10
12
|
|
|
11
13
|
constructor(name: string, modelName: string) {
|
|
@@ -80,17 +80,27 @@ export class PrismaObjectFieldBuilder<
|
|
|
80
80
|
Shape extends object = Model['Shape'],
|
|
81
81
|
> extends RootBuilder<Types, Shape, 'PrismaObject'> {
|
|
82
82
|
model: string;
|
|
83
|
+
|
|
83
84
|
prismaFieldMap: FieldMap;
|
|
84
85
|
|
|
85
86
|
exposeBoolean = this.createExpose('Boolean');
|
|
87
|
+
|
|
86
88
|
exposeFloat = this.createExpose('Float');
|
|
89
|
+
|
|
87
90
|
exposeInt = this.createExpose('Int');
|
|
91
|
+
|
|
88
92
|
exposeID = this.createExpose('ID');
|
|
93
|
+
|
|
89
94
|
exposeString = this.createExpose('String');
|
|
95
|
+
|
|
90
96
|
exposeBooleanList = this.createExpose(['Boolean']);
|
|
97
|
+
|
|
91
98
|
exposeFloatList = this.createExpose(['Float']);
|
|
99
|
+
|
|
92
100
|
exposeIntList = this.createExpose(['Int']);
|
|
101
|
+
|
|
93
102
|
exposeIDList = this.createExpose(['ID']);
|
|
103
|
+
|
|
94
104
|
exposeStringList = this.createExpose(['String']);
|
|
95
105
|
|
|
96
106
|
withAuth: 'scopeAuth' extends PluginName
|
|
@@ -117,6 +127,9 @@ export class PrismaObjectFieldBuilder<
|
|
|
117
127
|
...args: NormalizeArgs<
|
|
118
128
|
[
|
|
119
129
|
connectionOptions:
|
|
130
|
+
| ObjectRef<
|
|
131
|
+
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, false>>
|
|
132
|
+
>
|
|
120
133
|
| PothosSchemaTypes.ConnectionObjectOptions<
|
|
121
134
|
Types,
|
|
122
135
|
ObjectRef<
|
|
@@ -139,11 +152,12 @@ export class PrismaObjectFieldBuilder<
|
|
|
139
152
|
Args
|
|
140
153
|
>,
|
|
141
154
|
ConnectionInterfaces
|
|
142
|
-
>
|
|
143
|
-
| ObjectRef<
|
|
144
|
-
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, false>>
|
|
145
155
|
>,
|
|
146
156
|
edgeOptions:
|
|
157
|
+
| ObjectRef<{
|
|
158
|
+
cursor: string;
|
|
159
|
+
node?: ShapeFromTypeParam<Types, Model['Shape'], false>;
|
|
160
|
+
}>
|
|
147
161
|
| PothosSchemaTypes.ConnectionEdgeObjectOptions<
|
|
148
162
|
Types,
|
|
149
163
|
ObjectRef<
|
|
@@ -165,11 +179,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
165
179
|
Args
|
|
166
180
|
>,
|
|
167
181
|
EdgeInterfaces
|
|
168
|
-
|
|
169
|
-
| ObjectRef<{
|
|
170
|
-
cursor: string;
|
|
171
|
-
node?: ShapeFromTypeParam<Types, Model['Shape'], false>;
|
|
172
|
-
}>,
|
|
182
|
+
>,
|
|
173
183
|
],
|
|
174
184
|
0
|
|
175
185
|
>
|
|
@@ -528,18 +538,18 @@ export class PrismaObjectFieldBuilder<
|
|
|
528
538
|
name: Name,
|
|
529
539
|
...args: NormalizeArgs<
|
|
530
540
|
[
|
|
531
|
-
options:
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
541
|
+
options: ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> &
|
|
542
|
+
Omit<
|
|
543
|
+
PothosSchemaTypes.ObjectFieldOptions<
|
|
544
|
+
Types,
|
|
545
|
+
Shape,
|
|
546
|
+
Type,
|
|
547
|
+
Nullable,
|
|
548
|
+
{},
|
|
549
|
+
ResolveReturnShape
|
|
550
|
+
>,
|
|
551
|
+
'description' | 'nullable' | 'resolve' | 'select'
|
|
552
|
+
> & {
|
|
543
553
|
description?: string | false;
|
|
544
554
|
},
|
|
545
555
|
]
|
|
@@ -577,18 +587,18 @@ export class PrismaObjectFieldBuilder<
|
|
|
577
587
|
name: Name,
|
|
578
588
|
...args: NormalizeArgs<
|
|
579
589
|
[
|
|
580
|
-
options:
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
590
|
+
options: ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> &
|
|
591
|
+
Omit<
|
|
592
|
+
PothosSchemaTypes.ObjectFieldOptions<
|
|
593
|
+
Types,
|
|
594
|
+
Shape,
|
|
595
|
+
Type,
|
|
596
|
+
Nullable,
|
|
597
|
+
{},
|
|
598
|
+
ResolveReturnShape
|
|
599
|
+
>,
|
|
600
|
+
'description' | 'nullable' | 'resolve' | 'select' | 'type'
|
|
601
|
+
> & {
|
|
592
602
|
description?: string | false;
|
|
593
603
|
},
|
|
594
604
|
]
|
package/src/types.ts
CHANGED
|
@@ -155,7 +155,7 @@ export type TypesForRelation<
|
|
|
155
155
|
Relation extends keyof Model['Relations'],
|
|
156
156
|
> = Model['Relations'][Relation]['Name'] extends infer Name
|
|
157
157
|
? Name extends keyof Types['PrismaTypes']
|
|
158
|
-
? Types['PrismaTypes'][Name]
|
|
158
|
+
? PrismaModelTypes & Types['PrismaTypes'][Name]
|
|
159
159
|
: never
|
|
160
160
|
: never;
|
|
161
161
|
|
|
@@ -205,7 +205,7 @@ export type PrismaObjectImplementationOptions<
|
|
|
205
205
|
> = Omit<
|
|
206
206
|
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
207
207
|
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
208
|
-
'
|
|
208
|
+
'description' | 'fields'
|
|
209
209
|
> & {
|
|
210
210
|
description?: string | false;
|
|
211
211
|
fields?: PrismaObjectFieldsShape<
|
|
@@ -225,8 +225,8 @@ export type PrismaObjectTypeOptions<
|
|
|
225
225
|
Include,
|
|
226
226
|
Select,
|
|
227
227
|
Shape extends object,
|
|
228
|
-
> =
|
|
229
|
-
|
|
228
|
+
> = PrismaObjectImplementationOptions<Types, Model, Interfaces, FindUnique, Select, Shape> &
|
|
229
|
+
PrismaObjectRefOptions<Types, Model, FindUnique, Include, Select, Shape>;
|
|
230
230
|
|
|
231
231
|
export type PrismaInterfaceRefOptions<
|
|
232
232
|
Types extends SchemaTypes,
|
|
@@ -259,7 +259,7 @@ export type PrismaInterfaceImplementationOptions<
|
|
|
259
259
|
Shape extends object,
|
|
260
260
|
> = Omit<
|
|
261
261
|
PothosSchemaTypes.InterfaceTypeOptions<Types, Shape, Interfaces>,
|
|
262
|
-
'
|
|
262
|
+
'description' | 'fields'
|
|
263
263
|
> & {
|
|
264
264
|
description?: string | false;
|
|
265
265
|
fields?: PrismaObjectFieldsShape<
|
|
@@ -279,8 +279,8 @@ export type PrismaInterfaceTypeOptions<
|
|
|
279
279
|
Include,
|
|
280
280
|
Select,
|
|
281
281
|
Shape extends object,
|
|
282
|
-
> =
|
|
283
|
-
|
|
282
|
+
> = PrismaInterfaceImplementationOptions<Types, Model, Interfaces, FindUnique, Select, Shape> &
|
|
283
|
+
PrismaInterfaceRefOptions<Types, Model, FindUnique, Include, Select, Shape>;
|
|
284
284
|
|
|
285
285
|
type NameOrVariant =
|
|
286
286
|
| {
|
|
@@ -305,7 +305,14 @@ export type PrismaNodeOptions<
|
|
|
305
305
|
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
306
306
|
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
307
307
|
'fields' | 'isTypeOf'
|
|
308
|
-
> &
|
|
308
|
+
> &
|
|
309
|
+
(UniqueField extends string
|
|
310
|
+
? {
|
|
311
|
+
findUnique?: (id: string, context: Types['Context']) => Model['WhereUnique'];
|
|
312
|
+
}
|
|
313
|
+
: {
|
|
314
|
+
findUnique: (id: string, context: Types['Context']) => Model['WhereUnique'];
|
|
315
|
+
}) & {
|
|
309
316
|
id: Omit<
|
|
310
317
|
FieldOptionsFromKind<
|
|
311
318
|
Types,
|
|
@@ -341,14 +348,9 @@ export type PrismaNodeOptions<
|
|
|
341
348
|
Shape & { [prismaModelName]?: Model['Name'] },
|
|
342
349
|
Select
|
|
343
350
|
>;
|
|
344
|
-
} &
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
: {
|
|
349
|
-
findUnique: (id: string, context: Types['Context']) => Model['WhereUnique'];
|
|
350
|
-
}) &
|
|
351
|
-
(
|
|
351
|
+
} & {
|
|
352
|
+
nullable?: boolean;
|
|
353
|
+
} & (
|
|
352
354
|
| {
|
|
353
355
|
include?: Include & Model['Include'];
|
|
354
356
|
select?: never;
|
|
@@ -357,9 +359,7 @@ export type PrismaNodeOptions<
|
|
|
357
359
|
select: Model['Select'] & Select;
|
|
358
360
|
include?: never;
|
|
359
361
|
}
|
|
360
|
-
)
|
|
361
|
-
nullable?: boolean;
|
|
362
|
-
};
|
|
362
|
+
);
|
|
363
363
|
|
|
364
364
|
type QueryForField<
|
|
365
365
|
Types extends SchemaTypes,
|
|
@@ -425,7 +425,7 @@ export type RelatedFieldOptions<
|
|
|
425
425
|
Args,
|
|
426
426
|
ResolveReturnShape
|
|
427
427
|
>,
|
|
428
|
-
'
|
|
428
|
+
'description' | 'resolve' | 'type'
|
|
429
429
|
> &
|
|
430
430
|
(NeedsResolve extends false
|
|
431
431
|
? {
|
|
@@ -569,11 +569,11 @@ export type PrismaFieldWithInputOptions<
|
|
|
569
569
|
Type,
|
|
570
570
|
Model,
|
|
571
571
|
Param,
|
|
572
|
-
{
|
|
572
|
+
Args & {
|
|
573
573
|
[K in InputName]: InputFieldRef<
|
|
574
574
|
InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
|
|
575
575
|
>;
|
|
576
|
-
}
|
|
576
|
+
},
|
|
577
577
|
Nullable,
|
|
578
578
|
ResolveShape,
|
|
579
579
|
ResolveReturnShape,
|
|
@@ -583,11 +583,11 @@ export type PrismaFieldWithInputOptions<
|
|
|
583
583
|
> &
|
|
584
584
|
PothosSchemaTypes.FieldWithInputBaseOptions<
|
|
585
585
|
Types,
|
|
586
|
-
{
|
|
586
|
+
Args & {
|
|
587
587
|
[K in InputName]: InputFieldRef<
|
|
588
588
|
InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
|
|
589
589
|
>;
|
|
590
|
-
}
|
|
590
|
+
},
|
|
591
591
|
Fields,
|
|
592
592
|
InputName,
|
|
593
593
|
ArgRequired
|
|
@@ -620,8 +620,8 @@ export type PrismaConnectionFieldOptions<
|
|
|
620
620
|
Types extends SchemaTypes,
|
|
621
621
|
ParentShape,
|
|
622
622
|
Type extends
|
|
623
|
-
| PrismaRef<PrismaModelTypes>
|
|
624
623
|
| PrismaInterfaceRef<PrismaModelTypes>
|
|
624
|
+
| PrismaRef<PrismaModelTypes>
|
|
625
625
|
| keyof Types['PrismaTypes'],
|
|
626
626
|
Model extends PrismaModelTypes,
|
|
627
627
|
Param extends OutputType<Types>,
|
|
@@ -629,32 +629,33 @@ export type PrismaConnectionFieldOptions<
|
|
|
629
629
|
Args extends InputFieldMap,
|
|
630
630
|
ResolveReturnShape,
|
|
631
631
|
Kind extends FieldKind,
|
|
632
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
632
633
|
> = Omit<
|
|
633
|
-
|
|
634
|
+
FieldOptionsFromKind<
|
|
634
635
|
Types,
|
|
635
636
|
ParentShape,
|
|
636
637
|
Param,
|
|
637
638
|
Nullable,
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
639
|
+
InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments> &
|
|
640
|
+
(InputFieldMap extends Args ? {} : Args),
|
|
641
|
+
Kind,
|
|
642
|
+
ParentShape,
|
|
641
643
|
ResolveReturnShape
|
|
642
644
|
>,
|
|
643
|
-
'resolve' | 'type'
|
|
645
|
+
'args' | 'resolve' | 'type'
|
|
644
646
|
> &
|
|
645
647
|
Omit<
|
|
646
|
-
|
|
648
|
+
PothosSchemaTypes.ConnectionFieldOptions<
|
|
647
649
|
Types,
|
|
648
650
|
ParentShape,
|
|
649
651
|
Param,
|
|
650
652
|
Nullable,
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
ParentShape,
|
|
653
|
+
false,
|
|
654
|
+
false,
|
|
655
|
+
Args,
|
|
655
656
|
ResolveReturnShape
|
|
656
657
|
>,
|
|
657
|
-
'
|
|
658
|
+
'resolve' | 'type'
|
|
658
659
|
> &
|
|
659
660
|
(InputShapeFromFields<Args> &
|
|
660
661
|
PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
|
|
@@ -695,17 +696,18 @@ export type RelatedConnectionOptions<
|
|
|
695
696
|
Nullable extends boolean,
|
|
696
697
|
Args extends InputFieldMap,
|
|
697
698
|
NeedsResolve extends boolean,
|
|
699
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
698
700
|
> = Omit<
|
|
699
701
|
PothosSchemaTypes.ObjectFieldOptions<
|
|
700
702
|
Types,
|
|
701
703
|
Model['Shape'],
|
|
702
704
|
ObjectRef<unknown>,
|
|
703
705
|
Nullable,
|
|
704
|
-
|
|
705
|
-
|
|
706
|
+
InputFieldsFromShape<PothosSchemaTypes.DefaultConnectionArguments> &
|
|
707
|
+
(InputFieldMap extends Args ? {} : Args),
|
|
706
708
|
unknown
|
|
707
709
|
>,
|
|
708
|
-
'
|
|
710
|
+
'args' | 'description' | 'resolve' | 'type'
|
|
709
711
|
> &
|
|
710
712
|
Omit<
|
|
711
713
|
PothosSchemaTypes.ConnectionFieldOptions<
|
|
@@ -722,15 +724,7 @@ export type RelatedConnectionOptions<
|
|
|
722
724
|
> &
|
|
723
725
|
(InputShapeFromFields<Args> &
|
|
724
726
|
PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
|
|
725
|
-
?
|
|
726
|
-
description?: string | false;
|
|
727
|
-
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
728
|
-
type?: PrismaRef<TypesForRelation<Types, Model, Field>>;
|
|
729
|
-
cursor: CursorFromRelation<Model, Field>;
|
|
730
|
-
defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
731
|
-
maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
732
|
-
totalCount?: NeedsResolve extends false ? boolean : false;
|
|
733
|
-
} & (NeedsResolve extends false
|
|
727
|
+
? (NeedsResolve extends false
|
|
734
728
|
? {
|
|
735
729
|
resolve?: (
|
|
736
730
|
query: {
|
|
@@ -770,7 +764,15 @@ export type RelatedConnectionOptions<
|
|
|
770
764
|
Nullable
|
|
771
765
|
>
|
|
772
766
|
>;
|
|
773
|
-
})
|
|
767
|
+
}) & {
|
|
768
|
+
description?: string | false;
|
|
769
|
+
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
770
|
+
type?: PrismaRef<TypesForRelation<Types, Model, Field>>;
|
|
771
|
+
cursor: CursorFromRelation<Model, Field>;
|
|
772
|
+
defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
773
|
+
maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
774
|
+
totalCount?: NeedsResolve extends false ? boolean : false;
|
|
775
|
+
}
|
|
774
776
|
: never);
|
|
775
777
|
|
|
776
778
|
export type WithBrand<T> = T & { [typeBrandKey]: string };
|
|
@@ -790,7 +792,7 @@ export type FieldSelection =
|
|
|
790
792
|
context: object,
|
|
791
793
|
mergeNestedSelection: (
|
|
792
794
|
selection: SelectionMap | boolean | ((args: object, context: object) => SelectionMap),
|
|
793
|
-
path?: string[]
|
|
795
|
+
path?: IndirectInclude | string[],
|
|
794
796
|
) => SelectionMap | boolean,
|
|
795
797
|
resolveSelection: (path: string[]) => FieldNode | null,
|
|
796
798
|
) => SelectionMap);
|
package/src/util/map-query.ts
CHANGED
|
@@ -4,12 +4,15 @@ import {
|
|
|
4
4
|
FieldNode,
|
|
5
5
|
FragmentDefinitionNode,
|
|
6
6
|
getArgumentValues,
|
|
7
|
+
getDirectiveValues,
|
|
7
8
|
getNamedType,
|
|
8
9
|
GraphQLField,
|
|
10
|
+
GraphQLIncludeDirective,
|
|
9
11
|
GraphQLInterfaceType,
|
|
10
12
|
GraphQLNamedType,
|
|
11
13
|
GraphQLObjectType,
|
|
12
14
|
GraphQLResolveInfo,
|
|
15
|
+
GraphQLSkipDirective,
|
|
13
16
|
InlineFragmentNode,
|
|
14
17
|
isInterfaceType,
|
|
15
18
|
isObjectType,
|
|
@@ -60,8 +63,8 @@ function addTypeSelectionsForField(
|
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
if (
|
|
63
|
-
(pothosPrismaIndirectInclude?.path && pothosPrismaIndirectInclude.path.length > 0) ||
|
|
64
|
-
(pothosPrismaIndirectInclude?.paths && pothosPrismaIndirectInclude.paths.length === 0)
|
|
66
|
+
(!!pothosPrismaIndirectInclude?.path && pothosPrismaIndirectInclude.path.length > 0) ||
|
|
67
|
+
(!!pothosPrismaIndirectInclude?.paths && pothosPrismaIndirectInclude.paths.length === 0)
|
|
65
68
|
) {
|
|
66
69
|
resolveIndirectIncludePaths(
|
|
67
70
|
type,
|
|
@@ -94,7 +97,7 @@ function addTypeSelectionsForField(
|
|
|
94
97
|
state.mode = 'include';
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
if (pothosPrismaInclude
|
|
100
|
+
if (pothosPrismaInclude ?? pothosPrismaSelect) {
|
|
98
101
|
mergeSelection(state, {
|
|
99
102
|
select: pothosPrismaSelect ? { ...pothosPrismaSelect } : undefined,
|
|
100
103
|
include: pothosPrismaInclude ? { ...pothosPrismaInclude } : undefined,
|
|
@@ -145,7 +148,11 @@ function resolveIndirectInclude(
|
|
|
145
148
|
for (const sel of selection.selectionSet.selections) {
|
|
146
149
|
switch (sel.kind) {
|
|
147
150
|
case Kind.FIELD:
|
|
148
|
-
if (
|
|
151
|
+
if (
|
|
152
|
+
!fieldSkipped(info, sel) &&
|
|
153
|
+
sel.name.value === include.name &&
|
|
154
|
+
(isObjectType(type) || isInterfaceType(type))
|
|
155
|
+
) {
|
|
149
156
|
const returnType = getNamedType(type.getFields()[sel.name.value].type);
|
|
150
157
|
|
|
151
158
|
resolveIndirectInclude(
|
|
@@ -198,7 +205,7 @@ function resolveIndirectInclude(
|
|
|
198
205
|
}
|
|
199
206
|
|
|
200
207
|
function addNestedSelections(
|
|
201
|
-
type:
|
|
208
|
+
type: GraphQLInterfaceType | GraphQLObjectType,
|
|
202
209
|
context: object,
|
|
203
210
|
info: GraphQLResolveInfo,
|
|
204
211
|
state: SelectionState,
|
|
@@ -260,14 +267,14 @@ function addNestedSelections(
|
|
|
260
267
|
}
|
|
261
268
|
|
|
262
269
|
function addFieldSelection(
|
|
263
|
-
type:
|
|
270
|
+
type: GraphQLInterfaceType | GraphQLObjectType,
|
|
264
271
|
context: object,
|
|
265
272
|
info: GraphQLResolveInfo,
|
|
266
273
|
state: SelectionState,
|
|
267
274
|
selection: FieldNode,
|
|
268
275
|
indirectPath: string[],
|
|
269
276
|
) {
|
|
270
|
-
if (selection.name.value.startsWith('__')) {
|
|
277
|
+
if (selection.name.value.startsWith('__') || fieldSkipped(info, selection)) {
|
|
271
278
|
return;
|
|
272
279
|
}
|
|
273
280
|
|
|
@@ -316,8 +323,8 @@ function addFieldSelection(
|
|
|
316
323
|
}
|
|
317
324
|
|
|
318
325
|
if (
|
|
319
|
-
(normalizedIndirectInclude?.path && normalizedIndirectInclude.path.length > 0) ||
|
|
320
|
-
(normalizedIndirectInclude?.paths && normalizedIndirectInclude.paths.length > 0)
|
|
326
|
+
(!!normalizedIndirectInclude?.path && normalizedIndirectInclude.path.length > 0) ||
|
|
327
|
+
(!!normalizedIndirectInclude?.paths && normalizedIndirectInclude.paths.length > 0)
|
|
321
328
|
) {
|
|
322
329
|
resolveIndirectIncludePaths(
|
|
323
330
|
returnType,
|
|
@@ -397,7 +404,7 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
|
|
|
397
404
|
path?: string[];
|
|
398
405
|
paths?: string[][];
|
|
399
406
|
withUsageCheck?: boolean;
|
|
400
|
-
}): {
|
|
407
|
+
}): { include?: {} } | { select: T } {
|
|
401
408
|
const returnType = getNamedType(info.returnType);
|
|
402
409
|
const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
|
|
403
410
|
|
|
@@ -547,3 +554,17 @@ function normalizeInclude(path: string[], type: GraphQLNamedType): IndirectInclu
|
|
|
547
554
|
path: normalized,
|
|
548
555
|
};
|
|
549
556
|
}
|
|
557
|
+
|
|
558
|
+
function fieldSkipped(info: GraphQLResolveInfo, selection: FieldNode) {
|
|
559
|
+
const skip = getDirectiveValues(GraphQLSkipDirective, selection, info.variableValues);
|
|
560
|
+
if (skip?.if === true) {
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const include = getDirectiveValues(GraphQLIncludeDirective, selection, info.variableValues);
|
|
565
|
+
if (include?.if === false) {
|
|
566
|
+
return true;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
return false;
|
|
570
|
+
}
|