@pothos/plugin-prisma 3.51.1 → 3.53.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 +12 -0
- package/dts/global-types.d.ts.map +1 -1
- package/dts/prisma-field-builder.d.ts +25 -23
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +5 -1
- package/dts/types.d.ts.map +1 -1
- package/dts/util/map-query.d.ts +2 -1
- package/dts/util/map-query.d.ts.map +1 -1
- package/esm/connection-helpers.js +2 -1
- package/esm/connection-helpers.js.map +1 -1
- package/esm/field-builder.js +14 -9
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +2 -2
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/model-loader.js +10 -12
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.js.map +1 -1
- package/esm/object-ref.js +4 -4
- package/esm/object-ref.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +85 -43
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +36 -27
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/schema-builder.js +1 -1
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +5 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/util/cursors.js +2 -2
- package/esm/util/cursors.js.map +1 -1
- package/esm/util/datamodel.js.map +1 -1
- package/esm/util/deep-equal.js +2 -1
- package/esm/util/deep-equal.js.map +1 -1
- package/esm/util/description.js +4 -2
- 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 +2 -1
- package/esm/util/map-query.d.ts.map +1 -1
- package/esm/util/map-query.js +35 -13
- package/esm/util/map-query.js.map +1 -1
- package/esm/util/relation-map.js.map +1 -1
- package/esm/util/selections.js.map +1 -1
- package/lib/connection-helpers.js +13 -8
- package/lib/connection-helpers.js.map +1 -1
- package/lib/field-builder.js +23 -18
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +11 -11
- package/lib/generator.js.map +1 -1
- package/lib/index.js +58 -34
- package/lib/index.js.map +1 -1
- package/lib/model-loader.js +14 -14
- package/lib/model-loader.js.map +1 -1
- package/lib/node-ref.js +5 -3
- package/lib/node-ref.js.map +1 -1
- package/lib/object-ref.js +10 -6
- package/lib/object-ref.js.map +1 -1
- package/lib/prisma-field-builder.js +48 -37
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +25 -25
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js +3 -1
- package/lib/types.js.map +1 -1
- package/lib/util/cursors.js +46 -18
- package/lib/util/cursors.js.map +1 -1
- package/lib/util/datamodel.js +28 -12
- package/lib/util/datamodel.js.map +1 -1
- package/lib/util/deep-equal.js +6 -3
- package/lib/util/deep-equal.js.map +1 -1
- package/lib/util/description.js +12 -6
- package/lib/util/description.js.map +1 -1
- package/lib/util/get-client.js +6 -2
- package/lib/util/get-client.js.map +1 -1
- package/lib/util/loader-map.js +9 -3
- package/lib/util/loader-map.js.map +1 -1
- package/lib/util/map-query.js +48 -21
- package/lib/util/map-query.js.map +1 -1
- package/lib/util/relation-map.js +7 -3
- package/lib/util/relation-map.js.map +1 -1
- package/lib/util/selections.js +24 -12
- package/lib/util/selections.js.map +1 -1
- package/package.json +9 -9
- package/src/field-builder.ts +1 -1
- package/src/generator.ts +2 -3
- package/src/global-types.ts +0 -2
- package/src/prisma-field-builder.ts +29 -19
- package/src/types.ts +2 -1
- package/src/util/map-query.ts +42 -14
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { FieldNode, GraphQLResolveInfo } from 'graphql';
|
|
4
4
|
import {
|
|
5
5
|
CompatibleTypes,
|
|
6
|
+
ExposeNullability,
|
|
6
7
|
FieldKind,
|
|
7
8
|
FieldRef,
|
|
8
9
|
InputFieldMap,
|
|
@@ -261,7 +262,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
261
262
|
}
|
|
262
263
|
return typeName;
|
|
263
264
|
},
|
|
264
|
-
|
|
265
|
+
paths: [[{ name: 'nodes' }], [{ name: 'edges' }, { name: 'node' }]],
|
|
265
266
|
}) as SelectionMap;
|
|
266
267
|
|
|
267
268
|
const hasTotalCount = totalCount && !!getSelection(['totalCount']);
|
|
@@ -525,7 +526,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
525
526
|
Type extends TypeParam<Types>,
|
|
526
527
|
Nullable extends boolean,
|
|
527
528
|
ResolveReturnShape,
|
|
528
|
-
Name extends CompatibleTypes<Types, Model['Shape'], Type,
|
|
529
|
+
Name extends CompatibleTypes<Types, Model['Shape'], Type, true>,
|
|
529
530
|
>(
|
|
530
531
|
...args: NormalizeArgs<
|
|
531
532
|
[
|
|
@@ -539,8 +540,11 @@ export class PrismaObjectFieldBuilder<
|
|
|
539
540
|
{},
|
|
540
541
|
ResolveReturnShape
|
|
541
542
|
>,
|
|
542
|
-
'resolve' | 'select'
|
|
543
|
-
|
|
543
|
+
'resolve' | 'select' | 'description' | 'nullable'
|
|
544
|
+
> &
|
|
545
|
+
ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> & {
|
|
546
|
+
description?: string | false;
|
|
547
|
+
},
|
|
544
548
|
]
|
|
545
549
|
>
|
|
546
550
|
) {
|
|
@@ -549,13 +553,19 @@ export class PrismaObjectFieldBuilder<
|
|
|
549
553
|
const typeConfig = this.builder.configStore.getTypeConfig(this.typename, 'Object');
|
|
550
554
|
const usingSelect = !!typeConfig.extensions?.pothosPrismaSelect;
|
|
551
555
|
|
|
552
|
-
return this.exposeField(name as never, {
|
|
556
|
+
return this.exposeField<Type, Nullable, never>(name as never, {
|
|
553
557
|
...options,
|
|
558
|
+
description: getFieldDescription(
|
|
559
|
+
this.model,
|
|
560
|
+
this.builder,
|
|
561
|
+
name as string,
|
|
562
|
+
options.description,
|
|
563
|
+
) as never,
|
|
554
564
|
extensions: {
|
|
555
565
|
...options.extensions,
|
|
556
566
|
pothosPrismaVariant: name,
|
|
557
567
|
pothosPrismaSelect: usingSelect && {
|
|
558
|
-
[name]: true,
|
|
568
|
+
[name as string]: true,
|
|
559
569
|
},
|
|
560
570
|
},
|
|
561
571
|
});
|
|
@@ -565,7 +575,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
565
575
|
return <
|
|
566
576
|
Nullable extends boolean,
|
|
567
577
|
ResolveReturnShape,
|
|
568
|
-
Name extends CompatibleTypes<Types, Model['Shape'], Type,
|
|
578
|
+
Name extends CompatibleTypes<Types, Model['Shape'], Type, true>,
|
|
569
579
|
>(
|
|
570
580
|
...args: NormalizeArgs<
|
|
571
581
|
[
|
|
@@ -579,23 +589,23 @@ export class PrismaObjectFieldBuilder<
|
|
|
579
589
|
{},
|
|
580
590
|
ResolveReturnShape
|
|
581
591
|
>,
|
|
582
|
-
'resolve' | 'type' | 'select' | 'description'
|
|
583
|
-
> &
|
|
592
|
+
'resolve' | 'type' | 'select' | 'description' | 'nullable'
|
|
593
|
+
> &
|
|
594
|
+
ExposeNullability<Types, Type, Model['Shape'], Name, Nullable> & {
|
|
595
|
+
description?: string | false;
|
|
596
|
+
},
|
|
584
597
|
]
|
|
585
598
|
>
|
|
586
599
|
): FieldRef<ShapeFromTypeParam<Types, Type, Nullable>, 'PrismaObject'> => {
|
|
587
600
|
const [name, { description, ...options } = {} as never] = args;
|
|
588
601
|
|
|
589
|
-
return this.expose
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
) as never,
|
|
597
|
-
type,
|
|
598
|
-
});
|
|
602
|
+
return this.expose<Type, Nullable, ResolveReturnShape, never>(
|
|
603
|
+
name as never,
|
|
604
|
+
{
|
|
605
|
+
...options,
|
|
606
|
+
type,
|
|
607
|
+
} as never,
|
|
608
|
+
);
|
|
599
609
|
};
|
|
600
610
|
}
|
|
601
611
|
}
|
package/src/types.ts
CHANGED
|
@@ -747,7 +747,8 @@ export type LoaderMappings = Record<
|
|
|
747
747
|
|
|
748
748
|
export interface IndirectInclude {
|
|
749
749
|
getType: () => string;
|
|
750
|
-
path
|
|
750
|
+
path?: { type?: string; name: string }[];
|
|
751
|
+
paths?: { type?: string; name: string }[][];
|
|
751
752
|
}
|
|
752
753
|
|
|
753
754
|
export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
|
package/src/util/map-query.ts
CHANGED
|
@@ -56,12 +56,16 @@ function addTypeSelectionsForField(
|
|
|
56
56
|
pothosPrismaIndirectInclude?: IndirectInclude;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
if (
|
|
60
|
-
|
|
59
|
+
if (
|
|
60
|
+
(pothosPrismaIndirectInclude?.path && pothosPrismaIndirectInclude.path.length > 0) ||
|
|
61
|
+
(pothosPrismaIndirectInclude?.paths && pothosPrismaIndirectInclude.paths.length === 0)
|
|
62
|
+
) {
|
|
63
|
+
resolveIndirectIncludePaths(
|
|
61
64
|
type,
|
|
62
65
|
info,
|
|
63
66
|
selection,
|
|
64
|
-
|
|
67
|
+
[],
|
|
68
|
+
pothosPrismaIndirectInclude.paths ?? [pothosPrismaIndirectInclude.path!],
|
|
65
69
|
indirectPath,
|
|
66
70
|
(resolvedType, field, path) => {
|
|
67
71
|
addTypeSelectionsForField(resolvedType, context, info, state, field, path);
|
|
@@ -99,11 +103,29 @@ function addTypeSelectionsForField(
|
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
105
|
|
|
106
|
+
function resolveIndirectIncludePaths(
|
|
107
|
+
type: GraphQLNamedType,
|
|
108
|
+
info: GraphQLResolveInfo,
|
|
109
|
+
selection: FieldNode | FragmentDefinitionNode | InlineFragmentNode,
|
|
110
|
+
pathPrefix: { type?: string; name: string }[],
|
|
111
|
+
includePaths: { type?: string; name: string }[][],
|
|
112
|
+
path: string[],
|
|
113
|
+
resolve: (type: GraphQLNamedType, field: FieldNode, path: string[]) => void,
|
|
114
|
+
) {
|
|
115
|
+
for (const includePath of includePaths) {
|
|
116
|
+
if (pathPrefix.length > 0) {
|
|
117
|
+
resolveIndirectInclude(type, info, selection, [...pathPrefix, ...includePath], path, resolve);
|
|
118
|
+
} else {
|
|
119
|
+
resolveIndirectInclude(type, info, selection, includePath, path, resolve);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
102
124
|
function resolveIndirectInclude(
|
|
103
125
|
type: GraphQLNamedType,
|
|
104
126
|
info: GraphQLResolveInfo,
|
|
105
127
|
selection: FieldNode | FragmentDefinitionNode | InlineFragmentNode,
|
|
106
|
-
includePath:
|
|
128
|
+
includePath: { type?: string; name: string }[],
|
|
107
129
|
path: string[],
|
|
108
130
|
resolve: (type: GraphQLNamedType, field: FieldNode, path: string[]) => void,
|
|
109
131
|
) {
|
|
@@ -275,15 +297,16 @@ function addFieldSelection(
|
|
|
275
297
|
mergeSelection(fieldState, { select: {}, ...query });
|
|
276
298
|
}
|
|
277
299
|
|
|
278
|
-
if (
|
|
279
|
-
|
|
300
|
+
if (
|
|
301
|
+
(normalizedIndirectInclude?.path && normalizedIndirectInclude.path.length > 0) ||
|
|
302
|
+
(normalizedIndirectInclude?.paths && normalizedIndirectInclude.paths.length > 0)
|
|
303
|
+
) {
|
|
304
|
+
resolveIndirectIncludePaths(
|
|
280
305
|
returnType,
|
|
281
306
|
info,
|
|
282
307
|
selection,
|
|
283
|
-
[
|
|
284
|
-
|
|
285
|
-
...normalizedIndirectInclude.path,
|
|
286
|
-
],
|
|
308
|
+
(returnType.extensions?.pothosPrismaIndirectInclude as { path: [] })?.path ?? [],
|
|
309
|
+
normalizedIndirectInclude.paths ?? [normalizedIndirectInclude.path!],
|
|
287
310
|
[],
|
|
288
311
|
(resolvedType, resolvedField, path) => {
|
|
289
312
|
addTypeSelectionsForField(
|
|
@@ -346,12 +369,14 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
|
|
|
346
369
|
typeName,
|
|
347
370
|
select,
|
|
348
371
|
path = [],
|
|
372
|
+
paths = [],
|
|
349
373
|
}: {
|
|
350
374
|
context: object;
|
|
351
375
|
info: GraphQLResolveInfo;
|
|
352
376
|
typeName?: string;
|
|
353
377
|
select?: T;
|
|
354
378
|
path?: string[];
|
|
379
|
+
paths?: string[][];
|
|
355
380
|
}): { select: T } | { include?: {} } {
|
|
356
381
|
const returnType = getNamedType(info.returnType);
|
|
357
382
|
const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
|
|
@@ -359,7 +384,7 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
|
|
|
359
384
|
let state: SelectionState | undefined;
|
|
360
385
|
const initialSelection = select ? { select } : undefined;
|
|
361
386
|
|
|
362
|
-
if (path.length > 0) {
|
|
387
|
+
if (path.length > 0 || paths.length > 0) {
|
|
363
388
|
const { pothosPrismaIndirectInclude } = (returnType.extensions ?? {}) as {
|
|
364
389
|
pothosPrismaIndirectInclude?: IndirectInclude;
|
|
365
390
|
};
|
|
@@ -371,11 +396,14 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
|
|
|
371
396
|
pothosPrismaIndirectInclude?.path ?? [],
|
|
372
397
|
[],
|
|
373
398
|
(indirectType, indirectField, subPath) => {
|
|
374
|
-
|
|
399
|
+
resolveIndirectIncludePaths(
|
|
375
400
|
indirectType,
|
|
376
401
|
info,
|
|
377
402
|
indirectField,
|
|
378
|
-
|
|
403
|
+
[],
|
|
404
|
+
paths.length > 0
|
|
405
|
+
? paths.map((p) => p.map((n) => (typeof n === 'string' ? { name: n } : n)))
|
|
406
|
+
: [path.map((n) => (typeof n === 'string' ? { name: n } : n))],
|
|
379
407
|
subPath,
|
|
380
408
|
(resolvedType, resolvedField, nested) => {
|
|
381
409
|
state = createStateForType(
|
|
@@ -465,7 +493,7 @@ export function getIndirectType(type: GraphQLNamedType, info: GraphQLResolveInfo
|
|
|
465
493
|
return targetType;
|
|
466
494
|
}
|
|
467
495
|
|
|
468
|
-
function normalizeInclude(path: string[], type: GraphQLNamedType) {
|
|
496
|
+
function normalizeInclude(path: string[], type: GraphQLNamedType): IndirectInclude {
|
|
469
497
|
let currentType = type;
|
|
470
498
|
|
|
471
499
|
const normalized: { name: string; type: string }[] = [];
|