@pothos/plugin-prisma 4.1.0 → 4.2.1
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 +16 -4
- package/dts/connection-helpers.d.ts +2 -2
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/global-types.d.ts +8 -8
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts +2 -2
- package/dts/index.d.ts.map +1 -1
- package/dts/interface-ref.d.ts +2 -2
- package/dts/interface-ref.d.ts.map +1 -1
- package/dts/model-loader.d.ts +4 -4
- package/dts/model-loader.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 +1 -1
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/prisma-field-builder.d.ts +6 -6
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +10 -10
- package/dts/types.d.ts.map +1 -1
- package/dts/util/cursors.d.ts +3 -3
- package/dts/util/cursors.d.ts.map +1 -1
- package/dts/util/datamodel.d.ts +3 -3
- package/dts/util/datamodel.d.ts.map +1 -1
- package/dts/util/deep-equal.d.ts.map +1 -1
- package/dts/util/description.d.ts +1 -1
- package/dts/util/description.d.ts.map +1 -1
- package/dts/util/get-client.d.ts +2 -2
- package/dts/util/get-client.d.ts.map +1 -1
- package/dts/util/loader-map.d.ts +2 -2
- package/dts/util/loader-map.d.ts.map +1 -1
- package/dts/util/map-query.d.ts +3 -3
- package/dts/util/map-query.d.ts.map +1 -1
- package/dts/util/relation-map.d.ts +1 -1
- package/dts/util/relation-map.d.ts.map +1 -1
- package/dts/util/selections.d.ts +2 -2
- package/dts/util/selections.d.ts.map +1 -1
- package/dts/util/usage.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +2 -2
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/field-builder.js +6 -6
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +5 -5
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts +8 -8
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -4
- package/esm/index.js.map +1 -1
- package/esm/interface-ref.d.ts +2 -2
- package/esm/interface-ref.d.ts.map +1 -1
- package/esm/interface-ref.js.map +1 -1
- package/esm/model-loader.d.ts +4 -4
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +13 -15
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +1 -1
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/object-ref.d.ts +1 -1
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/object-ref.js +4 -2
- package/esm/object-ref.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +6 -6
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +7 -8
- 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 +10 -10
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/util/cursors.d.ts +3 -3
- package/esm/util/cursors.d.ts.map +1 -1
- package/esm/util/cursors.js +2 -2
- package/esm/util/cursors.js.map +1 -1
- package/esm/util/datamodel.d.ts +3 -3
- package/esm/util/datamodel.d.ts.map +1 -1
- package/esm/util/datamodel.js.map +1 -1
- package/esm/util/deep-equal.d.ts.map +1 -1
- package/esm/util/deep-equal.js +1 -1
- package/esm/util/deep-equal.js.map +1 -1
- package/esm/util/description.d.ts +1 -1
- package/esm/util/description.d.ts.map +1 -1
- package/esm/util/description.js +1 -1
- package/esm/util/description.js.map +1 -1
- package/esm/util/get-client.d.ts +2 -2
- package/esm/util/get-client.d.ts.map +1 -1
- package/esm/util/get-client.js +1 -1
- package/esm/util/get-client.js.map +1 -1
- package/esm/util/loader-map.d.ts +2 -2
- package/esm/util/loader-map.d.ts.map +1 -1
- package/esm/util/loader-map.js +4 -5
- package/esm/util/loader-map.js.map +1 -1
- package/esm/util/map-query.d.ts +3 -3
- package/esm/util/map-query.d.ts.map +1 -1
- package/esm/util/map-query.js +2 -3
- package/esm/util/map-query.js.map +1 -1
- package/esm/util/relation-map.d.ts +1 -1
- package/esm/util/relation-map.d.ts.map +1 -1
- package/esm/util/relation-map.js +12 -12
- package/esm/util/relation-map.js.map +1 -1
- package/esm/util/selections.d.ts +2 -2
- package/esm/util/selections.d.ts.map +1 -1
- package/esm/util/selections.js +9 -9
- package/esm/util/selections.js.map +1 -1
- package/esm/util/usage.d.ts.map +1 -1
- package/esm/util/usage.js +0 -1
- package/esm/util/usage.js.map +1 -1
- package/generated.d.ts +1 -1
- package/lib/field-builder.js +7 -5
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +4 -4
- package/lib/generator.js.map +1 -1
- package/lib/global-types.js +1 -1
- package/lib/global-types.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/interface-ref.js.map +1 -1
- package/lib/model-loader.js +12 -14
- package/lib/model-loader.js.map +1 -1
- package/lib/object-ref.js +3 -1
- package/lib/object-ref.js.map +1 -1
- package/lib/prisma-field-builder.js +6 -7
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +1 -1
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/util/cursors.js +2 -2
- package/lib/util/cursors.js.map +1 -1
- package/lib/util/datamodel.js.map +1 -1
- package/lib/util/deep-equal.js +1 -1
- package/lib/util/deep-equal.js.map +1 -1
- package/lib/util/description.js +1 -1
- package/lib/util/description.js.map +1 -1
- package/lib/util/get-client.js +1 -1
- package/lib/util/get-client.js.map +1 -1
- package/lib/util/loader-map.js +4 -5
- package/lib/util/loader-map.js.map +1 -1
- package/lib/util/map-query.js +2 -3
- package/lib/util/map-query.js.map +1 -1
- package/lib/util/relation-map.js +12 -12
- package/lib/util/relation-map.js.map +1 -1
- package/lib/util/selections.js +9 -9
- package/lib/util/selections.js.map +1 -1
- package/lib/util/usage.js +0 -1
- package/lib/util/usage.js.map +1 -1
- package/package.json +12 -12
- package/src/connection-helpers.ts +2 -2
- package/src/field-builder.ts +21 -13
- package/src/generator.ts +5 -8
- package/src/global-types.ts +35 -28
- package/src/index.ts +12 -11
- package/src/interface-ref.ts +2 -2
- package/src/model-loader.ts +17 -19
- package/src/node-ref.ts +1 -1
- package/src/object-ref.ts +5 -3
- package/src/prisma-field-builder.ts +58 -51
- package/src/schema-builder.ts +8 -8
- package/src/types.ts +64 -62
- package/src/util/cursors.ts +7 -8
- package/src/util/datamodel.ts +3 -3
- package/src/util/deep-equal.ts +0 -1
- package/src/util/description.ts +1 -2
- package/src/util/get-client.ts +2 -3
- package/src/util/loader-map.ts +6 -8
- package/src/util/map-query.ts +16 -19
- package/src/util/relation-map.ts +13 -13
- package/src/util/selections.ts +10 -12
- package/src/util/usage.ts +0 -2
package/src/field-builder.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import { getNamedType, GraphQLResolveInfo, isInterfaceType, isObjectType, Kind } from 'graphql';
|
|
2
1
|
import {
|
|
3
|
-
FieldKind,
|
|
4
|
-
FieldRef,
|
|
5
|
-
InputFieldMap,
|
|
6
|
-
|
|
7
|
-
MaybePromise,
|
|
2
|
+
type FieldKind,
|
|
3
|
+
type FieldRef,
|
|
4
|
+
type InputFieldMap,
|
|
5
|
+
type MaybePromise,
|
|
8
6
|
ObjectRef,
|
|
9
7
|
PothosError,
|
|
10
8
|
RootFieldBuilder,
|
|
11
|
-
SchemaTypes,
|
|
9
|
+
type SchemaTypes,
|
|
10
|
+
isThenable,
|
|
12
11
|
} from '@pothos/core';
|
|
12
|
+
import {
|
|
13
|
+
type GraphQLResolveInfo,
|
|
14
|
+
Kind,
|
|
15
|
+
getNamedType,
|
|
16
|
+
isInterfaceType,
|
|
17
|
+
isObjectType,
|
|
18
|
+
} from 'graphql';
|
|
13
19
|
import { ModelLoader } from './model-loader';
|
|
14
|
-
import { PrismaConnectionFieldOptions, PrismaModelTypes } from './types';
|
|
20
|
+
import type { PrismaConnectionFieldOptions, PrismaModelTypes } from './types';
|
|
15
21
|
import { getCursorFormatter, getCursorParser, resolvePrismaCursorConnection } from './util/cursors';
|
|
16
22
|
import { getRefFromModel } from './util/datamodel';
|
|
17
23
|
import { queryFromInfo } from './util/map-query';
|
|
@@ -177,7 +183,9 @@ fieldBuilderProto.prismaConnection = function prismaConnection<
|
|
|
177
183
|
},
|
|
178
184
|
formatCursor,
|
|
179
185
|
(q) => {
|
|
180
|
-
if (totalCountOnly)
|
|
186
|
+
if (totalCountOnly) {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
181
189
|
|
|
182
190
|
return checkIfQueryIsUsed(
|
|
183
191
|
this.builder,
|
|
@@ -205,13 +213,13 @@ fieldBuilderProto.prismaConnection = function prismaConnection<
|
|
|
205
213
|
extensions: {
|
|
206
214
|
pothosPrismaTotalCount: true,
|
|
207
215
|
},
|
|
208
|
-
resolve: (parent
|
|
216
|
+
resolve: (parent) => parent.totalCount?.(),
|
|
209
217
|
}),
|
|
210
218
|
...(connectionOptions as { fields?: (t: unknown) => {} }).fields?.(t),
|
|
211
219
|
})
|
|
212
220
|
: (connectionOptions as { fields: undefined }).fields,
|
|
213
221
|
extensions: {
|
|
214
|
-
...(connectionOptions as Record<string,
|
|
222
|
+
...(connectionOptions as Record<string, object> | undefined)?.extensions,
|
|
215
223
|
},
|
|
216
224
|
},
|
|
217
225
|
edgeOptions,
|
|
@@ -257,8 +265,8 @@ function checkIfQueryIsUsed<Types extends SchemaTypes, T>(
|
|
|
257
265
|
|
|
258
266
|
if (onUnusedQuery === 'error') {
|
|
259
267
|
throw new PothosError(message);
|
|
260
|
-
}
|
|
261
|
-
|
|
268
|
+
}
|
|
269
|
+
if (onUnusedQuery === 'warn') {
|
|
262
270
|
console.warn(message);
|
|
263
271
|
}
|
|
264
272
|
}
|
package/src/generator.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/* eslint-disable unicorn/prefer-module */
|
|
2
|
-
/* eslint-disable no-magic-numbers */
|
|
3
|
-
/* eslint-disable no-nested-ternary */
|
|
4
1
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
5
|
-
import { dirname, join, resolve as resolvePath
|
|
2
|
+
import { dirname, join, posix, resolve as resolvePath } from 'node:path';
|
|
3
|
+
import { type DMMF, generatorHandler } from '@prisma/generator-helper';
|
|
6
4
|
import ts, { ListFormat, ScriptKind, ScriptTarget, SyntaxKind, version } from 'typescript';
|
|
7
|
-
import {
|
|
8
|
-
import { PothosPrismaDatamodel } from './types';
|
|
5
|
+
import type { PothosPrismaDatamodel } from './types';
|
|
9
6
|
|
|
10
7
|
const MIN_TS_VERSION = [4, 5, 2];
|
|
11
8
|
|
|
@@ -83,7 +80,7 @@ function trimDmmf(dmmf: DMMF.Document, documentation = false): PothosPrismaDatam
|
|
|
83
80
|
},
|
|
84
81
|
};
|
|
85
82
|
|
|
86
|
-
dmmf.datamodel.models
|
|
83
|
+
for (const model of dmmf.datamodel.models) {
|
|
87
84
|
trimmed.datamodel.models[model.name] = {
|
|
88
85
|
fields: model.fields.map((field) => ({
|
|
89
86
|
type: field.type,
|
|
@@ -108,7 +105,7 @@ function trimDmmf(dmmf: DMMF.Document, documentation = false): PothosPrismaDatam
|
|
|
108
105
|
})),
|
|
109
106
|
documentation: documentation ? model.documentation : undefined,
|
|
110
107
|
};
|
|
111
|
-
}
|
|
108
|
+
}
|
|
112
109
|
|
|
113
110
|
return trimmed;
|
|
114
111
|
}
|
package/src/global-types.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
3
|
-
import { GraphQLResolveInfo } from 'graphql';
|
|
4
|
-
import {
|
|
1
|
+
import type {
|
|
5
2
|
FieldKind,
|
|
6
3
|
FieldMap,
|
|
7
4
|
FieldNullability,
|
|
@@ -15,24 +12,25 @@ import {
|
|
|
15
12
|
ShapeFromTypeParam,
|
|
16
13
|
TypeParam,
|
|
17
14
|
} from '@pothos/core';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
15
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
16
|
+
import type { PrismaInterfaceRef, PrismaRef } from './interface-ref';
|
|
17
|
+
import type { PrismaNodeRef } from './node-ref';
|
|
18
|
+
import type { PrismaObjectRef, prismaModelKey } from './object-ref';
|
|
19
|
+
import type { PrismaObjectFieldBuilder as InternalPrismaObjectFieldBuilder } from './prisma-field-builder';
|
|
22
20
|
import {
|
|
23
|
-
PrismaClient,
|
|
24
|
-
PrismaConnectionFieldOptions,
|
|
25
|
-
PrismaConnectionShape,
|
|
26
|
-
PrismaFieldOptions,
|
|
27
|
-
PrismaFieldWithInputOptions,
|
|
28
|
-
PrismaInterfaceTypeOptions,
|
|
21
|
+
type PrismaClient,
|
|
22
|
+
type PrismaConnectionFieldOptions,
|
|
23
|
+
type PrismaConnectionShape,
|
|
24
|
+
type PrismaFieldOptions,
|
|
25
|
+
type PrismaFieldWithInputOptions,
|
|
26
|
+
type PrismaInterfaceTypeOptions,
|
|
27
|
+
type PrismaModelTypes,
|
|
28
|
+
type PrismaNodeOptions,
|
|
29
|
+
type PrismaObjectFieldOptions,
|
|
30
|
+
type PrismaObjectTypeOptions,
|
|
31
|
+
type ShapeFromConnection,
|
|
32
|
+
type ShapeFromSelection,
|
|
29
33
|
prismaModelName,
|
|
30
|
-
PrismaModelTypes,
|
|
31
|
-
PrismaNodeOptions,
|
|
32
|
-
PrismaObjectFieldOptions,
|
|
33
|
-
PrismaObjectTypeOptions,
|
|
34
|
-
ShapeFromConnection,
|
|
35
|
-
ShapeFromSelection,
|
|
36
34
|
} from './types';
|
|
37
35
|
|
|
38
36
|
import type { PothosPrismaPlugin } from '.';
|
|
@@ -254,10 +252,11 @@ declare global {
|
|
|
254
252
|
> {
|
|
255
253
|
prismaField: <
|
|
256
254
|
Args extends InputFieldMap,
|
|
257
|
-
TypeParam extends
|
|
255
|
+
TypeParam extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
258
256
|
| PrismaRef<any, PrismaModelTypes>
|
|
259
257
|
| keyof Types['PrismaTypes']
|
|
260
258
|
| [keyof Types['PrismaTypes']]
|
|
259
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
261
260
|
| [PrismaRef<any, PrismaModelTypes>],
|
|
262
261
|
Nullable extends FieldNullability<Type>,
|
|
263
262
|
ResolveShape,
|
|
@@ -268,9 +267,11 @@ declare global {
|
|
|
268
267
|
Model extends PrismaModelTypes = PrismaModelTypes &
|
|
269
268
|
(TypeParam extends [keyof Types['PrismaTypes']]
|
|
270
269
|
? Types['PrismaTypes'][TypeParam[0]]
|
|
271
|
-
:
|
|
270
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
271
|
+
TypeParam extends [PrismaRef<any, PrismaModelTypes>]
|
|
272
272
|
? TypeParam[0][typeof prismaModelKey]
|
|
273
|
-
:
|
|
273
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
274
|
+
TypeParam extends PrismaRef<any, PrismaModelTypes>
|
|
274
275
|
? TypeParam[typeof prismaModelKey]
|
|
275
276
|
: TypeParam extends keyof Types['PrismaTypes']
|
|
276
277
|
? Types['PrismaTypes'][TypeParam]
|
|
@@ -292,14 +293,17 @@ declare global {
|
|
|
292
293
|
|
|
293
294
|
prismaConnection: 'relay' extends PluginName
|
|
294
295
|
? <
|
|
296
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
295
297
|
Type extends PrismaRef<any, PrismaModelTypes> | keyof Types['PrismaTypes'],
|
|
296
298
|
Nullable extends boolean,
|
|
297
299
|
ResolveReturnShape,
|
|
298
300
|
Args extends InputFieldMap = {},
|
|
299
|
-
|
|
301
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
302
|
+
Model extends PrismaModelTypes = Type extends PrismaRef<any, infer T>
|
|
300
303
|
? T
|
|
301
304
|
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
|
|
302
|
-
|
|
305
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
306
|
+
Shape = Type extends PrismaRef<any, PrismaModelTypes, infer S> ? S : Model['Shape'],
|
|
303
307
|
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
|
|
304
308
|
EdgeInterfaces extends InterfaceParam<Types>[] = [],
|
|
305
309
|
>(
|
|
@@ -356,10 +360,11 @@ declare global {
|
|
|
356
360
|
prismaFieldWithInput: 'withInput' extends PluginName
|
|
357
361
|
? <
|
|
358
362
|
Fields extends InputFieldMap,
|
|
359
|
-
TypeParam extends
|
|
363
|
+
TypeParam extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
360
364
|
| PrismaRef<any, PrismaModelTypes>
|
|
361
365
|
| keyof Types['PrismaTypes']
|
|
362
366
|
| [keyof Types['PrismaTypes']]
|
|
367
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
363
368
|
| [PrismaRef<any, PrismaModelTypes>],
|
|
364
369
|
Type extends TypeParam extends [unknown]
|
|
365
370
|
? [ObjectRef<Types, Model['Shape']>]
|
|
@@ -373,9 +378,11 @@ declare global {
|
|
|
373
378
|
Model extends PrismaModelTypes = PrismaModelTypes &
|
|
374
379
|
(TypeParam extends [keyof Types['PrismaTypes']]
|
|
375
380
|
? Types['PrismaTypes'][TypeParam[0]]
|
|
376
|
-
:
|
|
381
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
382
|
+
TypeParam extends [PrismaRef<any, PrismaModelTypes>]
|
|
377
383
|
? TypeParam[0][typeof prismaModelKey]
|
|
378
|
-
:
|
|
384
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
385
|
+
TypeParam extends PrismaRef<any, PrismaModelTypes>
|
|
379
386
|
? TypeParam[typeof prismaModelKey]
|
|
380
387
|
: TypeParam extends keyof Types['PrismaTypes']
|
|
381
388
|
? Types['PrismaTypes'][TypeParam]
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import './global-types';
|
|
2
2
|
import './schema-builder';
|
|
3
3
|
import './field-builder';
|
|
4
|
-
import { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql';
|
|
5
4
|
import SchemaBuilder, {
|
|
6
5
|
BasePlugin,
|
|
7
|
-
BuildCache,
|
|
8
|
-
PothosOutputFieldConfig,
|
|
6
|
+
type BuildCache,
|
|
7
|
+
type PothosOutputFieldConfig,
|
|
9
8
|
PothosSchemaError,
|
|
10
|
-
PothosTypeConfig,
|
|
11
|
-
SchemaTypes,
|
|
9
|
+
type PothosTypeConfig,
|
|
10
|
+
type SchemaTypes,
|
|
12
11
|
} from '@pothos/core';
|
|
13
|
-
|
|
12
|
+
// biome-ignore lint/style/useImportType: <explanation>
|
|
13
|
+
import { GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql';
|
|
14
|
+
import type { ModelLoader } from './model-loader';
|
|
14
15
|
import { PrismaObjectFieldBuilder as InternalPrismaObjectFieldBuilder } from './prisma-field-builder';
|
|
15
|
-
import { PrismaModelTypes } from './types';
|
|
16
|
+
import type { PrismaModelTypes } from './types';
|
|
16
17
|
import { formatPrismaCursor, parsePrismaCursor } from './util/cursors';
|
|
17
18
|
import { getModel, getRefFromModel } from './util/datamodel';
|
|
18
19
|
import { getLoaderMapping, setLoaderMappings } from './util/loader-map';
|
|
@@ -56,7 +57,7 @@ export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Ty
|
|
|
56
57
|
|
|
57
58
|
let model = typeConfig.extensions?.pothosPrismaModel as string | undefined;
|
|
58
59
|
|
|
59
|
-
typeConfig.interfaces
|
|
60
|
+
for (const iface of typeConfig.interfaces) {
|
|
60
61
|
const interfaceModel = this.buildCache.getTypeConfig(iface, 'Interface').extensions
|
|
61
62
|
?.pothosPrismaModel as string | undefined;
|
|
62
63
|
|
|
@@ -69,7 +70,7 @@ export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Ty
|
|
|
69
70
|
|
|
70
71
|
model = interfaceModel;
|
|
71
72
|
}
|
|
72
|
-
}
|
|
73
|
+
}
|
|
73
74
|
|
|
74
75
|
return {
|
|
75
76
|
...typeConfig,
|
|
@@ -133,12 +134,12 @@ export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Ty
|
|
|
133
134
|
const parentTypes = new Set([fieldConfig.parentType]);
|
|
134
135
|
|
|
135
136
|
if (parentConfig.kind === 'Interface' || parentConfig.kind === 'Object') {
|
|
136
|
-
parentConfig.interfaces
|
|
137
|
+
for (const iface of parentConfig.interfaces) {
|
|
137
138
|
const interfaceConfig = this.buildCache.getTypeConfig(iface, 'Interface');
|
|
138
139
|
if (interfaceConfig.extensions?.pothosPrismaModel) {
|
|
139
140
|
parentTypes.add(interfaceConfig.name);
|
|
140
141
|
}
|
|
141
|
-
}
|
|
142
|
+
}
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
return (parent, args, context, info) => {
|
package/src/interface-ref.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InterfaceRef, SchemaTypes } from '@pothos/core';
|
|
2
|
-
import {
|
|
1
|
+
import { InterfaceRef, type SchemaTypes } from '@pothos/core';
|
|
2
|
+
import { type PrismaObjectRef, prismaModelKey } from './object-ref';
|
|
3
3
|
import type { PrismaModelTypes } from './types';
|
|
4
4
|
|
|
5
5
|
export type PrismaRef<Types extends SchemaTypes, Model extends PrismaModelTypes, T = {}> =
|
package/src/model-loader.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { GraphQLResolveInfo } from 'graphql';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ObjectRef,
|
|
2
|
+
type InterfaceRef,
|
|
3
|
+
type ObjectRef,
|
|
6
4
|
PothosSchemaError,
|
|
7
|
-
SchemaTypes,
|
|
5
|
+
type SchemaTypes,
|
|
6
|
+
createContextCache,
|
|
8
7
|
} from '@pothos/core';
|
|
9
|
-
import {
|
|
8
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
9
|
+
import type { PrismaDelegate, SelectionMap } from './types';
|
|
10
10
|
import { getDelegateFromModel, getModel } from './util/datamodel';
|
|
11
11
|
import { getClient } from './util/get-client';
|
|
12
12
|
import { cacheKey, setLoaderMappings } from './util/loader-map';
|
|
13
13
|
import { selectionStateFromInfo } from './util/map-query';
|
|
14
14
|
import {
|
|
15
|
+
type SelectionState,
|
|
15
16
|
mergeSelection,
|
|
16
17
|
selectionCompatible,
|
|
17
|
-
SelectionState,
|
|
18
18
|
selectionToQuery,
|
|
19
19
|
} from './util/selections';
|
|
20
20
|
|
|
@@ -75,7 +75,7 @@ export class ModelLoader {
|
|
|
75
75
|
? () => {
|
|
76
76
|
throw new PothosSchemaError(`Missing findUnique for ${ref.name}`);
|
|
77
77
|
}
|
|
78
|
-
: findUnique ??
|
|
78
|
+
: findUnique ?? ModelLoader.getDefaultFindUnique(ref, modelName, builder),
|
|
79
79
|
),
|
|
80
80
|
);
|
|
81
81
|
}
|
|
@@ -147,9 +147,9 @@ export class ModelLoader {
|
|
|
147
147
|
modelName: string,
|
|
148
148
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
149
149
|
): (model: Record<string, unknown>) => {} {
|
|
150
|
-
const findBy =
|
|
150
|
+
const findBy = ModelLoader.getDefaultFindBy(ref, modelName, builder);
|
|
151
151
|
|
|
152
|
-
return
|
|
152
|
+
return ModelLoader.getFindUnique(findBy);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
static getDefaultIDSelection<Types extends SchemaTypes>(
|
|
@@ -157,7 +157,7 @@ export class ModelLoader {
|
|
|
157
157
|
modelName: string,
|
|
158
158
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
159
159
|
): Record<string, boolean> {
|
|
160
|
-
const findBy =
|
|
160
|
+
const findBy = ModelLoader.getDefaultFindBy(ref, modelName, builder);
|
|
161
161
|
|
|
162
162
|
if (typeof findBy === 'string') {
|
|
163
163
|
return { [findBy]: true };
|
|
@@ -236,7 +236,7 @@ export class ModelLoader {
|
|
|
236
236
|
throw new PothosSchemaError(`Unable to find field or index for ${fieldName} of ${ref.name}`);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
return
|
|
239
|
+
return ModelLoader.getFindUnique(findBy);
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
getSelection(info: GraphQLResolveInfo) {
|
|
@@ -277,7 +277,7 @@ export class ModelLoader {
|
|
|
277
277
|
entry.models.set(model, createResolvablePromise<Record<string, unknown> | null>());
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
return entry.models.get(model)!.promise;
|
|
280
|
+
return await entry.models.get(model)!.promise;
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -298,31 +298,29 @@ export class ModelLoader {
|
|
|
298
298
|
this.staged.add(entry);
|
|
299
299
|
|
|
300
300
|
const nextTick = createResolvablePromise<void>();
|
|
301
|
-
|
|
301
|
+
this.tick.then(() => {
|
|
302
302
|
this.staged.delete(entry);
|
|
303
303
|
|
|
304
304
|
for (const [model, { resolve, reject }] of entry.models) {
|
|
305
305
|
if (this.delegate.findUniqueOrThrow) {
|
|
306
|
-
|
|
306
|
+
this.delegate
|
|
307
307
|
.findUniqueOrThrow({
|
|
308
308
|
...selectionToQuery(state),
|
|
309
309
|
where: { ...(this.findUnique(model as Record<string, unknown>, this.context) as {}) },
|
|
310
310
|
} as never)
|
|
311
|
-
// eslint-disable-next-line promise/no-nesting
|
|
312
311
|
.then(resolve as () => {}, reject);
|
|
313
312
|
} else {
|
|
314
|
-
|
|
313
|
+
this.delegate
|
|
315
314
|
.findUnique({
|
|
316
315
|
rejectOnNotFound: true,
|
|
317
316
|
...selectionToQuery(state),
|
|
318
317
|
where: { ...(this.findUnique(model as Record<string, unknown>, this.context) as {}) },
|
|
319
318
|
} as never)
|
|
320
|
-
// eslint-disable-next-line promise/no-nesting
|
|
321
319
|
.then(resolve as () => {}, reject);
|
|
322
320
|
}
|
|
323
321
|
}
|
|
324
322
|
});
|
|
325
|
-
setTimeout(() =>
|
|
323
|
+
setTimeout(() => nextTick.resolve(), 0);
|
|
326
324
|
this.tick = nextTick.promise;
|
|
327
325
|
|
|
328
326
|
return promise.promise;
|
package/src/node-ref.ts
CHANGED
package/src/object-ref.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ObjectRef,
|
|
3
|
+
type SchemaTypes,
|
|
2
4
|
abstractReturnShapeKey,
|
|
3
5
|
brandWithType,
|
|
4
|
-
ObjectRef,
|
|
5
|
-
SchemaTypes,
|
|
6
6
|
typeBrandKey,
|
|
7
7
|
} from '@pothos/core';
|
|
8
8
|
import type { PrismaModelTypes, WithBrand } from './types';
|
|
@@ -30,7 +30,9 @@ export class PrismaObjectRef<
|
|
|
30
30
|
value: V,
|
|
31
31
|
): V extends T[] ? { [K in keyof V]: WithBrand<V[K]> } : WithBrand<V> {
|
|
32
32
|
if (Array.isArray(value)) {
|
|
33
|
-
|
|
33
|
+
for (const val of value) {
|
|
34
|
+
brandWithType(val, this.name as never);
|
|
35
|
+
}
|
|
34
36
|
|
|
35
37
|
return value as never;
|
|
36
38
|
}
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
/* eslint-disable no-nested-ternary */
|
|
2
|
-
/* eslint-disable no-underscore-dangle */
|
|
3
1
|
import {
|
|
4
|
-
|
|
2
|
+
type CompatibleTypes,
|
|
3
|
+
type ExposeNullability,
|
|
4
|
+
type FieldKind,
|
|
5
|
+
type FieldRef,
|
|
6
|
+
type InferredFieldOptionKeys,
|
|
7
|
+
type InputFieldMap,
|
|
8
|
+
type InterfaceParam,
|
|
9
|
+
type MaybePromise,
|
|
10
|
+
type NormalizeArgs,
|
|
11
|
+
ObjectRef,
|
|
12
|
+
type PluginName,
|
|
13
|
+
RootFieldBuilder,
|
|
14
|
+
type SchemaTypes,
|
|
15
|
+
type ShapeFromTypeParam,
|
|
16
|
+
type TypeParam,
|
|
17
|
+
isThenable,
|
|
18
|
+
} from '@pothos/core';
|
|
19
|
+
import {
|
|
20
|
+
type FieldNode,
|
|
21
|
+
type GraphQLResolveInfo,
|
|
22
|
+
Kind,
|
|
5
23
|
getNamedType,
|
|
6
|
-
GraphQLResolveInfo,
|
|
7
24
|
isInterfaceType,
|
|
8
25
|
isObjectType,
|
|
9
|
-
Kind,
|
|
10
26
|
} from 'graphql';
|
|
11
|
-
import {
|
|
12
|
-
CompatibleTypes,
|
|
13
|
-
ExposeNullability,
|
|
14
|
-
FieldKind,
|
|
15
|
-
FieldRef,
|
|
16
|
-
InferredFieldOptionKeys,
|
|
17
|
-
InputFieldMap,
|
|
18
|
-
InterfaceParam,
|
|
19
|
-
isThenable,
|
|
20
|
-
MaybePromise,
|
|
21
|
-
NormalizeArgs,
|
|
22
|
-
ObjectRef,
|
|
23
|
-
PluginName,
|
|
24
|
-
RootFieldBuilder,
|
|
25
|
-
SchemaTypes,
|
|
26
|
-
ShapeFromTypeParam,
|
|
27
|
-
TypeParam,
|
|
28
|
-
} from '@pothos/core';
|
|
29
|
-
import { PrismaRef } from './interface-ref';
|
|
27
|
+
import type { PrismaRef } from './interface-ref';
|
|
30
28
|
import { ModelLoader } from './model-loader';
|
|
31
|
-
import {
|
|
29
|
+
import type {
|
|
32
30
|
PrismaConnectionShape,
|
|
33
31
|
PrismaModelTypes,
|
|
34
32
|
RelatedConnectionOptions,
|
|
@@ -47,11 +45,11 @@ import {
|
|
|
47
45
|
} from './util/cursors';
|
|
48
46
|
import { getRefFromModel, getRelation } from './util/datamodel';
|
|
49
47
|
import { getFieldDescription } from './util/description';
|
|
50
|
-
import { FieldMap } from './util/relation-map';
|
|
48
|
+
import type { FieldMap } from './util/relation-map';
|
|
51
49
|
|
|
52
50
|
// Workaround for FieldKind not being extended on Builder classes
|
|
53
51
|
const RootBuilder: {
|
|
54
|
-
//
|
|
52
|
+
// biome-ignore lint/suspicious/noRedeclare: <explanation>
|
|
55
53
|
new <Types extends SchemaTypes, Shape, Kind extends FieldKind>(
|
|
56
54
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
57
55
|
kind: FieldKind,
|
|
@@ -59,21 +57,26 @@ const RootBuilder: {
|
|
|
59
57
|
): PothosSchemaTypes.RootFieldBuilder<Types, Shape, Kind>;
|
|
60
58
|
} = RootFieldBuilder as never;
|
|
61
59
|
|
|
62
|
-
type ContextForAuth<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
: object;
|
|
70
|
-
|
|
71
|
-
type FieldAuthScopes<Types extends SchemaTypes, Parent, Args extends {} = {}> =
|
|
72
|
-
PothosSchemaTypes.ScopeAuthFieldAuthScopes<Types, Parent, Args> extends {
|
|
73
|
-
Scopes: infer T;
|
|
74
|
-
}
|
|
60
|
+
type ContextForAuth<
|
|
61
|
+
Types extends SchemaTypes,
|
|
62
|
+
Scopes extends {} = {},
|
|
63
|
+
> = PothosSchemaTypes.ScopeAuthContextForAuth<Types, Scopes> extends {
|
|
64
|
+
Context: infer T;
|
|
65
|
+
}
|
|
66
|
+
? T extends object
|
|
75
67
|
? T
|
|
76
|
-
:
|
|
68
|
+
: object
|
|
69
|
+
: object;
|
|
70
|
+
|
|
71
|
+
type FieldAuthScopes<
|
|
72
|
+
Types extends SchemaTypes,
|
|
73
|
+
Parent,
|
|
74
|
+
Args extends {} = {},
|
|
75
|
+
> = PothosSchemaTypes.ScopeAuthFieldAuthScopes<Types, Parent, Args> extends {
|
|
76
|
+
Scopes: infer T;
|
|
77
|
+
}
|
|
78
|
+
? T
|
|
79
|
+
: never;
|
|
77
80
|
|
|
78
81
|
export class PrismaObjectFieldBuilder<
|
|
79
82
|
Types extends SchemaTypes,
|
|
@@ -285,7 +288,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
285
288
|
const relationSelect = (
|
|
286
289
|
args: object,
|
|
287
290
|
context: object,
|
|
288
|
-
nestedQuery: (query: unknown, path?: unknown) => { select?:
|
|
291
|
+
nestedQuery: (query: unknown, path?: unknown) => { select?: object },
|
|
289
292
|
getSelection: (path: string[]) => FieldNode | null,
|
|
290
293
|
) => {
|
|
291
294
|
typeName ??= this.builder.configStore.getTypeConfig(ref).name;
|
|
@@ -407,7 +410,7 @@ export class PrismaObjectFieldBuilder<
|
|
|
407
410
|
extensions: {
|
|
408
411
|
pothosPrismaTotalCount: true,
|
|
409
412
|
},
|
|
410
|
-
resolve: (parent,
|
|
413
|
+
resolve: (parent, _args, _context) => parent.totalCount,
|
|
411
414
|
}),
|
|
412
415
|
...(connectionOptions as { fields?: (t: unknown) => {} }).fields?.(t),
|
|
413
416
|
})
|
|
@@ -454,8 +457,8 @@ export class PrismaObjectFieldBuilder<
|
|
|
454
457
|
const { query = {}, resolve, extensions, onNull, ...rest } = options;
|
|
455
458
|
|
|
456
459
|
const relationSelect = (
|
|
457
|
-
|
|
458
|
-
|
|
460
|
+
_args: object,
|
|
461
|
+
_context: object,
|
|
459
462
|
nestedQuery: (query: unknown) => unknown,
|
|
460
463
|
) => ({ select: { [name]: nestedQuery(query) } });
|
|
461
464
|
|
|
@@ -527,13 +530,14 @@ export class PrismaObjectFieldBuilder<
|
|
|
527
530
|
type: 'Int',
|
|
528
531
|
nullable: false,
|
|
529
532
|
select: countSelect as never,
|
|
530
|
-
resolve: (parent,
|
|
533
|
+
resolve: (parent, _args, _context, _info) =>
|
|
531
534
|
(parent as unknown as { _count: Record<string, never> })._count?.[name],
|
|
532
535
|
}) as FieldRef<Types, number, 'Object'>;
|
|
533
536
|
}
|
|
534
537
|
|
|
535
538
|
variant<
|
|
536
|
-
|
|
539
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
540
|
+
Variant extends Model['Name'] | PrismaRef<any, Model>,
|
|
537
541
|
Args extends InputFieldMap,
|
|
538
542
|
Nullable,
|
|
539
543
|
>(
|
|
@@ -543,7 +547,8 @@ export class PrismaObjectFieldBuilder<
|
|
|
543
547
|
options: VariantFieldOptions<
|
|
544
548
|
Types,
|
|
545
549
|
Model,
|
|
546
|
-
|
|
550
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
551
|
+
Variant extends PrismaRef<any, Model> ? Variant : PrismaRef<Types, Model>,
|
|
547
552
|
Args,
|
|
548
553
|
Nullable,
|
|
549
554
|
Shape
|
|
@@ -555,8 +560,11 @@ export class PrismaObjectFieldBuilder<
|
|
|
555
560
|
const ref: PrismaRef<Types, PrismaModelTypes> =
|
|
556
561
|
typeof variant === 'string' ? getRefFromModel(variant, this.builder) : variant;
|
|
557
562
|
|
|
558
|
-
const selfSelect = (
|
|
559
|
-
|
|
563
|
+
const selfSelect = (
|
|
564
|
+
_args: object,
|
|
565
|
+
_context: object,
|
|
566
|
+
nestedQuery: (query: unknown) => unknown,
|
|
567
|
+
) => nestedQuery({});
|
|
560
568
|
|
|
561
569
|
return this.field({
|
|
562
570
|
...(options as {}),
|
|
@@ -680,7 +688,6 @@ function addScopes(
|
|
|
680
688
|
) {
|
|
681
689
|
const originalCreateField = builder.createField;
|
|
682
690
|
|
|
683
|
-
// eslint-disable-next-line no-param-reassign
|
|
684
691
|
builder.createField = function createField(options) {
|
|
685
692
|
return originalCreateField.call(this, {
|
|
686
693
|
authScopes: scopes,
|
package/src/schema-builder.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import './global-types';
|
|
2
|
-
import { GraphQLResolveInfo } from 'graphql';
|
|
3
2
|
import SchemaBuilder, {
|
|
4
3
|
brandWithType,
|
|
5
4
|
completeValue,
|
|
6
|
-
FieldRef,
|
|
7
|
-
InterfaceRef,
|
|
8
|
-
OutputType,
|
|
5
|
+
type FieldRef,
|
|
6
|
+
type InterfaceRef,
|
|
7
|
+
type OutputType,
|
|
9
8
|
PothosError,
|
|
10
|
-
SchemaTypes,
|
|
9
|
+
type SchemaTypes,
|
|
11
10
|
} from '@pothos/core';
|
|
11
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
12
12
|
import { PrismaInterfaceRef } from './interface-ref';
|
|
13
13
|
import { ModelLoader } from './model-loader';
|
|
14
14
|
import { PrismaNodeRef } from './node-ref';
|
|
15
15
|
import { PrismaObjectRef } from './object-ref';
|
|
16
16
|
import { PrismaObjectFieldBuilder } from './prisma-field-builder';
|
|
17
|
-
import { PrismaModelTypes, PrismaNodeOptions } from './types';
|
|
17
|
+
import type { PrismaModelTypes, PrismaNodeOptions } from './types';
|
|
18
18
|
import { getDefaultIDParser, getDefaultIDSerializer } from './util/cursors';
|
|
19
19
|
import { getDelegateFromModel, getRefFromModel } from './util/datamodel';
|
|
20
20
|
import { getModelDescription } from './util/description';
|
|
@@ -187,12 +187,12 @@ schemaBuilderProto.prismaNode = function prismaNode(
|
|
|
187
187
|
globalID: (options: Record<string, unknown>) => FieldRef<SchemaTypes, unknown>;
|
|
188
188
|
}
|
|
189
189
|
).globalID({
|
|
190
|
-
...(this.options as { relayOptions?: { idFieldOptions?:
|
|
190
|
+
...(this.options as { relayOptions?: { idFieldOptions?: object } }).relayOptions
|
|
191
191
|
?.idFieldOptions,
|
|
192
192
|
...idOptions,
|
|
193
193
|
nullable: false,
|
|
194
194
|
args: {},
|
|
195
|
-
resolve: (parent: never,
|
|
195
|
+
resolve: (parent: never, _args: object, context: object) =>
|
|
196
196
|
completeValue(resolve(parent, context), (id) => ({
|
|
197
197
|
type: nodeConfig.name,
|
|
198
198
|
id,
|