@pothos/plugin-prisma 3.47.3 → 3.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dts/connection-helpers.d.ts +1 -1
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/global-types.d.ts +3 -3
- package/dts/global-types.d.ts.map +1 -1
- package/dts/prisma-field-builder.d.ts +12 -4
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +10 -0
- package/dts/types.d.ts.map +1 -1
- package/dts/util/cursors.d.ts +12 -13
- package/dts/util/cursors.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +1 -1
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/connection-helpers.js +2 -2
- package/esm/connection-helpers.js.map +1 -1
- package/esm/field-builder.js +1 -0
- package/esm/field-builder.js.map +1 -1
- package/esm/global-types.d.ts +3 -3
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +12 -4
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +2 -2
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/types.d.ts +14 -0
- package/esm/types.d.ts.map +1 -1
- package/esm/util/cursors.d.ts +12 -13
- package/esm/util/cursors.d.ts.map +1 -1
- package/esm/util/cursors.js +22 -12
- package/esm/util/cursors.js.map +1 -1
- package/lib/connection-helpers.js +2 -2
- package/lib/connection-helpers.js.map +1 -1
- package/lib/field-builder.js +1 -0
- package/lib/field-builder.js.map +1 -1
- package/lib/prisma-field-builder.js +2 -2
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/util/cursors.js +22 -12
- package/lib/util/cursors.js.map +1 -1
- package/package.json +2 -2
- package/src/connection-helpers.ts +3 -1
- package/src/field-builder.ts +1 -0
- package/src/global-types.ts +5 -2
- package/src/prisma-field-builder.ts +37 -6
- package/src/types.ts +18 -0
- package/src/util/cursors.ts +30 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pothos/plugin-prisma",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.48.0",
|
|
4
4
|
"description": "A Pothos plugin for more efficient integration with prisma",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./dts/index.d.ts",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@pothos/core": "3.30.0",
|
|
73
73
|
"@pothos/plugin-complexity": "3.12.1",
|
|
74
74
|
"@pothos/plugin-errors": "3.11.1",
|
|
75
|
-
"@pothos/plugin-relay": "3.
|
|
75
|
+
"@pothos/plugin-relay": "3.42.0",
|
|
76
76
|
"@pothos/plugin-simple-objects": "3.6.8",
|
|
77
77
|
"@pothos/test-utils": "1.4.8"
|
|
78
78
|
},
|
|
@@ -51,12 +51,14 @@ export function prismaConnectionHelpers<
|
|
|
51
51
|
const cursorSelection = ModelLoader.getCursorSelection(ref, modelName, options.cursor, builder);
|
|
52
52
|
const fieldMap = getRelationMap(getDMMF(builder)).get(modelName)!;
|
|
53
53
|
|
|
54
|
-
function resolve(
|
|
54
|
+
function resolve<Parent = unknown>(
|
|
55
55
|
list: (EdgeShape & {})[],
|
|
56
56
|
args: PothosSchemaTypes.DefaultConnectionArguments,
|
|
57
57
|
ctx: Types['Context'],
|
|
58
|
+
parent?: Parent,
|
|
58
59
|
) {
|
|
59
60
|
return wrapConnectionResult(
|
|
61
|
+
parent,
|
|
60
62
|
list,
|
|
61
63
|
args,
|
|
62
64
|
getQueryArgs(args, ctx).take,
|
package/src/field-builder.ts
CHANGED
package/src/global-types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
3
|
+
import { A } from 'vitest/dist/types-fafda418';
|
|
3
4
|
import {
|
|
4
5
|
FieldKind,
|
|
5
6
|
FieldMap,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
FieldRef,
|
|
8
9
|
InputFieldMap,
|
|
9
10
|
InputFieldRef,
|
|
11
|
+
InputShapeFromFields,
|
|
10
12
|
InterfaceParam,
|
|
11
13
|
NormalizeArgs,
|
|
12
14
|
OutputType,
|
|
@@ -21,6 +23,7 @@ import { PrismaObjectFieldBuilder as InternalPrismaObjectFieldBuilder } from './
|
|
|
21
23
|
import {
|
|
22
24
|
PrismaClient,
|
|
23
25
|
PrismaConnectionFieldOptions,
|
|
26
|
+
PrismaConnectionShape,
|
|
24
27
|
PrismaFieldOptions,
|
|
25
28
|
PrismaFieldWithInputOptions,
|
|
26
29
|
prismaModelName,
|
|
@@ -260,7 +263,7 @@ declare global {
|
|
|
260
263
|
ObjectRef<Shape>,
|
|
261
264
|
false,
|
|
262
265
|
false,
|
|
263
|
-
|
|
266
|
+
PrismaConnectionShape<Types, Shape, ParentShape, Args>,
|
|
264
267
|
ConnectionInterfaces
|
|
265
268
|
>
|
|
266
269
|
| ObjectRef<ShapeFromConnection<ConnectionShapeHelper<Types, Shape, false>>>,
|
|
@@ -269,7 +272,7 @@ declare global {
|
|
|
269
272
|
Types,
|
|
270
273
|
ObjectRef<Shape>,
|
|
271
274
|
false,
|
|
272
|
-
|
|
275
|
+
PrismaConnectionShape<Types, Shape, ParentShape, Args>,
|
|
273
276
|
EdgeInterfaces
|
|
274
277
|
>
|
|
275
278
|
| ObjectRef<{
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import { ModelLoader } from './model-loader';
|
|
21
21
|
import { PrismaObjectRef } from './object-ref';
|
|
22
22
|
import {
|
|
23
|
+
PrismaConnectionShape,
|
|
23
24
|
PrismaModelTypes,
|
|
24
25
|
RelatedConnectionOptions,
|
|
25
26
|
RelatedFieldOptions,
|
|
@@ -107,7 +108,6 @@ export class PrismaObjectFieldBuilder<
|
|
|
107
108
|
Field extends Model['ListRelations'],
|
|
108
109
|
Nullable extends boolean,
|
|
109
110
|
Args extends InputFieldMap,
|
|
110
|
-
ResolveReturnShape,
|
|
111
111
|
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
|
|
112
112
|
EdgeInterfaces extends InterfaceParam<Types>[] = [],
|
|
113
113
|
>(
|
|
@@ -118,10 +118,25 @@ export class PrismaObjectFieldBuilder<
|
|
|
118
118
|
connectionOptions:
|
|
119
119
|
| PothosSchemaTypes.ConnectionObjectOptions<
|
|
120
120
|
Types,
|
|
121
|
-
ObjectRef<
|
|
121
|
+
ObjectRef<
|
|
122
|
+
ShapeFromTypeParam<
|
|
123
|
+
Types,
|
|
124
|
+
[ObjectRef<Model['Relations'][Field & keyof Model['Relations']]['Shape']>],
|
|
125
|
+
Nullable
|
|
126
|
+
>
|
|
127
|
+
>,
|
|
122
128
|
false,
|
|
123
129
|
false,
|
|
124
|
-
|
|
130
|
+
PrismaConnectionShape<
|
|
131
|
+
Types,
|
|
132
|
+
ShapeFromTypeParam<
|
|
133
|
+
Types,
|
|
134
|
+
[ObjectRef<Model['Relations'][Field & keyof Model['Relations']]['Shape']>],
|
|
135
|
+
Nullable
|
|
136
|
+
>,
|
|
137
|
+
Shape,
|
|
138
|
+
Args
|
|
139
|
+
>,
|
|
125
140
|
ConnectionInterfaces
|
|
126
141
|
>
|
|
127
142
|
| ObjectRef<
|
|
@@ -130,9 +145,24 @@ export class PrismaObjectFieldBuilder<
|
|
|
130
145
|
edgeOptions:
|
|
131
146
|
| PothosSchemaTypes.ConnectionEdgeObjectOptions<
|
|
132
147
|
Types,
|
|
133
|
-
ObjectRef<
|
|
148
|
+
ObjectRef<
|
|
149
|
+
ShapeFromTypeParam<
|
|
150
|
+
Types,
|
|
151
|
+
[ObjectRef<Model['Relations'][Field & keyof Model['Relations']]['Shape']>],
|
|
152
|
+
Nullable
|
|
153
|
+
>
|
|
154
|
+
>,
|
|
134
155
|
false,
|
|
135
|
-
|
|
156
|
+
PrismaConnectionShape<
|
|
157
|
+
Types,
|
|
158
|
+
ShapeFromTypeParam<
|
|
159
|
+
Types,
|
|
160
|
+
[ObjectRef<Model['Relations'][Field & keyof Model['Relations']]['Shape']>],
|
|
161
|
+
Nullable
|
|
162
|
+
>,
|
|
163
|
+
Shape,
|
|
164
|
+
Args
|
|
165
|
+
>,
|
|
136
166
|
EdgeInterfaces
|
|
137
167
|
>
|
|
138
168
|
| ObjectRef<{
|
|
@@ -289,7 +319,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
289
319
|
context,
|
|
290
320
|
info,
|
|
291
321
|
),
|
|
292
|
-
).then((result) => wrapConnectionResult(result, args, q.take, formatCursor))),
|
|
322
|
+
).then((result) => wrapConnectionResult(parent, result, args, q.take, formatCursor))),
|
|
293
323
|
},
|
|
294
324
|
type: ref,
|
|
295
325
|
resolve: (
|
|
@@ -300,6 +330,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
300
330
|
const connectionQuery = getQuery(args, context);
|
|
301
331
|
|
|
302
332
|
return wrapConnectionResult(
|
|
333
|
+
parent,
|
|
303
334
|
(parent as Record<string, never>)[name],
|
|
304
335
|
args,
|
|
305
336
|
connectionQuery.take,
|
package/src/types.ts
CHANGED
|
@@ -752,6 +752,24 @@ export interface IndirectInclude {
|
|
|
752
752
|
|
|
753
753
|
export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
|
|
754
754
|
|
|
755
|
+
export type PrismaConnectionShape<
|
|
756
|
+
Types extends SchemaTypes,
|
|
757
|
+
T,
|
|
758
|
+
Parent,
|
|
759
|
+
Args extends InputFieldMap,
|
|
760
|
+
> = (
|
|
761
|
+
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, T, false>> extends infer Shape
|
|
762
|
+
? Shape & {
|
|
763
|
+
parent: Parent;
|
|
764
|
+
args: InputShapeFromFields<Args> & PothosSchemaTypes.DefaultConnectionArguments;
|
|
765
|
+
}
|
|
766
|
+
: never
|
|
767
|
+
) extends infer C
|
|
768
|
+
? [C] extends [{ edges: MaybePromise<readonly (infer Edge)[]> }]
|
|
769
|
+
? Omit<C, 'edges'> & { edges: MaybePromise<(Edge & { connection: C })[]> }
|
|
770
|
+
: C
|
|
771
|
+
: never;
|
|
772
|
+
|
|
755
773
|
export type UniqueFieldsExtendedWhereUnique<T> = NonNullable<
|
|
756
774
|
T extends infer O
|
|
757
775
|
? {
|
package/src/util/cursors.ts
CHANGED
|
@@ -215,6 +215,7 @@ export interface PrismaCursorConnectionQueryOptions {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
interface ResolvePrismaCursorConnectionOptions extends PrismaCursorConnectionQueryOptions {
|
|
218
|
+
parent?: unknown;
|
|
218
219
|
query: {};
|
|
219
220
|
totalCount?: number | (() => MaybePromise<number>);
|
|
220
221
|
}
|
|
@@ -275,6 +276,7 @@ export function prismaCursorConnectionQuery({
|
|
|
275
276
|
}
|
|
276
277
|
|
|
277
278
|
export function wrapConnectionResult<T extends {}>(
|
|
279
|
+
parent: unknown,
|
|
278
280
|
results: readonly T[],
|
|
279
281
|
args: PothosSchemaTypes.DefaultConnectionArguments,
|
|
280
282
|
take: number,
|
|
@@ -289,31 +291,41 @@ export function wrapConnectionResult<T extends {}>(
|
|
|
289
291
|
? results.slice(take < 0 ? 1 : 0, take < 0 ? results.length : -1)
|
|
290
292
|
: results;
|
|
291
293
|
|
|
294
|
+
const connection = {
|
|
295
|
+
parent,
|
|
296
|
+
args,
|
|
297
|
+
totalCount,
|
|
298
|
+
edges: [] as ({ cursor: string; node: unknown } | null)[],
|
|
299
|
+
pageInfo: {
|
|
300
|
+
startCursor: null as string | null,
|
|
301
|
+
endCursor: null as string | null,
|
|
302
|
+
hasPreviousPage,
|
|
303
|
+
hasNextPage,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
|
|
292
307
|
const edges = nodes.map((value, index) =>
|
|
293
308
|
value == null
|
|
294
309
|
? null
|
|
295
310
|
: resolveNode
|
|
296
311
|
? {
|
|
312
|
+
connection,
|
|
297
313
|
...value,
|
|
298
314
|
cursor: cursor(value),
|
|
299
315
|
node: resolveNode(value),
|
|
300
316
|
}
|
|
301
317
|
: {
|
|
318
|
+
connection,
|
|
302
319
|
cursor: cursor(value),
|
|
303
320
|
node: value,
|
|
304
321
|
},
|
|
305
322
|
);
|
|
306
323
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
endCursor: edges[edges.length - 1]?.cursor,
|
|
313
|
-
hasPreviousPage,
|
|
314
|
-
hasNextPage,
|
|
315
|
-
},
|
|
316
|
-
};
|
|
324
|
+
connection.edges = edges;
|
|
325
|
+
connection.pageInfo.startCursor = edges[0]?.cursor ?? null;
|
|
326
|
+
connection.pageInfo.endCursor = edges[edges.length - 1]?.cursor ?? null;
|
|
327
|
+
|
|
328
|
+
return connection;
|
|
317
329
|
}
|
|
318
330
|
|
|
319
331
|
export async function resolvePrismaCursorConnection<T extends {}>(
|
|
@@ -336,7 +348,14 @@ export async function resolvePrismaCursorConnection<T extends {}>(
|
|
|
336
348
|
return results;
|
|
337
349
|
}
|
|
338
350
|
|
|
339
|
-
return wrapConnectionResult(
|
|
351
|
+
return wrapConnectionResult(
|
|
352
|
+
options.parent,
|
|
353
|
+
results,
|
|
354
|
+
options.args,
|
|
355
|
+
query.take,
|
|
356
|
+
cursor,
|
|
357
|
+
options.totalCount,
|
|
358
|
+
);
|
|
340
359
|
}
|
|
341
360
|
|
|
342
361
|
export function getCursorFormatter<Types extends SchemaTypes>(
|