@pothos/plugin-prisma 3.63.1 → 3.65.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 +15 -0
- package/README.md +150 -31
- package/dts/connection-helpers.d.ts +1 -1
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/global-types.d.ts +4 -0
- package/dts/global-types.d.ts.map +1 -1
- package/dts/types.d.ts +4 -3
- package/dts/types.d.ts.map +1 -1
- package/dts/util/map-query.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 +13 -15
- package/esm/connection-helpers.js.map +1 -1
- package/esm/field-builder.js +2 -1
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +2 -1
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts +4 -0
- package/esm/global-types.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +1 -1
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/types.d.ts +4 -3
- package/esm/types.d.ts.map +1 -1
- package/esm/util/map-query.d.ts.map +1 -1
- package/esm/util/map-query.js +16 -7
- package/esm/util/map-query.js.map +1 -1
- package/lib/connection-helpers.js +13 -15
- package/lib/connection-helpers.js.map +1 -1
- package/lib/field-builder.js +2 -1
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +2 -1
- package/lib/generator.js.map +1 -1
- package/lib/prisma-field-builder.js +1 -1
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/util/map-query.js +15 -7
- package/lib/util/map-query.js.map +1 -1
- package/package.json +2 -2
- package/src/connection-helpers.ts +20 -16
- package/src/field-builder.ts +2 -2
- package/src/generator.ts +8 -0
- package/src/global-types.ts +4 -0
- package/src/index.ts +1 -1
- package/src/prisma-field-builder.ts +2 -2
- package/src/types.ts +6 -1
- package/src/util/map-query.ts +22 -6
package/src/index.ts
CHANGED
|
@@ -95,7 +95,7 @@ export class PrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
|
|
|
95
95
|
? (
|
|
96
96
|
args: {},
|
|
97
97
|
ctx: Types['Context'],
|
|
98
|
-
nestedQuery: (query: unknown, path?: string[]) => never,
|
|
98
|
+
nestedQuery: (query: unknown, path?: string[], type?: string) => never,
|
|
99
99
|
) => ({
|
|
100
100
|
select: (select as (args: unknown, ctx: unknown, nestedQuery: unknown) => {})(
|
|
101
101
|
args,
|
|
@@ -197,8 +197,8 @@ export class PrismaObjectFieldBuilder<
|
|
|
197
197
|
this: PrismaObjectFieldBuilder<SchemaTypes, Model, boolean>,
|
|
198
198
|
name: string,
|
|
199
199
|
{
|
|
200
|
-
maxSize,
|
|
201
|
-
defaultSize,
|
|
200
|
+
maxSize = this.builder.options.prisma.maxConnectionSize,
|
|
201
|
+
defaultSize = this.builder.options.prisma.defaultConnectionSize,
|
|
202
202
|
cursor: cursorValue,
|
|
203
203
|
query,
|
|
204
204
|
resolve,
|
package/src/types.ts
CHANGED
|
@@ -52,6 +52,7 @@ export interface PrismaModelTypes {
|
|
|
52
52
|
{
|
|
53
53
|
Shape: unknown;
|
|
54
54
|
Name: string;
|
|
55
|
+
Nullable: boolean;
|
|
55
56
|
// Types: PrismaModelTypes;
|
|
56
57
|
}
|
|
57
58
|
>;
|
|
@@ -99,6 +100,7 @@ export type PrismaObjectFieldOptions<
|
|
|
99
100
|
nestedSelection: <Selection extends boolean | {}>(
|
|
100
101
|
selection?: Selection,
|
|
101
102
|
path?: string[],
|
|
103
|
+
type?: string,
|
|
102
104
|
) => Selection,
|
|
103
105
|
) => ExtractModel<Types, ParentShape>['Select'])
|
|
104
106
|
);
|
|
@@ -169,7 +171,9 @@ type RelationShapeFromInclude<
|
|
|
169
171
|
: never]: K extends keyof Model['Relations']
|
|
170
172
|
? Model['Relations'][K]['Shape'] extends unknown[]
|
|
171
173
|
? ShapeFromSelection<Types, TypesForRelation<Types, Model, K>, Include[K]>[]
|
|
172
|
-
:
|
|
174
|
+
: Model['Relations'][K]['Nullable'] extends true
|
|
175
|
+
? ShapeFromSelection<Types, TypesForRelation<Types, Model, K>, Include[K]> | null
|
|
176
|
+
: ShapeFromSelection<Types, TypesForRelation<Types, Model, K>, Include[K]>
|
|
173
177
|
: unknown;
|
|
174
178
|
}>;
|
|
175
179
|
|
|
@@ -794,6 +798,7 @@ export type FieldSelection =
|
|
|
794
798
|
mergeNestedSelection: (
|
|
795
799
|
selection: SelectionMap | boolean | ((args: object, context: object) => SelectionMap),
|
|
796
800
|
path?: IndirectInclude | string[],
|
|
801
|
+
type?: string,
|
|
797
802
|
) => SelectionMap | boolean,
|
|
798
803
|
resolveSelection: (path: string[]) => FieldNode | null,
|
|
799
804
|
) => SelectionMap);
|
package/src/util/map-query.ts
CHANGED
|
@@ -301,12 +301,16 @@ function addFieldSelection(
|
|
|
301
301
|
fieldSelectionMap = fieldSelect(
|
|
302
302
|
args,
|
|
303
303
|
context,
|
|
304
|
-
(rawQuery, indirectInclude) => {
|
|
304
|
+
(rawQuery, indirectInclude, expectedType) => {
|
|
305
305
|
const returnType = getNamedType(field.type);
|
|
306
306
|
const query = typeof rawQuery === 'function' ? rawQuery(args, context) : rawQuery;
|
|
307
307
|
|
|
308
308
|
const normalizedIndirectInclude = Array.isArray(indirectInclude)
|
|
309
|
-
? normalizeInclude(
|
|
309
|
+
? normalizeInclude(
|
|
310
|
+
indirectInclude,
|
|
311
|
+
getIndirectType(returnType, info),
|
|
312
|
+
expectedType ? getNamedType(info.schema.getType(expectedType)) : undefined,
|
|
313
|
+
)
|
|
310
314
|
: indirectInclude;
|
|
311
315
|
|
|
312
316
|
const fieldState = createStateForType(
|
|
@@ -333,7 +337,8 @@ function addFieldSelection(
|
|
|
333
337
|
info,
|
|
334
338
|
selection,
|
|
335
339
|
(returnType.extensions?.pothosPrismaIndirectInclude as { path: [] })?.path ?? [],
|
|
336
|
-
normalizedIndirectInclude
|
|
340
|
+
normalizedIndirectInclude?.paths ??
|
|
341
|
+
(normalizedIndirectInclude?.path ? [normalizedIndirectInclude.path] : []),
|
|
337
342
|
[],
|
|
338
343
|
(resolvedType, resolvedField, path) => {
|
|
339
344
|
addTypeSelectionsForField(
|
|
@@ -346,6 +351,11 @@ function addFieldSelection(
|
|
|
346
351
|
);
|
|
347
352
|
},
|
|
348
353
|
);
|
|
354
|
+
} else if (normalizedIndirectInclude) {
|
|
355
|
+
const targetType = info.schema.getType(normalizedIndirectInclude.getType())!;
|
|
356
|
+
if (targetType !== returnType) {
|
|
357
|
+
addTypeSelectionsForField(targetType, context, info, fieldState, selection, []);
|
|
358
|
+
}
|
|
349
359
|
}
|
|
350
360
|
|
|
351
361
|
addTypeSelectionsForField(returnType, context, info, fieldState, selection, []);
|
|
@@ -530,8 +540,12 @@ export function getIndirectType(type: GraphQLNamedType, info: GraphQLResolveInfo
|
|
|
530
540
|
return targetType;
|
|
531
541
|
}
|
|
532
542
|
|
|
533
|
-
function normalizeInclude(
|
|
534
|
-
|
|
543
|
+
function normalizeInclude(
|
|
544
|
+
path: string[],
|
|
545
|
+
type: GraphQLNamedType,
|
|
546
|
+
expectedType?: GraphQLNamedType,
|
|
547
|
+
): IndirectInclude {
|
|
548
|
+
let currentType = path.length > 0 ? type : expectedType ?? type;
|
|
535
549
|
|
|
536
550
|
const normalized: { name: string; type: string }[] = [];
|
|
537
551
|
|
|
@@ -556,7 +570,9 @@ function normalizeInclude(path: string[], type: GraphQLNamedType): IndirectInclu
|
|
|
556
570
|
}
|
|
557
571
|
|
|
558
572
|
return {
|
|
559
|
-
getType: () =>
|
|
573
|
+
getType: () =>
|
|
574
|
+
expectedType?.name ??
|
|
575
|
+
(normalized.length > 0 ? normalized[normalized.length - 1].type : type.name),
|
|
560
576
|
path: normalized,
|
|
561
577
|
};
|
|
562
578
|
}
|