@pothos/plugin-prisma 4.1.0 → 4.2.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 +10 -4
- package/dts/connection-helpers.d.ts +2 -2
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/global-types.d.ts +7 -7
- 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 +4 -4
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +7 -7
- 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 +7 -7
- 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 +4 -4
- 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 +7 -7
- 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 +31 -26
- 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 +54 -49
- package/src/schema-builder.ts +8 -8
- package/src/types.ts +58 -59
- 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/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,6 +293,7 @@ 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,
|
|
@@ -356,10 +358,11 @@ declare global {
|
|
|
356
358
|
prismaFieldWithInput: 'withInput' extends PluginName
|
|
357
359
|
? <
|
|
358
360
|
Fields extends InputFieldMap,
|
|
359
|
-
TypeParam extends
|
|
361
|
+
TypeParam extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
360
362
|
| PrismaRef<any, PrismaModelTypes>
|
|
361
363
|
| keyof Types['PrismaTypes']
|
|
362
364
|
| [keyof Types['PrismaTypes']]
|
|
365
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
363
366
|
| [PrismaRef<any, PrismaModelTypes>],
|
|
364
367
|
Type extends TypeParam extends [unknown]
|
|
365
368
|
? [ObjectRef<Types, Model['Shape']>]
|
|
@@ -373,9 +376,11 @@ declare global {
|
|
|
373
376
|
Model extends PrismaModelTypes = PrismaModelTypes &
|
|
374
377
|
(TypeParam extends [keyof Types['PrismaTypes']]
|
|
375
378
|
? Types['PrismaTypes'][TypeParam[0]]
|
|
376
|
-
:
|
|
379
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
380
|
+
TypeParam extends [PrismaRef<any, PrismaModelTypes>]
|
|
377
381
|
? TypeParam[0][typeof prismaModelKey]
|
|
378
|
-
:
|
|
382
|
+
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
383
|
+
TypeParam extends PrismaRef<any, PrismaModelTypes>
|
|
379
384
|
? TypeParam[typeof prismaModelKey]
|
|
380
385
|
: TypeParam extends keyof Types['PrismaTypes']
|
|
381
386
|
? 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,7 +530,7 @@ 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
|
}
|
|
@@ -555,8 +558,11 @@ export class PrismaObjectFieldBuilder<
|
|
|
555
558
|
const ref: PrismaRef<Types, PrismaModelTypes> =
|
|
556
559
|
typeof variant === 'string' ? getRefFromModel(variant, this.builder) : variant;
|
|
557
560
|
|
|
558
|
-
const selfSelect = (
|
|
559
|
-
|
|
561
|
+
const selfSelect = (
|
|
562
|
+
_args: object,
|
|
563
|
+
_context: object,
|
|
564
|
+
nestedQuery: (query: unknown) => unknown,
|
|
565
|
+
) => nestedQuery({});
|
|
560
566
|
|
|
561
567
|
return this.field({
|
|
562
568
|
...(options as {}),
|
|
@@ -680,7 +686,6 @@ function addScopes(
|
|
|
680
686
|
) {
|
|
681
687
|
const originalCreateField = builder.createField;
|
|
682
688
|
|
|
683
|
-
// eslint-disable-next-line no-param-reassign
|
|
684
689
|
builder.createField = function createField(options) {
|
|
685
690
|
return originalCreateField.call(this, {
|
|
686
691
|
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,
|