@pothos/plugin-prisma 3.65.3 → 4.0.0-next.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 +21 -4
- package/README.md +3 -5
- package/dts/connection-helpers.d.ts +10 -10
- package/dts/connection-helpers.d.ts.map +1 -1
- package/dts/global-types.d.ts +25 -25
- 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 +3 -3
- package/dts/interface-ref.d.ts.map +1 -1
- package/dts/model-loader.d.ts +6 -6
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/node-ref.d.ts +2 -1
- package/dts/node-ref.d.ts.map +1 -1
- package/dts/object-ref.d.ts +2 -2
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/prisma-field-builder.d.ts +69 -53
- package/dts/prisma-field-builder.d.ts.map +1 -1
- package/dts/types.d.ts +81 -55
- package/dts/types.d.ts.map +1 -1
- package/dts/util/cursors.d.ts.map +1 -1
- package/dts/util/datamodel.d.ts +5 -5
- package/dts/util/datamodel.d.ts.map +1 -1
- 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/esm/connection-helpers.d.ts +7 -7
- package/esm/connection-helpers.d.ts.map +1 -1
- package/esm/connection-helpers.js.map +1 -1
- package/esm/field-builder.js.map +1 -1
- package/esm/generator.js +69 -29
- package/esm/generator.js.map +1 -1
- package/esm/global-types.d.ts +36 -36
- package/esm/global-types.d.ts.map +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 +13 -2
- package/esm/index.js.map +1 -1
- package/esm/interface-ref.d.ts +3 -3
- package/esm/interface-ref.d.ts.map +1 -1
- package/esm/interface-ref.js.map +1 -1
- package/esm/model-loader.d.ts +6 -6
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +2 -1
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/node-ref.js.map +1 -1
- package/esm/object-ref.d.ts +2 -2
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/object-ref.js.map +1 -1
- package/esm/prisma-field-builder.d.ts +74 -58
- package/esm/prisma-field-builder.d.ts.map +1 -1
- package/esm/prisma-field-builder.js +14 -5
- package/esm/prisma-field-builder.js.map +1 -1
- package/esm/schema-builder.js +3 -3
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +82 -58
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/util/cursors.d.ts.map +1 -1
- package/esm/util/cursors.js.map +1 -1
- package/esm/util/datamodel.d.ts +5 -5
- package/esm/util/datamodel.d.ts.map +1 -1
- package/esm/util/datamodel.js.map +1 -1
- package/esm/util/deep-equal.js.map +1 -1
- package/esm/util/description.js.map +1 -1
- package/esm/util/get-client.js.map +1 -1
- package/esm/util/loader-map.js.map +1 -1
- package/esm/util/map-query.d.ts.map +1 -1
- package/esm/util/map-query.js +3 -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.map +1 -1
- package/esm/util/selections.js.map +1 -1
- package/esm/util/usage.js.map +1 -1
- package/lib/connection-helpers.js.map +1 -1
- package/lib/field-builder.js.map +1 -1
- package/lib/generator.js +68 -26
- package/lib/generator.js.map +1 -1
- package/lib/global-types.js.map +1 -1
- package/lib/index.js +16 -5
- package/lib/index.js.map +1 -1
- package/lib/interface-ref.js.map +1 -1
- package/lib/model-loader.js.map +1 -1
- package/lib/node-ref.js.map +1 -1
- package/lib/object-ref.js.map +1 -1
- package/lib/prisma-field-builder.js +14 -5
- package/lib/prisma-field-builder.js.map +1 -1
- package/lib/schema-builder.js +3 -3
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/util/cursors.js.map +1 -1
- package/lib/util/datamodel.js.map +1 -1
- package/lib/util/deep-equal.js.map +1 -1
- package/lib/util/description.js.map +1 -1
- package/lib/util/get-client.js.map +1 -1
- package/lib/util/loader-map.js.map +1 -1
- package/lib/util/map-query.js +1 -1
- package/lib/util/map-query.js.map +1 -1
- package/lib/util/relation-map.js.map +1 -1
- package/lib/util/selections.js.map +1 -1
- package/lib/util/usage.js.map +1 -1
- package/package.json +18 -16
- package/src/connection-helpers.ts +7 -6
- package/src/field-builder.ts +12 -11
- package/src/generator.ts +125 -25
- package/src/global-types.ts +61 -55
- package/src/index.ts +11 -5
- package/src/interface-ref.ts +9 -5
- package/src/model-loader.ts +6 -6
- package/src/node-ref.ts +6 -1
- package/src/object-ref.ts +12 -2
- package/src/prisma-field-builder.ts +101 -74
- package/src/schema-builder.ts +10 -7
- package/src/types.ts +186 -184
- package/src/util/datamodel.ts +5 -5
- package/src/util/map-query.ts +2 -3
package/src/generator.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/* eslint-disable unicorn/prefer-module */
|
|
2
2
|
/* eslint-disable no-magic-numbers */
|
|
3
3
|
/* eslint-disable no-nested-ternary */
|
|
4
|
-
import {
|
|
4
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { dirname, join, resolve as resolvePath, posix } from 'node:path';
|
|
6
6
|
import ts, { ListFormat, ScriptKind, ScriptTarget, SyntaxKind, version } from 'typescript';
|
|
7
7
|
import { DMMF, generatorHandler } from '@prisma/generator-helper';
|
|
8
|
+
import { PothosPrismaDatamodel } from './types';
|
|
8
9
|
|
|
9
10
|
const MIN_TS_VERSION = [4, 5, 2];
|
|
10
11
|
|
|
@@ -26,7 +27,15 @@ function checkTSVersion() {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
const defaultOutput = resolvePath(__dirname, '../generated.ts');
|
|
30
|
+
const defaultOutput = resolvePath(__dirname, '../generated.d.ts');
|
|
31
|
+
|
|
32
|
+
interface GeneratorConfig {
|
|
33
|
+
clientOutput?: string;
|
|
34
|
+
prismaUtils?: string;
|
|
35
|
+
pluginPath?: string;
|
|
36
|
+
generateDatamodel?: string;
|
|
37
|
+
documentation?: string;
|
|
38
|
+
}
|
|
30
39
|
|
|
31
40
|
generatorHandler({
|
|
32
41
|
onManifest: () => ({
|
|
@@ -36,7 +45,7 @@ generatorHandler({
|
|
|
36
45
|
}),
|
|
37
46
|
onGenerate: async (options) => {
|
|
38
47
|
checkTSVersion();
|
|
39
|
-
const config = options.generator.config as
|
|
48
|
+
const config = options.generator.config as GeneratorConfig;
|
|
40
49
|
const prismaLocation =
|
|
41
50
|
config.clientOutput ??
|
|
42
51
|
options.otherGenerators.find((gen) => gen.provider.value === 'prisma-client-js')!.output!
|
|
@@ -45,26 +54,74 @@ generatorHandler({
|
|
|
45
54
|
const outputLocation = options.generator.output?.value ?? defaultOutput;
|
|
46
55
|
const prismaTypes = buildTypes(options.dmmf, config);
|
|
47
56
|
|
|
48
|
-
await generateOutput(
|
|
57
|
+
await generateOutput(
|
|
58
|
+
options.dmmf,
|
|
59
|
+
prismaTypes,
|
|
60
|
+
prismaLocation,
|
|
61
|
+
outputLocation,
|
|
62
|
+
config,
|
|
63
|
+
outputLocation === defaultOutput ? 'cjs' : 'ts',
|
|
64
|
+
);
|
|
49
65
|
|
|
50
66
|
if (outputLocation === defaultOutput) {
|
|
51
67
|
await generateOutput(
|
|
52
68
|
options.dmmf,
|
|
53
69
|
prismaTypes,
|
|
54
70
|
prismaLocation.startsWith('@') ? prismaLocation : posix.join(prismaLocation, 'index.js'),
|
|
55
|
-
join(outputLocation, '../esm/generated.ts'),
|
|
71
|
+
join(outputLocation, '../esm/generated.d.ts'),
|
|
72
|
+
config,
|
|
73
|
+
'esm',
|
|
56
74
|
);
|
|
57
75
|
}
|
|
58
76
|
},
|
|
59
77
|
});
|
|
60
78
|
|
|
79
|
+
function trimDmmf(dmmf: DMMF.Document, documentation = false): PothosPrismaDatamodel {
|
|
80
|
+
const trimmed: PothosPrismaDatamodel = {
|
|
81
|
+
datamodel: {
|
|
82
|
+
models: {},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
dmmf.datamodel.models.forEach((model) => {
|
|
87
|
+
trimmed.datamodel.models[model.name] = {
|
|
88
|
+
fields: model.fields.map((field) => ({
|
|
89
|
+
type: field.type,
|
|
90
|
+
kind: field.kind,
|
|
91
|
+
name: field.name,
|
|
92
|
+
isRequired: field.isRequired,
|
|
93
|
+
isList: field.isList,
|
|
94
|
+
hasDefaultValue: field.hasDefaultValue,
|
|
95
|
+
isUnique: field.isUnique,
|
|
96
|
+
isId: field.isId,
|
|
97
|
+
relationName: field.relationName,
|
|
98
|
+
relationFromFields: field.relationFromFields,
|
|
99
|
+
isUpdatedAt: field.isUpdatedAt,
|
|
100
|
+
documentation: documentation ? field.documentation : undefined,
|
|
101
|
+
})),
|
|
102
|
+
primaryKey: model.primaryKey
|
|
103
|
+
? { name: model.primaryKey.name, fields: model.primaryKey.fields }
|
|
104
|
+
: null,
|
|
105
|
+
uniqueIndexes: model.uniqueIndexes.map((index) => ({
|
|
106
|
+
name: index.name,
|
|
107
|
+
fields: index.fields,
|
|
108
|
+
})),
|
|
109
|
+
documentation: documentation ? model.documentation : undefined,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return trimmed;
|
|
114
|
+
}
|
|
115
|
+
|
|
61
116
|
async function generateOutput(
|
|
62
117
|
dmmf: DMMF.Document,
|
|
63
118
|
prismaTypes: ts.InterfaceDeclaration,
|
|
64
119
|
prismaLocation: string,
|
|
65
120
|
outputLocation: string,
|
|
121
|
+
config: GeneratorConfig,
|
|
122
|
+
datamodel: 'esm' | 'cjs' | 'ts' = 'ts',
|
|
66
123
|
) {
|
|
67
|
-
const
|
|
124
|
+
const prismaImportStatement = ts.factory.createImportDeclaration(
|
|
68
125
|
...modifiersArg,
|
|
69
126
|
[],
|
|
70
127
|
ts.factory.createImportClause(
|
|
@@ -84,6 +141,23 @@ async function generateOutput(
|
|
|
84
141
|
ts.factory.createStringLiteral(prismaLocation),
|
|
85
142
|
);
|
|
86
143
|
|
|
144
|
+
const dmmfImportStatement = ts.factory.createImportDeclaration(
|
|
145
|
+
...modifiersArg,
|
|
146
|
+
[],
|
|
147
|
+
ts.factory.createImportClause(
|
|
148
|
+
true,
|
|
149
|
+
undefined,
|
|
150
|
+
ts.factory.createNamedImports([
|
|
151
|
+
ts.factory.createImportSpecifier(
|
|
152
|
+
false,
|
|
153
|
+
undefined,
|
|
154
|
+
ts.factory.createIdentifier('PothosPrismaDatamodel'),
|
|
155
|
+
),
|
|
156
|
+
]),
|
|
157
|
+
),
|
|
158
|
+
ts.factory.createStringLiteral(config.pluginPath ?? '@pothos/plugin-prisma'),
|
|
159
|
+
);
|
|
160
|
+
|
|
87
161
|
const printer = ts.createPrinter({});
|
|
88
162
|
|
|
89
163
|
const sourcefile = ts.createSourceFile(
|
|
@@ -94,29 +168,55 @@ async function generateOutput(
|
|
|
94
168
|
ScriptKind.TS,
|
|
95
169
|
);
|
|
96
170
|
|
|
97
|
-
const
|
|
171
|
+
const trimmedDatamodel = trimDmmf(dmmf, config.documentation === 'true');
|
|
172
|
+
|
|
173
|
+
const dmmfExport = ts.factory.createFunctionDeclaration(
|
|
174
|
+
[ts.factory.createModifier(SyntaxKind.ExportKeyword)],
|
|
175
|
+
undefined,
|
|
176
|
+
'getDatamodel',
|
|
177
|
+
[],
|
|
178
|
+
[],
|
|
179
|
+
ts.factory.createTypeReferenceNode('PothosPrismaDatamodel'),
|
|
180
|
+
outputLocation.endsWith('.d.ts')
|
|
181
|
+
? undefined
|
|
182
|
+
: ts.factory.createBlock([
|
|
183
|
+
ts.factory.createReturnStatement(
|
|
184
|
+
ts.factory.createCallExpression(
|
|
185
|
+
ts.factory.createPropertyAccessExpression(
|
|
186
|
+
ts.factory.createIdentifier('JSON'),
|
|
187
|
+
'parse',
|
|
188
|
+
),
|
|
189
|
+
[],
|
|
190
|
+
[ts.factory.createStringLiteral(JSON.stringify(trimmedDatamodel))],
|
|
191
|
+
),
|
|
192
|
+
),
|
|
193
|
+
]),
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const nodes = ts.factory.createNodeArray(
|
|
197
|
+
config.generateDatamodel === 'true' && datamodel === 'ts'
|
|
198
|
+
? [prismaImportStatement, dmmfImportStatement, prismaTypes, dmmfExport]
|
|
199
|
+
: [prismaImportStatement, prismaTypes],
|
|
200
|
+
);
|
|
98
201
|
|
|
99
202
|
const result = printer.printList(ListFormat.SourceFileStatements, nodes, sourcefile);
|
|
100
203
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (err) {
|
|
104
|
-
reject(err);
|
|
105
|
-
} else {
|
|
106
|
-
resolve();
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
204
|
+
mkdirSync(dirname(sourcefile.fileName), { recursive: true });
|
|
205
|
+
writeFileSync(sourcefile.fileName, `/* eslint-disable */\n${result}`);
|
|
110
206
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
207
|
+
if (config.generateDatamodel === 'true' && datamodel === 'cjs') {
|
|
208
|
+
writeFileSync(
|
|
209
|
+
outputLocation.replace(/\.ts$/, '.js'),
|
|
210
|
+
`/* eslint-disable */\nmodule.exports = { getDatamodel: () => JSON.parse(${JSON.stringify(JSON.stringify(trimmedDatamodel))}) }\n`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (config.generateDatamodel === 'true' && datamodel === 'esm') {
|
|
215
|
+
writeFileSync(
|
|
216
|
+
outputLocation.replace(/\.ts$/, '.js'),
|
|
217
|
+
`/* eslint-disable */\nexport function getDatamodel() { return JSON.parse(${JSON.stringify(JSON.stringify(trimmedDatamodel))}) }\n`,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
120
220
|
}
|
|
121
221
|
|
|
122
222
|
function buildTypes(dmmf: DMMF.Document, config: { prismaUtils?: string }) {
|
package/src/global-types.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
FieldNullability,
|
|
8
8
|
FieldRef,
|
|
9
9
|
InputFieldMap,
|
|
10
|
-
InputFieldRef,
|
|
11
10
|
InterfaceParam,
|
|
12
11
|
NormalizeArgs,
|
|
13
12
|
OutputType,
|
|
@@ -36,12 +35,12 @@ import {
|
|
|
36
35
|
ShapeFromSelection,
|
|
37
36
|
} from './types';
|
|
38
37
|
|
|
39
|
-
import type {
|
|
38
|
+
import type { PothosPrismaPlugin } from '.';
|
|
40
39
|
|
|
41
40
|
declare global {
|
|
42
41
|
export namespace PothosSchemaTypes {
|
|
43
42
|
export interface Plugins<Types extends SchemaTypes> {
|
|
44
|
-
prisma:
|
|
43
|
+
prisma: PothosPrismaPlugin<Types>;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
export interface SchemaBuilderOptions<Types extends SchemaTypes> {
|
|
@@ -111,7 +110,6 @@ declare global {
|
|
|
111
110
|
prismaObject: <
|
|
112
111
|
Name extends keyof Types['PrismaTypes'],
|
|
113
112
|
Interfaces extends InterfaceParam<Types>[],
|
|
114
|
-
FindUnique,
|
|
115
113
|
Model extends PrismaModelTypes & Types['PrismaTypes'][Name],
|
|
116
114
|
Include = unknown,
|
|
117
115
|
Select = unknown,
|
|
@@ -121,12 +119,12 @@ declare global {
|
|
|
121
119
|
Types,
|
|
122
120
|
Model,
|
|
123
121
|
Interfaces,
|
|
124
|
-
FindUnique,
|
|
125
122
|
Include,
|
|
126
123
|
Select,
|
|
127
124
|
ShapeFromSelection<Types, Model, { select: Select; include: Include }>
|
|
128
125
|
>,
|
|
129
126
|
) => PrismaObjectRef<
|
|
127
|
+
Types,
|
|
130
128
|
Model,
|
|
131
129
|
ShapeFromSelection<Types, Model, { select: Select; include: Include }>
|
|
132
130
|
>;
|
|
@@ -134,7 +132,6 @@ declare global {
|
|
|
134
132
|
prismaInterface: <
|
|
135
133
|
Name extends keyof Types['PrismaTypes'],
|
|
136
134
|
Interfaces extends InterfaceParam<Types>[],
|
|
137
|
-
FindUnique,
|
|
138
135
|
Model extends PrismaModelTypes & Types['PrismaTypes'][Name],
|
|
139
136
|
Include = unknown,
|
|
140
137
|
Select = unknown,
|
|
@@ -144,22 +141,22 @@ declare global {
|
|
|
144
141
|
Types,
|
|
145
142
|
Model,
|
|
146
143
|
Interfaces,
|
|
147
|
-
FindUnique,
|
|
148
144
|
Include,
|
|
149
145
|
Select,
|
|
150
146
|
ShapeFromSelection<Types, Model, { select: Select; include: Include }>
|
|
151
147
|
>,
|
|
152
148
|
) => PrismaInterfaceRef<
|
|
149
|
+
Types,
|
|
153
150
|
Model,
|
|
154
151
|
ShapeFromSelection<Types, Model, { select: Select; include: Include }>
|
|
155
152
|
>;
|
|
156
153
|
|
|
157
154
|
prismaObjectField: <
|
|
158
|
-
Type extends PrismaObjectRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
159
|
-
Model extends PrismaModelTypes = Type extends PrismaObjectRef<infer M, {}>
|
|
155
|
+
Type extends PrismaObjectRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
156
|
+
Model extends PrismaModelTypes = Type extends PrismaObjectRef<Types, infer M, {}>
|
|
160
157
|
? M
|
|
161
158
|
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
|
|
162
|
-
Shape extends {} = Type extends PrismaObjectRef<PrismaModelTypes, infer S>
|
|
159
|
+
Shape extends {} = Type extends PrismaObjectRef<Types, PrismaModelTypes, infer S>
|
|
163
160
|
? S & { [prismaModelName]?: Model['Name'] }
|
|
164
161
|
: Model['Shape'] & {
|
|
165
162
|
[prismaModelName]?: Type;
|
|
@@ -167,15 +164,15 @@ declare global {
|
|
|
167
164
|
>(
|
|
168
165
|
type: Type,
|
|
169
166
|
fieldName: string,
|
|
170
|
-
field: (t: PrismaObjectFieldBuilder<Types, Model,
|
|
167
|
+
field: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldRef<Types>,
|
|
171
168
|
) => void;
|
|
172
169
|
|
|
173
170
|
prismaInterfaceField: <
|
|
174
|
-
Type extends PrismaInterfaceRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
175
|
-
Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<infer M, {}>
|
|
171
|
+
Type extends PrismaInterfaceRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
172
|
+
Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<Types, infer M, {}>
|
|
176
173
|
? M
|
|
177
174
|
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
|
|
178
|
-
Shape extends {} = Type extends PrismaInterfaceRef<PrismaModelTypes, infer S>
|
|
175
|
+
Shape extends {} = Type extends PrismaInterfaceRef<Types, PrismaModelTypes, infer S>
|
|
179
176
|
? S & { [prismaModelName]?: Model['Name'] }
|
|
180
177
|
: Model['Shape'] & {
|
|
181
178
|
[prismaModelName]?: Type;
|
|
@@ -183,37 +180,37 @@ declare global {
|
|
|
183
180
|
>(
|
|
184
181
|
type: Type,
|
|
185
182
|
fieldName: string,
|
|
186
|
-
field: (t: PrismaObjectFieldBuilder<Types, Model,
|
|
183
|
+
field: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldRef<Types>,
|
|
187
184
|
) => void;
|
|
188
185
|
|
|
189
186
|
prismaObjectFields: <
|
|
190
|
-
Type extends PrismaObjectRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
191
|
-
Model extends PrismaModelTypes = Type extends PrismaObjectRef<infer M, {}>
|
|
187
|
+
Type extends PrismaObjectRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
188
|
+
Model extends PrismaModelTypes = Type extends PrismaObjectRef<Types, infer M, {}>
|
|
192
189
|
? M
|
|
193
190
|
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
|
|
194
|
-
Shape extends {} = Type extends PrismaObjectRef<PrismaModelTypes, infer S>
|
|
191
|
+
Shape extends {} = Type extends PrismaObjectRef<Types, PrismaModelTypes, infer S>
|
|
195
192
|
? S & { [prismaModelName]?: Model['Name'] }
|
|
196
193
|
: Model['Shape'] & {
|
|
197
194
|
[prismaModelName]?: Type;
|
|
198
195
|
},
|
|
199
196
|
>(
|
|
200
197
|
type: Type,
|
|
201
|
-
fields: (t: PrismaObjectFieldBuilder<Types, Model,
|
|
198
|
+
fields: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldMap,
|
|
202
199
|
) => void;
|
|
203
200
|
|
|
204
201
|
prismaInterfaceFields: <
|
|
205
|
-
Type extends PrismaInterfaceRef<PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
206
|
-
Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<infer M, {}>
|
|
202
|
+
Type extends PrismaInterfaceRef<Types, PrismaModelTypes, {}> | keyof Types['PrismaTypes'],
|
|
203
|
+
Model extends PrismaModelTypes = Type extends PrismaInterfaceRef<Types, infer M, {}>
|
|
207
204
|
? M
|
|
208
205
|
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
|
|
209
|
-
Shape extends {} = Type extends PrismaInterfaceRef<PrismaModelTypes, infer S>
|
|
206
|
+
Shape extends {} = Type extends PrismaInterfaceRef<Types, PrismaModelTypes, infer S>
|
|
210
207
|
? S & { [prismaModelName]?: Model['Name'] }
|
|
211
208
|
: Model['Shape'] & {
|
|
212
209
|
[prismaModelName]?: Type;
|
|
213
210
|
},
|
|
214
211
|
>(
|
|
215
212
|
type: Type,
|
|
216
|
-
fields: (t: PrismaObjectFieldBuilder<Types, Model,
|
|
213
|
+
fields: (t: PrismaObjectFieldBuilder<Types, Model, Shape>) => FieldMap,
|
|
217
214
|
) => void;
|
|
218
215
|
|
|
219
216
|
prismaNode: 'relay' extends PluginName
|
|
@@ -239,6 +236,7 @@ declare global {
|
|
|
239
236
|
UniqueField
|
|
240
237
|
>,
|
|
241
238
|
) => PrismaNodeRef<
|
|
239
|
+
Types,
|
|
242
240
|
PrismaModelTypes & Types['PrismaTypes'][Name],
|
|
243
241
|
ShapeFromSelection<
|
|
244
242
|
Types,
|
|
@@ -257,22 +255,22 @@ declare global {
|
|
|
257
255
|
prismaField: <
|
|
258
256
|
Args extends InputFieldMap,
|
|
259
257
|
TypeParam extends
|
|
260
|
-
| PrismaRef<PrismaModelTypes>
|
|
258
|
+
| PrismaRef<Types, PrismaModelTypes>
|
|
261
259
|
| keyof Types['PrismaTypes']
|
|
262
260
|
| [keyof Types['PrismaTypes']]
|
|
263
|
-
| [PrismaRef<PrismaModelTypes>],
|
|
261
|
+
| [PrismaRef<Types, PrismaModelTypes>],
|
|
264
262
|
Nullable extends FieldNullability<Type>,
|
|
265
263
|
ResolveShape,
|
|
266
264
|
ResolveReturnShape,
|
|
267
265
|
Type extends TypeParam extends [unknown]
|
|
268
|
-
? [ObjectRef<Model['Shape']>]
|
|
269
|
-
: ObjectRef<Model['Shape']>,
|
|
266
|
+
? [ObjectRef<Types, Model['Shape']>]
|
|
267
|
+
: ObjectRef<Types, Model['Shape']>,
|
|
270
268
|
Model extends PrismaModelTypes = PrismaModelTypes &
|
|
271
269
|
(TypeParam extends [keyof Types['PrismaTypes']]
|
|
272
270
|
? Types['PrismaTypes'][TypeParam[0]]
|
|
273
|
-
: TypeParam extends [PrismaRef<PrismaModelTypes>]
|
|
271
|
+
: TypeParam extends [PrismaRef<Types, PrismaModelTypes>]
|
|
274
272
|
? TypeParam[0][typeof prismaModelKey]
|
|
275
|
-
: TypeParam extends PrismaRef<PrismaModelTypes>
|
|
273
|
+
: TypeParam extends PrismaRef<Types, PrismaModelTypes>
|
|
276
274
|
? TypeParam[typeof prismaModelKey]
|
|
277
275
|
: TypeParam extends keyof Types['PrismaTypes']
|
|
278
276
|
? Types['PrismaTypes'][TypeParam]
|
|
@@ -290,18 +288,18 @@ declare global {
|
|
|
290
288
|
ResolveReturnShape,
|
|
291
289
|
Kind
|
|
292
290
|
>,
|
|
293
|
-
) => FieldRef<ShapeFromTypeParam<Types, Type, Nullable>>;
|
|
291
|
+
) => FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>>;
|
|
294
292
|
|
|
295
293
|
prismaConnection: 'relay' extends PluginName
|
|
296
294
|
? <
|
|
297
|
-
Type extends PrismaRef<PrismaModelTypes> | keyof Types['PrismaTypes'],
|
|
295
|
+
Type extends PrismaRef<Types, PrismaModelTypes> | keyof Types['PrismaTypes'],
|
|
298
296
|
Nullable extends boolean,
|
|
299
297
|
ResolveReturnShape,
|
|
300
298
|
Args extends InputFieldMap = {},
|
|
301
|
-
Model extends PrismaModelTypes = Type extends PrismaRef<infer T>
|
|
299
|
+
Model extends PrismaModelTypes = Type extends PrismaRef<Types, infer T>
|
|
302
300
|
? T
|
|
303
301
|
: PrismaModelTypes & Types['PrismaTypes'][Type & keyof Types['PrismaTypes']],
|
|
304
|
-
Shape = Type extends PrismaRef<PrismaModelTypes, infer S> ? S : Model['Shape'],
|
|
302
|
+
Shape = Type extends PrismaRef<Types, PrismaModelTypes, infer S> ? S : Model['Shape'],
|
|
305
303
|
ConnectionInterfaces extends InterfaceParam<Types>[] = [],
|
|
306
304
|
EdgeInterfaces extends InterfaceParam<Types>[] = [],
|
|
307
305
|
>(
|
|
@@ -310,7 +308,7 @@ declare global {
|
|
|
310
308
|
ParentShape,
|
|
311
309
|
Type,
|
|
312
310
|
Model,
|
|
313
|
-
ObjectRef<Model['Shape']>,
|
|
311
|
+
ObjectRef<Types, Model['Shape']>,
|
|
314
312
|
Nullable,
|
|
315
313
|
Args,
|
|
316
314
|
ResolveReturnShape,
|
|
@@ -321,54 +319,63 @@ declare global {
|
|
|
321
319
|
connectionOptions:
|
|
322
320
|
| ConnectionObjectOptions<
|
|
323
321
|
Types,
|
|
324
|
-
ObjectRef<Shape>,
|
|
322
|
+
ObjectRef<Types, Shape>,
|
|
325
323
|
false,
|
|
326
324
|
false,
|
|
327
325
|
PrismaConnectionShape<Types, Shape, ParentShape, Args>,
|
|
328
326
|
ConnectionInterfaces
|
|
329
327
|
>
|
|
330
|
-
| ObjectRef<
|
|
328
|
+
| ObjectRef<
|
|
329
|
+
Types,
|
|
330
|
+
ShapeFromConnection<ConnectionShapeHelper<Types, Shape, false>>
|
|
331
|
+
>,
|
|
331
332
|
edgeOptions:
|
|
332
333
|
| ConnectionEdgeObjectOptions<
|
|
333
334
|
Types,
|
|
334
|
-
ObjectRef<Shape>,
|
|
335
|
+
ObjectRef<Types, Shape>,
|
|
335
336
|
false,
|
|
336
337
|
PrismaConnectionShape<Types, Shape, ParentShape, Args>,
|
|
337
338
|
EdgeInterfaces
|
|
338
339
|
>
|
|
339
|
-
| ObjectRef<
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
340
|
+
| ObjectRef<
|
|
341
|
+
Types,
|
|
342
|
+
{
|
|
343
|
+
cursor: string;
|
|
344
|
+
node?: Shape | null | undefined;
|
|
345
|
+
}
|
|
346
|
+
>,
|
|
343
347
|
],
|
|
344
348
|
0
|
|
345
349
|
>
|
|
346
|
-
) => FieldRef<
|
|
350
|
+
) => FieldRef<
|
|
351
|
+
Types,
|
|
352
|
+
ShapeFromConnection<ConnectionShapeHelper<Types, Model['Shape'], Nullable>>
|
|
353
|
+
>
|
|
347
354
|
: '@pothos/plugin-relay is required to use this method';
|
|
348
355
|
|
|
349
356
|
prismaFieldWithInput: 'prisma' extends PluginName
|
|
350
357
|
? <
|
|
351
|
-
Fields extends
|
|
358
|
+
Fields extends InputFieldMap,
|
|
352
359
|
TypeParam extends
|
|
353
|
-
| PrismaRef<PrismaModelTypes>
|
|
360
|
+
| PrismaRef<Types, PrismaModelTypes>
|
|
354
361
|
| keyof Types['PrismaTypes']
|
|
355
362
|
| [keyof Types['PrismaTypes']]
|
|
356
|
-
| [PrismaRef<PrismaModelTypes>],
|
|
363
|
+
| [PrismaRef<Types, PrismaModelTypes>],
|
|
357
364
|
Type extends TypeParam extends [unknown]
|
|
358
|
-
? [ObjectRef<Model['Shape']>]
|
|
359
|
-
: ObjectRef<Model['Shape']>,
|
|
365
|
+
? [ObjectRef<Types, Model['Shape']>]
|
|
366
|
+
: ObjectRef<Types, Model['Shape']>,
|
|
360
367
|
ResolveShape,
|
|
361
368
|
ResolveReturnShape,
|
|
362
369
|
ArgRequired extends boolean,
|
|
363
|
-
Args extends
|
|
370
|
+
Args extends InputFieldMap = {},
|
|
364
371
|
Nullable extends FieldNullability<Type> = Types['DefaultFieldNullability'],
|
|
365
372
|
InputName extends string = 'input',
|
|
366
373
|
Model extends PrismaModelTypes = PrismaModelTypes &
|
|
367
374
|
(TypeParam extends [keyof Types['PrismaTypes']]
|
|
368
375
|
? Types['PrismaTypes'][TypeParam[0]]
|
|
369
|
-
: TypeParam extends [PrismaRef<PrismaModelTypes>]
|
|
376
|
+
: TypeParam extends [PrismaRef<Types, PrismaModelTypes>]
|
|
370
377
|
? TypeParam[0][typeof prismaModelKey]
|
|
371
|
-
: TypeParam extends PrismaRef<PrismaModelTypes>
|
|
378
|
+
: TypeParam extends PrismaRef<Types, PrismaModelTypes>
|
|
372
379
|
? TypeParam[typeof prismaModelKey]
|
|
373
380
|
: TypeParam extends keyof Types['PrismaTypes']
|
|
374
381
|
? Types['PrismaTypes'][TypeParam]
|
|
@@ -391,7 +398,7 @@ declare global {
|
|
|
391
398
|
? (Types & { WithInputArgRequired: boolean })['WithInputArgRequired']
|
|
392
399
|
: ArgRequired
|
|
393
400
|
>,
|
|
394
|
-
) => FieldRef<ShapeFromTypeParam<Types, Type, Nullable>>
|
|
401
|
+
) => FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>>
|
|
395
402
|
: '@pothos/plugin-prisma is required to use this method';
|
|
396
403
|
}
|
|
397
404
|
|
|
@@ -442,15 +449,14 @@ declare global {
|
|
|
442
449
|
export interface PrismaObjectFieldBuilder<
|
|
443
450
|
Types extends SchemaTypes,
|
|
444
451
|
Model extends PrismaModelTypes,
|
|
445
|
-
NeedsResolve extends boolean,
|
|
446
452
|
Shape extends object = Model['Shape'],
|
|
447
|
-
> extends InternalPrismaObjectFieldBuilder<Types, Model,
|
|
453
|
+
> extends InternalPrismaObjectFieldBuilder<Types, Model, Shape>,
|
|
448
454
|
RootFieldBuilder<Types, Shape, 'PrismaObject'> {}
|
|
449
455
|
|
|
450
456
|
export interface FieldWithInputBaseOptions<
|
|
451
457
|
Types extends SchemaTypes,
|
|
452
|
-
Args extends
|
|
453
|
-
Fields extends
|
|
458
|
+
Args extends InputFieldMap,
|
|
459
|
+
Fields extends InputFieldMap,
|
|
454
460
|
InputName extends string,
|
|
455
461
|
ArgRequired extends boolean,
|
|
456
462
|
> {}
|
package/src/index.ts
CHANGED
|
@@ -38,14 +38,13 @@ export type PrismaObjectFieldBuilder<
|
|
|
38
38
|
export const ObjectFieldBuilder = InternalPrismaObjectFieldBuilder as new <
|
|
39
39
|
Types extends SchemaTypes,
|
|
40
40
|
Model extends PrismaModelTypes,
|
|
41
|
-
NeedsResolve extends boolean,
|
|
42
41
|
Shape extends object = Model['Shape'],
|
|
43
42
|
>(
|
|
44
|
-
|
|
43
|
+
typename: string,
|
|
45
44
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
46
|
-
) => PothosSchemaTypes.PrismaObjectFieldBuilder<Types, Model,
|
|
45
|
+
) => PothosSchemaTypes.PrismaObjectFieldBuilder<Types, Model, Shape>;
|
|
47
46
|
|
|
48
|
-
export class
|
|
47
|
+
export class PothosPrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
|
|
49
48
|
constructor(cache: BuildCache<Types>) {
|
|
50
49
|
super(cache, pluginName);
|
|
51
50
|
}
|
|
@@ -171,4 +170,11 @@ export class PrismaPlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
|
|
|
171
170
|
}
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
SchemaBuilder.registerPlugin(pluginName,
|
|
173
|
+
SchemaBuilder.registerPlugin(pluginName, PothosPrismaPlugin, {
|
|
174
|
+
v3: (options) => ({
|
|
175
|
+
prisma: {
|
|
176
|
+
...options.prisma,
|
|
177
|
+
filterConnectionTotalCount: options.prisma?.filterConnectionTotalCount ?? false,
|
|
178
|
+
},
|
|
179
|
+
}),
|
|
180
|
+
});
|
package/src/interface-ref.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { InterfaceRef } from '@pothos/core';
|
|
1
|
+
import { InterfaceRef, SchemaTypes } from '@pothos/core';
|
|
2
2
|
import { prismaModelKey, PrismaObjectRef } from './object-ref';
|
|
3
3
|
import type { PrismaModelTypes } from './types';
|
|
4
4
|
|
|
5
|
-
export type PrismaRef<Model extends PrismaModelTypes, T = {}> =
|
|
6
|
-
| PrismaInterfaceRef<Model, T>
|
|
7
|
-
| PrismaObjectRef<Model, T>;
|
|
5
|
+
export type PrismaRef<Types extends SchemaTypes, Model extends PrismaModelTypes, T = {}> =
|
|
6
|
+
| PrismaInterfaceRef<Types, Model, T>
|
|
7
|
+
| PrismaObjectRef<Types, Model, T>;
|
|
8
8
|
|
|
9
|
-
export class PrismaInterfaceRef<
|
|
9
|
+
export class PrismaInterfaceRef<
|
|
10
|
+
Types extends SchemaTypes,
|
|
11
|
+
Model extends PrismaModelTypes,
|
|
12
|
+
T = {},
|
|
13
|
+
> extends InterfaceRef<Types, T> {
|
|
10
14
|
[prismaModelKey]!: Model;
|
|
11
15
|
|
|
12
16
|
modelName: string;
|
package/src/model-loader.ts
CHANGED
|
@@ -60,7 +60,7 @@ export class ModelLoader {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
static forRef<Types extends SchemaTypes>(
|
|
63
|
-
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
63
|
+
ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
|
|
64
64
|
modelName: string,
|
|
65
65
|
findUnique: ((model: Record<string, unknown>, ctx: {}) => unknown) | undefined,
|
|
66
66
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
@@ -106,7 +106,7 @@ export class ModelLoader {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
static getDefaultFindBy<Types extends SchemaTypes>(
|
|
109
|
-
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
109
|
+
ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
|
|
110
110
|
modelName: string,
|
|
111
111
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
112
112
|
) {
|
|
@@ -143,7 +143,7 @@ export class ModelLoader {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
static getDefaultFindUnique<Types extends SchemaTypes>(
|
|
146
|
-
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
146
|
+
ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
|
|
147
147
|
modelName: string,
|
|
148
148
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
149
149
|
): (model: Record<string, unknown>) => {} {
|
|
@@ -153,7 +153,7 @@ export class ModelLoader {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
static getDefaultIDSelection<Types extends SchemaTypes>(
|
|
156
|
-
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
156
|
+
ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
|
|
157
157
|
modelName: string,
|
|
158
158
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
159
159
|
): Record<string, boolean> {
|
|
@@ -173,7 +173,7 @@ export class ModelLoader {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
static getCursorSelection<Types extends SchemaTypes>(
|
|
176
|
-
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
176
|
+
ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
|
|
177
177
|
modelName: string,
|
|
178
178
|
cursor: string,
|
|
179
179
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
@@ -202,7 +202,7 @@ export class ModelLoader {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
static getFindUniqueForField<Types extends SchemaTypes>(
|
|
205
|
-
ref: InterfaceRef<unknown> | ObjectRef<unknown>,
|
|
205
|
+
ref: InterfaceRef<Types, unknown> | ObjectRef<Types, unknown>,
|
|
206
206
|
modelName: string,
|
|
207
207
|
fieldName: string,
|
|
208
208
|
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
package/src/node-ref.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { SchemaTypes } from '@pothos/core';
|
|
1
2
|
import { PrismaObjectRef } from './object-ref';
|
|
2
3
|
import type { PrismaModelTypes } from './types';
|
|
3
4
|
|
|
4
|
-
export class PrismaNodeRef<
|
|
5
|
+
export class PrismaNodeRef<
|
|
6
|
+
Types extends SchemaTypes,
|
|
7
|
+
Model extends PrismaModelTypes,
|
|
8
|
+
T,
|
|
9
|
+
> extends PrismaObjectRef<Types, Model, T> {}
|
package/src/object-ref.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
abstractReturnShapeKey,
|
|
3
|
+
brandWithType,
|
|
4
|
+
ObjectRef,
|
|
5
|
+
SchemaTypes,
|
|
6
|
+
typeBrandKey,
|
|
7
|
+
} from '@pothos/core';
|
|
2
8
|
import type { PrismaModelTypes, WithBrand } from './types';
|
|
3
9
|
|
|
4
10
|
export const prismaModelKey = Symbol.for('Pothos.prismaModelKey');
|
|
5
11
|
|
|
6
|
-
export class PrismaObjectRef<
|
|
12
|
+
export class PrismaObjectRef<
|
|
13
|
+
Types extends SchemaTypes,
|
|
14
|
+
Model extends PrismaModelTypes,
|
|
15
|
+
T = {},
|
|
16
|
+
> extends ObjectRef<Types, T> {
|
|
7
17
|
[prismaModelKey]!: Model;
|
|
8
18
|
|
|
9
19
|
[abstractReturnShapeKey]!: WithBrand<T>;
|