@pothos/plugin-prisma 0.15.2 → 0.16.3
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/.turbo/turbo-build.log +5 -5
- package/.turbo/turbo-test.log +8 -7
- package/.turbo/turbo-type.log +2 -2
- package/CHANGELOG.md +24 -0
- package/esm/field-builder.d.ts.map +1 -1
- package/esm/field-builder.js +5 -3
- 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 +12 -12
- package/esm/global-types.d.ts.map +1 -1
- package/esm/model-loader.d.ts +2 -1
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +23 -11
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +4 -2
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/node-ref.js +3 -2
- package/esm/node-ref.js.map +1 -1
- package/esm/object-ref.d.ts +7 -0
- package/esm/object-ref.d.ts.map +1 -0
- package/esm/object-ref.js +5 -0
- package/esm/object-ref.js.map +1 -0
- package/esm/prisma-field-builder.d.ts +10 -4
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +33 -7
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/refs.d.ts +5 -3
- package/esm/refs.d.ts.map +1 -1
- package/esm/refs.js +2 -1
- package/esm/refs.js.map +1 -1
- package/esm/schema-builder.js +8 -11
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +19 -6
- package/esm/types.d.ts.map +1 -1
- package/esm/util/map-includes.d.ts +1 -0
- package/esm/util/map-includes.d.ts.map +1 -1
- package/esm/util/map-includes.js +23 -7
- package/esm/util/map-includes.js.map +1 -1
- package/lib/field-builder.d.ts.map +1 -1
- package/lib/field-builder.js +5 -3
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +2 -1
- package/lib/generator.js.map +1 -1
- package/lib/global-types.d.ts +12 -12
- package/lib/global-types.d.ts.map +1 -1
- package/lib/model-loader.d.ts +2 -1
- package/lib/model-loader.d.ts.map +1 -1
- package/lib/model-loader.js +23 -11
- package/lib/model-loader.js.map +1 -1
- package/lib/node-ref.d.ts +4 -2
- package/lib/node-ref.d.ts.map +1 -1
- package/lib/node-ref.js +2 -1
- package/lib/node-ref.js.map +1 -1
- package/lib/object-ref.d.ts +7 -0
- package/lib/object-ref.d.ts.map +1 -0
- package/lib/object-ref.js +9 -0
- package/lib/object-ref.js.map +1 -0
- package/lib/prisma-field-builder.d.ts +10 -4
- package/lib/prisma-field-builder.d.ts.map +1 -1
- package/lib/prisma-field-builder.js +32 -6
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/refs.d.ts +5 -3
- package/lib/refs.d.ts.map +1 -1
- package/lib/refs.js +2 -1
- package/lib/refs.js.map +1 -1
- package/lib/schema-builder.js +8 -11
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.d.ts +19 -6
- package/lib/types.d.ts.map +1 -1
- package/lib/util/map-includes.d.ts +1 -0
- package/lib/util/map-includes.d.ts.map +1 -1
- package/lib/util/map-includes.js +24 -8
- package/lib/util/map-includes.js.map +1 -1
- package/package.json +10 -10
- package/src/field-builder.ts +7 -5
- package/src/generator.ts +8 -1
- package/src/global-types.ts +28 -11
- package/src/model-loader.ts +30 -13
- package/src/node-ref.ts +7 -2
- package/src/object-ref.ts +8 -0
- package/src/prisma-field-builder.ts +59 -8
- package/src/refs.ts +5 -3
- package/src/schema-builder.ts +5 -7
- package/src/types.ts +69 -35
- package/src/util/map-includes.ts +35 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/generated.ts +0 -54
package/src/types.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
TypeParam,
|
|
21
21
|
} from '@pothos/core';
|
|
22
22
|
import { PrismaObjectFieldBuilder } from './field-builder';
|
|
23
|
+
import { PrismaObjectRef } from './object-ref';
|
|
23
24
|
|
|
24
25
|
export interface PrismaDelegate {
|
|
25
26
|
findUnique: (...args: any[]) => Promise<unknown>;
|
|
@@ -65,6 +66,7 @@ export type ModelTypes<Model extends {}> = Model extends {
|
|
|
65
66
|
: never;
|
|
66
67
|
|
|
67
68
|
export interface PrismaModelTypes {
|
|
69
|
+
Name: string;
|
|
68
70
|
Shape: {};
|
|
69
71
|
Include: unknown;
|
|
70
72
|
Where: {};
|
|
@@ -126,16 +128,27 @@ export type PrismaObjectTypeOptions<
|
|
|
126
128
|
FindUnique,
|
|
127
129
|
Include extends Model['Include'],
|
|
128
130
|
Shape extends object,
|
|
129
|
-
> =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
> = NameOrVariant &
|
|
132
|
+
Omit<
|
|
133
|
+
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
134
|
+
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
135
|
+
'fields'
|
|
136
|
+
> & {
|
|
137
|
+
include?: Include;
|
|
138
|
+
fields?: PrismaObjectFieldsShape<Types, Model, FindUnique extends null ? true : false, Shape>;
|
|
139
|
+
findUnique: FindUnique &
|
|
140
|
+
(((parent: Shape, context: Types['Context']) => Model['Where']) | null);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export type NameOrVariant =
|
|
144
|
+
| {
|
|
145
|
+
name?: never;
|
|
146
|
+
variant?: string;
|
|
147
|
+
}
|
|
148
|
+
| {
|
|
149
|
+
name?: string;
|
|
150
|
+
variant?: never;
|
|
151
|
+
};
|
|
139
152
|
|
|
140
153
|
export type PrismaNodeOptions<
|
|
141
154
|
Types extends SchemaTypes,
|
|
@@ -143,31 +156,31 @@ export type PrismaNodeOptions<
|
|
|
143
156
|
Interfaces extends InterfaceParam<Types>[],
|
|
144
157
|
Include extends Model['Include'],
|
|
145
158
|
Shape extends object,
|
|
146
|
-
> =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
name?: string;
|
|
152
|
-
include?: Include;
|
|
153
|
-
id: Omit<
|
|
154
|
-
FieldOptionsFromKind<
|
|
155
|
-
Types,
|
|
156
|
-
Shape,
|
|
157
|
-
'ID',
|
|
158
|
-
false,
|
|
159
|
-
{},
|
|
160
|
-
'Object',
|
|
161
|
-
OutputShape<Types, 'ID'>,
|
|
162
|
-
MaybePromise<OutputShape<Types, 'ID'>>
|
|
163
|
-
>,
|
|
164
|
-
'args' | 'nullable' | 'resolve' | 'type'
|
|
159
|
+
> = NameOrVariant &
|
|
160
|
+
Omit<
|
|
161
|
+
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
162
|
+
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
163
|
+
'fields' | 'isTypeOf'
|
|
165
164
|
> & {
|
|
166
|
-
|
|
165
|
+
include?: Include;
|
|
166
|
+
id: Omit<
|
|
167
|
+
FieldOptionsFromKind<
|
|
168
|
+
Types,
|
|
169
|
+
Shape,
|
|
170
|
+
'ID',
|
|
171
|
+
false,
|
|
172
|
+
{},
|
|
173
|
+
'Object',
|
|
174
|
+
OutputShape<Types, 'ID'>,
|
|
175
|
+
MaybePromise<OutputShape<Types, 'ID'>>
|
|
176
|
+
>,
|
|
177
|
+
'args' | 'nullable' | 'resolve' | 'type'
|
|
178
|
+
> & {
|
|
179
|
+
resolve: (parent: Shape, context: Types['Context']) => MaybePromise<OutputShape<Types, 'ID'>>;
|
|
180
|
+
};
|
|
181
|
+
fields?: PrismaObjectFieldsShape<Types, Model, false, Shape>;
|
|
182
|
+
findUnique: (id: string, context: Types['Context']) => Model['Where'];
|
|
167
183
|
};
|
|
168
|
-
fields?: PrismaObjectFieldsShape<Types, Model, false, Shape>;
|
|
169
|
-
findUnique: (id: string, context: Types['Context']) => Model['Where'];
|
|
170
|
-
};
|
|
171
184
|
|
|
172
185
|
export type QueryForField<
|
|
173
186
|
Types extends SchemaTypes,
|
|
@@ -254,9 +267,19 @@ export type RelatedFieldOptions<
|
|
|
254
267
|
ShapeWithNullability<Types, Model['Relations'][Field]['Shape'], Nullable>
|
|
255
268
|
>;
|
|
256
269
|
}) & {
|
|
270
|
+
type?: PrismaObjectRef<Model['Relations'][Field]['Types']>;
|
|
257
271
|
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
258
272
|
};
|
|
259
273
|
|
|
274
|
+
export type VariantFieldOptions<
|
|
275
|
+
Types extends SchemaTypes,
|
|
276
|
+
Model extends PrismaModelTypes,
|
|
277
|
+
Variant extends PrismaObjectRef<Model>,
|
|
278
|
+
> = Omit<
|
|
279
|
+
PothosSchemaTypes.ObjectFieldOptions<Types, Model['Shape'], Variant, false, {}, Model['Shape']>,
|
|
280
|
+
'resolve' | 'type'
|
|
281
|
+
>;
|
|
282
|
+
|
|
260
283
|
export type RelationCountOptions<
|
|
261
284
|
Types extends SchemaTypes,
|
|
262
285
|
Shape,
|
|
@@ -286,7 +309,11 @@ export type RelationCountOptions<
|
|
|
286
309
|
export type PrismaFieldOptions<
|
|
287
310
|
Types extends SchemaTypes,
|
|
288
311
|
ParentShape,
|
|
289
|
-
Type extends
|
|
312
|
+
Type extends
|
|
313
|
+
| PrismaObjectRef<PrismaModelTypes>
|
|
314
|
+
| keyof Types['PrismaTypes']
|
|
315
|
+
| [keyof Types['PrismaTypes']]
|
|
316
|
+
| [PrismaObjectRef<PrismaModelTypes>],
|
|
290
317
|
Model extends PrismaModelTypes,
|
|
291
318
|
Param extends TypeParam<Types>,
|
|
292
319
|
Args extends InputFieldMap,
|
|
@@ -325,7 +352,7 @@ export type PrismaFieldOptions<
|
|
|
325
352
|
export type PrismaConnectionFieldOptions<
|
|
326
353
|
Types extends SchemaTypes,
|
|
327
354
|
ParentShape,
|
|
328
|
-
Type extends keyof Types['PrismaTypes'],
|
|
355
|
+
Type extends PrismaObjectRef<PrismaModelTypes> | keyof Types['PrismaTypes'],
|
|
329
356
|
Model extends PrismaModelTypes,
|
|
330
357
|
Param extends OutputType<Types>,
|
|
331
358
|
Nullable extends boolean,
|
|
@@ -339,6 +366,8 @@ export type PrismaConnectionFieldOptions<
|
|
|
339
366
|
ParentShape,
|
|
340
367
|
Param,
|
|
341
368
|
Nullable,
|
|
369
|
+
false,
|
|
370
|
+
false,
|
|
342
371
|
Args,
|
|
343
372
|
ResolveReturnShape
|
|
344
373
|
>,
|
|
@@ -399,6 +428,8 @@ export type RelatedConnectionOptions<
|
|
|
399
428
|
Types,
|
|
400
429
|
Model['Shape'],
|
|
401
430
|
ObjectRef<unknown>,
|
|
431
|
+
false,
|
|
432
|
+
false,
|
|
402
433
|
Nullable,
|
|
403
434
|
Args,
|
|
404
435
|
unknown
|
|
@@ -406,6 +437,7 @@ export type RelatedConnectionOptions<
|
|
|
406
437
|
'resolve' | 'type'
|
|
407
438
|
> & {
|
|
408
439
|
query?: QueryForField<Types, Args, Model['Include'][Field & keyof Model['Include']]>;
|
|
440
|
+
type?: PrismaObjectRef<Model['Relations'][Field]['Types']>;
|
|
409
441
|
cursor: CursorFromRelation<Model, Field>;
|
|
410
442
|
defaultSize?: number;
|
|
411
443
|
maxSize?: number;
|
|
@@ -468,3 +500,5 @@ export interface IndirectLoadMap {
|
|
|
468
500
|
subFields: SubFieldInclude[];
|
|
469
501
|
path: string[];
|
|
470
502
|
}
|
|
503
|
+
|
|
504
|
+
export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
|
package/src/util/map-includes.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
/* eslint-disable no-param-reassign */
|
|
3
3
|
/* eslint-disable no-continue */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
5
4
|
import {
|
|
6
5
|
FieldNode,
|
|
7
6
|
getNamedType,
|
|
@@ -22,6 +21,8 @@ import {
|
|
|
22
21
|
} from '../types';
|
|
23
22
|
import { mergeIncludes, resolveIndirectType } from '.';
|
|
24
23
|
|
|
24
|
+
export const SELF_RELATION = '@self';
|
|
25
|
+
|
|
25
26
|
function handleField(
|
|
26
27
|
ctx: object,
|
|
27
28
|
info: GraphQLResolveInfo,
|
|
@@ -108,7 +109,8 @@ function handleField(
|
|
|
108
109
|
query = query(args, ctx);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
const existingInclude =
|
|
112
|
+
const existingInclude =
|
|
113
|
+
relationName === SELF_RELATION ? { include: includes } : includes[relationName];
|
|
112
114
|
|
|
113
115
|
query = { ...(query as {}), include: newIncludes };
|
|
114
116
|
|
|
@@ -120,6 +122,10 @@ function handleField(
|
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
|
|
125
|
+
if (!mappings[relationName]) {
|
|
126
|
+
mappings[relationName] = [];
|
|
127
|
+
}
|
|
128
|
+
|
|
123
129
|
const nestedIncludes = (query as { include: IncludeMap }).include;
|
|
124
130
|
const nestedMappings: LoaderMappings = {};
|
|
125
131
|
const nestedCounts: IncludeCounts = {
|
|
@@ -127,8 +133,33 @@ function handleField(
|
|
|
127
133
|
parent: counts.current,
|
|
128
134
|
};
|
|
129
135
|
|
|
130
|
-
if (
|
|
131
|
-
mappings[relationName]
|
|
136
|
+
if (relationName === SELF_RELATION) {
|
|
137
|
+
mappings[relationName].push({
|
|
138
|
+
field: selection.name.value,
|
|
139
|
+
alias: selection.alias?.value,
|
|
140
|
+
mappings: nestedMappings,
|
|
141
|
+
indirectPath: indirectMap?.path ?? [],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const { include } = query as { include: Record<string, IncludeMap> };
|
|
145
|
+
|
|
146
|
+
if (selection.selectionSet) {
|
|
147
|
+
includesFromSelectionSet(
|
|
148
|
+
ctx,
|
|
149
|
+
type,
|
|
150
|
+
info,
|
|
151
|
+
includes,
|
|
152
|
+
counts,
|
|
153
|
+
nestedMappings,
|
|
154
|
+
selection.selectionSet,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
Object.keys(include).forEach((key) => {
|
|
159
|
+
includes[key] = include[key];
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return;
|
|
132
163
|
}
|
|
133
164
|
|
|
134
165
|
mappings[relationName].push({
|