@pothos/plugin-prisma 3.35.7 → 3.36.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 +232 -41
- package/dts/connection-helpers.d.ts +34 -0
- package/dts/connection-helpers.d.ts.map +1 -0
- package/dts/global-types.d.ts +15 -6
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts +3 -0
- package/dts/index.d.ts.map +1 -1
- package/dts/node-ref.d.ts +1 -1
- package/dts/node-ref.d.ts.map +1 -1
- package/dts/object-ref.d.ts +2 -0
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/prisma-field-builder.d.ts +5 -2
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +8 -6
- package/dts/types.d.ts.map +1 -1
- package/dts/util/map-query.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +34 -0
- package/esm/connection-helpers.d.ts.map +1 -0
- package/esm/connection-helpers.js +26 -0
- package/esm/connection-helpers.js.map +1 -0
- package/esm/field-builder.js +9 -15
- package/esm/field-builder.js.map +1 -1
- package/esm/global-types.d.ts +15 -6
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.d.ts +3 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +3 -0
- package/esm/index.js.map +1 -1
- package/esm/node-ref.d.ts +1 -1
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/node-ref.js +1 -1
- package/esm/node-ref.js.map +1 -1
- package/esm/object-ref.d.ts +2 -0
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/object-ref.js +4 -0
- package/esm/object-ref.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +5 -2
- 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/schema-builder.js +18 -3
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +8 -6
- package/esm/types.d.ts.map +1 -1
- package/esm/util/datamodel.js +1 -1
- package/esm/util/datamodel.js.map +1 -1
- package/esm/util/map-query.d.ts.map +1 -1
- package/esm/util/map-query.js +21 -21
- package/esm/util/map-query.js.map +1 -1
- package/lib/connection-helpers.js +41 -0
- package/lib/connection-helpers.js.map +1 -0
- package/lib/field-builder.js +8 -14
- package/lib/field-builder.js.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/node-ref.js +1 -1
- package/lib/node-ref.js.map +1 -1
- package/lib/object-ref.js +4 -0
- package/lib/object-ref.js.map +1 -1
- package/lib/prisma-field-builder.js +1 -1
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +18 -8
- package/lib/schema-builder.js.map +1 -1
- package/lib/util/datamodel.js +1 -1
- package/lib/util/datamodel.js.map +1 -1
- package/lib/util/map-query.js +21 -20
- package/lib/util/map-query.js.map +1 -1
- package/package.json +10 -10
- package/src/connection-helpers.ts +65 -0
- package/src/field-builder.ts +23 -23
- package/src/global-types.ts +50 -14
- package/src/index.ts +3 -0
- package/src/node-ref.ts +1 -4
- package/src/object-ref.ts +7 -0
- package/src/prisma-field-builder.ts +38 -25
- package/src/schema-builder.ts +38 -3
- package/src/types.ts +35 -16
- package/src/util/datamodel.ts +1 -1
- package/src/util/map-query.ts +32 -17
|
@@ -111,19 +111,28 @@ export class PrismaObjectFieldBuilder<
|
|
|
111
111
|
options: RelatedConnectionOptions<Types, Model, Field, Nullable, Args, NeedsResolve>,
|
|
112
112
|
...args: NormalizeArgs<
|
|
113
113
|
[
|
|
114
|
-
connectionOptions:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
connectionOptions:
|
|
115
|
+
| PothosSchemaTypes.ConnectionObjectOptions<
|
|
116
|
+
Types,
|
|
117
|
+
ObjectRef<Shape>,
|
|
118
|
+
false,
|
|
119
|
+
false,
|
|
120
|
+
ResolveReturnShape
|
|
121
|
+
>
|
|
122
|
+
| ObjectRef<
|
|
123
|
+
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, Shape, false>>
|
|
124
|
+
>,
|
|
125
|
+
edgeOptions:
|
|
126
|
+
| PothosSchemaTypes.ConnectionEdgeObjectOptions<
|
|
127
|
+
Types,
|
|
128
|
+
ObjectRef<Shape>,
|
|
129
|
+
false,
|
|
130
|
+
ResolveReturnShape
|
|
131
|
+
>
|
|
132
|
+
| ObjectRef<{
|
|
133
|
+
cursor: string;
|
|
134
|
+
node?: ShapeFromTypeParam<Types, Model['Shape'], false>;
|
|
135
|
+
}>,
|
|
127
136
|
],
|
|
128
137
|
0
|
|
129
138
|
>
|
|
@@ -272,18 +281,22 @@ export class PrismaObjectFieldBuilder<
|
|
|
272
281
|
);
|
|
273
282
|
},
|
|
274
283
|
},
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
284
|
+
connectionOptions instanceof ObjectRef
|
|
285
|
+
? connectionOptions
|
|
286
|
+
: {
|
|
287
|
+
...connectionOptions,
|
|
288
|
+
fields: totalCount
|
|
289
|
+
? (
|
|
290
|
+
t: PothosSchemaTypes.ObjectFieldBuilder<SchemaTypes, { totalCount?: number }>,
|
|
291
|
+
) => ({
|
|
292
|
+
totalCount: t.int({
|
|
293
|
+
nullable: false,
|
|
294
|
+
resolve: (parent, args, context) => parent.totalCount,
|
|
295
|
+
}),
|
|
296
|
+
...(connectionOptions as { fields?: (t: unknown) => {} }).fields?.(t),
|
|
297
|
+
})
|
|
298
|
+
: (connectionOptions as { fields: undefined }).fields,
|
|
299
|
+
},
|
|
287
300
|
edgeOptions,
|
|
288
301
|
);
|
|
289
302
|
|
package/src/schema-builder.ts
CHANGED
|
@@ -9,7 +9,8 @@ import SchemaBuilder, {
|
|
|
9
9
|
} from '@pothos/core';
|
|
10
10
|
import { PrismaObjectFieldBuilder } from './field-builder';
|
|
11
11
|
import { ModelLoader } from './model-loader';
|
|
12
|
-
import PrismaNodeRef from './node-ref';
|
|
12
|
+
import { PrismaNodeRef } from './node-ref';
|
|
13
|
+
import { PrismaObjectRef } from './object-ref';
|
|
13
14
|
import { PrismaModelTypes, PrismaNodeOptions } from './types';
|
|
14
15
|
import { getDefaultIDParser, getDefaultIDSerializer } from './util/cursors';
|
|
15
16
|
import { getDelegateFromModel, getRefFromModel } from './util/datamodel';
|
|
@@ -24,7 +25,9 @@ schemaBuilderProto.prismaObject = function prismaObject(
|
|
|
24
25
|
type,
|
|
25
26
|
{ fields, findUnique, select, include, description, ...options },
|
|
26
27
|
) {
|
|
27
|
-
const ref = options.variant
|
|
28
|
+
const ref = options.variant
|
|
29
|
+
? new PrismaObjectRef(options.variant, type)
|
|
30
|
+
: getRefFromModel(type, this);
|
|
28
31
|
const name = options.variant ?? options.name ?? type;
|
|
29
32
|
const fieldMap = getRelationMap(getDMMF(this)).get(type)!;
|
|
30
33
|
const idSelection = ModelLoader.getDefaultIDSelection(ref, type, this);
|
|
@@ -77,7 +80,7 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
77
80
|
const resolve = rawResolve ?? getDefaultIDSerializer(type, fieldName, this);
|
|
78
81
|
const idParser = fieldName ? getDefaultIDParser(type, fieldName, this) : undefined;
|
|
79
82
|
const typeName = variant ?? name ?? type;
|
|
80
|
-
const nodeRef = new PrismaNodeRef(typeName);
|
|
83
|
+
const nodeRef = new PrismaNodeRef(typeName, type);
|
|
81
84
|
const findUnique = rawFindUnique
|
|
82
85
|
? (parent: unknown, context: {}) =>
|
|
83
86
|
rawFindUnique(resolve(parent as never, context) as string, context)
|
|
@@ -156,3 +159,35 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
156
159
|
|
|
157
160
|
return nodeRef;
|
|
158
161
|
} as never;
|
|
162
|
+
|
|
163
|
+
schemaBuilderProto.prismaObjectField = function prismaObjectField(type, fieldName, field) {
|
|
164
|
+
const ref = typeof type === 'string' ? getRefFromModel(type, this) : type;
|
|
165
|
+
this.configStore.onTypeConfig(ref, ({ name }) => {
|
|
166
|
+
this.configStore.addFields(ref, () => ({
|
|
167
|
+
[fieldName]: field(
|
|
168
|
+
new PrismaObjectFieldBuilder(
|
|
169
|
+
name,
|
|
170
|
+
this,
|
|
171
|
+
ref.modelName,
|
|
172
|
+
getRelationMap(getDMMF(this)).get(ref.modelName)!,
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
}));
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
schemaBuilderProto.prismaObjectFields = function prismaObjectFields(type, fields) {
|
|
180
|
+
const ref = typeof type === 'string' ? getRefFromModel(type, this) : type;
|
|
181
|
+
this.configStore.onTypeConfig(ref, ({ name }) => {
|
|
182
|
+
this.configStore.addFields(ref, () =>
|
|
183
|
+
fields(
|
|
184
|
+
new PrismaObjectFieldBuilder(
|
|
185
|
+
name,
|
|
186
|
+
this,
|
|
187
|
+
ref.modelName,
|
|
188
|
+
getRelationMap(getDMMF(this)).get(ref.modelName)!,
|
|
189
|
+
),
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -151,29 +151,15 @@ type RelationShapeFromInclude<Model extends PrismaModelTypes, Include> = Normali
|
|
|
151
151
|
: unknown;
|
|
152
152
|
}>;
|
|
153
153
|
|
|
154
|
-
export type
|
|
154
|
+
export type PrismaObjectRefOptions<
|
|
155
155
|
Types extends SchemaTypes,
|
|
156
156
|
Model extends PrismaModelTypes,
|
|
157
|
-
Interfaces extends InterfaceParam<Types>[],
|
|
158
157
|
FindUnique,
|
|
159
158
|
Include,
|
|
160
159
|
Select,
|
|
161
160
|
Shape extends object,
|
|
162
161
|
> = NameOrVariant &
|
|
163
|
-
|
|
164
|
-
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
165
|
-
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
166
|
-
'fields' | 'description'
|
|
167
|
-
> & {
|
|
168
|
-
description?: string | false;
|
|
169
|
-
fields?: PrismaObjectFieldsShape<
|
|
170
|
-
Types,
|
|
171
|
-
Model,
|
|
172
|
-
FindUnique extends null ? true : false,
|
|
173
|
-
Shape & (FindUnique extends null ? {} : { [prismaModelName]?: Model['Name'] }),
|
|
174
|
-
Select
|
|
175
|
-
>;
|
|
176
|
-
} & (
|
|
162
|
+
(
|
|
177
163
|
| {
|
|
178
164
|
include?: Include & Model['Include'];
|
|
179
165
|
select?: never;
|
|
@@ -187,6 +173,39 @@ export type PrismaObjectTypeOptions<
|
|
|
187
173
|
}
|
|
188
174
|
);
|
|
189
175
|
|
|
176
|
+
export type PrismaObjectImplementationOptions<
|
|
177
|
+
Types extends SchemaTypes,
|
|
178
|
+
Model extends PrismaModelTypes,
|
|
179
|
+
Interfaces extends InterfaceParam<Types>[],
|
|
180
|
+
FindUnique,
|
|
181
|
+
Select,
|
|
182
|
+
Shape extends object,
|
|
183
|
+
> = Omit<
|
|
184
|
+
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
185
|
+
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
186
|
+
'fields' | 'description'
|
|
187
|
+
> & {
|
|
188
|
+
description?: string | false;
|
|
189
|
+
fields?: PrismaObjectFieldsShape<
|
|
190
|
+
Types,
|
|
191
|
+
Model,
|
|
192
|
+
FindUnique extends null ? true : false,
|
|
193
|
+
Shape & (FindUnique extends null ? {} : { [prismaModelName]?: Model['Name'] }),
|
|
194
|
+
Select
|
|
195
|
+
>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export type PrismaObjectTypeOptions<
|
|
199
|
+
Types extends SchemaTypes,
|
|
200
|
+
Model extends PrismaModelTypes,
|
|
201
|
+
Interfaces extends InterfaceParam<Types>[],
|
|
202
|
+
FindUnique,
|
|
203
|
+
Include,
|
|
204
|
+
Select,
|
|
205
|
+
Shape extends object,
|
|
206
|
+
> = PrismaObjectRefOptions<Types, Model, FindUnique, Include, Select, Shape> &
|
|
207
|
+
PrismaObjectImplementationOptions<Types, Model, Interfaces, FindUnique, Select, Shape>;
|
|
208
|
+
|
|
190
209
|
type NameOrVariant =
|
|
191
210
|
| {
|
|
192
211
|
name?: never;
|
package/src/util/datamodel.ts
CHANGED
|
@@ -24,7 +24,7 @@ export function getRefFromModel<Types extends SchemaTypes>(
|
|
|
24
24
|
const cache = refMap.get(builder)!;
|
|
25
25
|
|
|
26
26
|
if (!cache.has(name)) {
|
|
27
|
-
cache.set(name, new PrismaObjectRef(name));
|
|
27
|
+
cache.set(name, new PrismaObjectRef(name, name));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return cache.get(name)!;
|
package/src/util/map-query.ts
CHANGED
|
@@ -96,6 +96,11 @@ function resolveIndirectInclude(
|
|
|
96
96
|
path: string[],
|
|
97
97
|
resolve: (type: GraphQLNamedType, field: FieldNode, path: string[]) => void,
|
|
98
98
|
) {
|
|
99
|
+
if (includePath.length === 0) {
|
|
100
|
+
resolve(type, selection as FieldNode, path);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
99
104
|
const [include, ...rest] = includePath;
|
|
100
105
|
if (!selection.selectionSet || !include) {
|
|
101
106
|
return;
|
|
@@ -107,18 +112,14 @@ function resolveIndirectInclude(
|
|
|
107
112
|
if (sel.name.value === include.name && isObjectType(type)) {
|
|
108
113
|
const returnType = getNamedType(type.getFields()[sel.name.value].type);
|
|
109
114
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
[...path, sel.alias?.value ?? sel.name.value],
|
|
119
|
-
resolve,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
115
|
+
resolveIndirectInclude(
|
|
116
|
+
returnType,
|
|
117
|
+
info,
|
|
118
|
+
sel,
|
|
119
|
+
rest,
|
|
120
|
+
[...path, sel.alias?.value ?? sel.name.value],
|
|
121
|
+
resolve,
|
|
122
|
+
);
|
|
122
123
|
}
|
|
123
124
|
continue;
|
|
124
125
|
case Kind.FRAGMENT_SPREAD:
|
|
@@ -334,7 +335,8 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
|
|
|
334
335
|
select?: T;
|
|
335
336
|
path?: string[];
|
|
336
337
|
}): { select: T } | { include?: {} } {
|
|
337
|
-
const
|
|
338
|
+
const returnType = getNamedType(info.returnType);
|
|
339
|
+
const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
|
|
338
340
|
const state = createStateForType(type, info);
|
|
339
341
|
|
|
340
342
|
if (select) {
|
|
@@ -342,14 +344,27 @@ export function queryFromInfo<T extends SelectionMap['select'] | undefined = und
|
|
|
342
344
|
}
|
|
343
345
|
|
|
344
346
|
if (path.length > 0) {
|
|
347
|
+
const { pothosPrismaIndirectInclude } = (returnType.extensions ?? {}) as {
|
|
348
|
+
pothosPrismaIndirectInclude?: IndirectInclude;
|
|
349
|
+
};
|
|
350
|
+
|
|
345
351
|
resolveIndirectInclude(
|
|
346
|
-
|
|
352
|
+
returnType,
|
|
347
353
|
info,
|
|
348
354
|
info.fieldNodes[0],
|
|
349
|
-
path
|
|
355
|
+
pothosPrismaIndirectInclude?.path ?? [],
|
|
350
356
|
[],
|
|
351
|
-
(
|
|
352
|
-
|
|
357
|
+
(indirectType, indirectField, subPath) => {
|
|
358
|
+
resolveIndirectInclude(
|
|
359
|
+
indirectType,
|
|
360
|
+
info,
|
|
361
|
+
indirectField,
|
|
362
|
+
path.map((n) => (typeof n === 'string' ? { name: n } : n)),
|
|
363
|
+
subPath,
|
|
364
|
+
(resolvedType, resolvedField, nested) => {
|
|
365
|
+
addTypeSelectionsForField(resolvedType, context, info, state, resolvedField, nested);
|
|
366
|
+
},
|
|
367
|
+
);
|
|
353
368
|
},
|
|
354
369
|
);
|
|
355
370
|
} else {
|