prisma-nestjs-graphql 23.0.1 → 23.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/README.md +383 -204
- package/bin.mjs +1 -0
- package/package.json +13 -11
- package/prisma-nestjs-graphql.d.ts +485 -49
- package/prisma-nestjs-graphql.mjs +789 -378
package/bin.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-nestjs-graphql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "23.0
|
|
4
|
+
"version": "23.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module",
|
|
7
7
|
"bin": "bin.mjs",
|
|
@@ -25,9 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"test": "npm run eslint && npm run tscheck && npm run test:r",
|
|
28
|
-
"
|
|
29
|
-
"test:
|
|
30
|
-
"test:cov": "vitest run --coverage",
|
|
28
|
+
"test:r": "vitest --run",
|
|
29
|
+
"test:cov": "vitest --run --coverage",
|
|
31
30
|
"test:w": "vitest watch",
|
|
32
31
|
"tscheck": "tsc --noEmit",
|
|
33
32
|
"tscheck:w": "npm run tscheck -- --watch",
|
|
@@ -59,8 +58,7 @@
|
|
|
59
58
|
"outmatch": "^1.0.0",
|
|
60
59
|
"pluralize": "^8.0.0",
|
|
61
60
|
"pupa": "^3.3.0",
|
|
62
|
-
"ts-morph": "^28.0.0"
|
|
63
|
-
"vitest": "^4.1.5"
|
|
61
|
+
"ts-morph": "^28.0.0"
|
|
64
62
|
},
|
|
65
63
|
"devDependencies": {
|
|
66
64
|
"@apollo/server": "^5.5.1",
|
|
@@ -69,10 +67,10 @@
|
|
|
69
67
|
"@eslint/compat": "^2.1.0",
|
|
70
68
|
"@eslint/js": "^10.0.1",
|
|
71
69
|
"@nestjs/apollo": "^13.4.0",
|
|
72
|
-
"@nestjs/common": "^11.1.
|
|
73
|
-
"@nestjs/core": "^11.1.
|
|
70
|
+
"@nestjs/common": "^11.1.21",
|
|
71
|
+
"@nestjs/core": "^11.1.21",
|
|
74
72
|
"@nestjs/graphql": "^13.4.0",
|
|
75
|
-
"@nestjs/platform-express": "^11.1.
|
|
73
|
+
"@nestjs/platform-express": "^11.1.21",
|
|
76
74
|
"@paljs/plugins": "^9.0.0",
|
|
77
75
|
"@poppinss/ts-exec": "^1.4.4",
|
|
78
76
|
"@prisma/adapter-pg": "^7.8.0",
|
|
@@ -84,8 +82,10 @@
|
|
|
84
82
|
"@types/flat": "^5.0.5",
|
|
85
83
|
"@types/graceful-fs": "^4.1.9",
|
|
86
84
|
"@types/lodash": "^4.17.24",
|
|
87
|
-
"@types/node": "^25.
|
|
85
|
+
"@types/node": "^25.8.0",
|
|
88
86
|
"@types/pluralize": "^0.0.33",
|
|
87
|
+
"@types/serialize-javascript": "^5.0.4",
|
|
88
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
89
89
|
"apollo-server-express": "^3.13.0",
|
|
90
90
|
"class-transformer": "^0.5.1",
|
|
91
91
|
"class-validator": "^0.15.1",
|
|
@@ -118,11 +118,13 @@
|
|
|
118
118
|
"reflect-metadata": "^0.2.2",
|
|
119
119
|
"rxjs": "^7.8.2",
|
|
120
120
|
"semantic-release": "^25.0.3",
|
|
121
|
+
"serialize-javascript": "^7.0.5",
|
|
121
122
|
"simplytyped": "^3.3.0",
|
|
122
123
|
"temp-dir": "^3.0.0",
|
|
123
124
|
"tslib": "^2.8.1",
|
|
124
125
|
"type-fest": "^5.6.0",
|
|
125
126
|
"typescript": "^6.0.3",
|
|
126
|
-
"typescript-eslint": "^8.59.
|
|
127
|
+
"typescript-eslint": "^8.59.3",
|
|
128
|
+
"vitest": "^4.1.6"
|
|
127
129
|
}
|
|
128
130
|
}
|
|
@@ -3,6 +3,91 @@ import AwaitEventEmitter from 'await-event-emitter';
|
|
|
3
3
|
import { Project, SourceFile } from 'ts-morph';
|
|
4
4
|
import { ValueOf, WritableDeep } from 'type-fest';
|
|
5
5
|
|
|
6
|
+
export type ConfigurationCreateArgs = {
|
|
7
|
+
config: {
|
|
8
|
+
[k: string]: GeneratorConfigLine;
|
|
9
|
+
};
|
|
10
|
+
output: string;
|
|
11
|
+
sourceFilePath: string;
|
|
12
|
+
};
|
|
13
|
+
declare class Configuration {
|
|
14
|
+
#private;
|
|
15
|
+
readonly warnings: Set<string>;
|
|
16
|
+
schemaConfig: Record<string, unknown>;
|
|
17
|
+
externalConfig?: ExternalConfig;
|
|
18
|
+
externalConfigFile?: string;
|
|
19
|
+
constructor(args: Pick<Configuration, "schemaConfig" | "externalConfig" | "externalConfigFile"> & {
|
|
20
|
+
sourceFilePath: string;
|
|
21
|
+
output: string;
|
|
22
|
+
warnings?: string[];
|
|
23
|
+
});
|
|
24
|
+
static create(args: ConfigurationCreateArgs): Promise<Configuration>;
|
|
25
|
+
private initializeOutputFilePattern;
|
|
26
|
+
get output(): string;
|
|
27
|
+
get outputFilePattern(): string;
|
|
28
|
+
get importExtension(): string;
|
|
29
|
+
get emitCompiled(): boolean;
|
|
30
|
+
get tsConfigFilePath(): string | undefined;
|
|
31
|
+
get combineScalarFilters(): boolean;
|
|
32
|
+
get noTypeId(): boolean;
|
|
33
|
+
get noAtomicOperations(): boolean;
|
|
34
|
+
get reExport(): ReExportType;
|
|
35
|
+
get purgeOutput(): boolean;
|
|
36
|
+
get emitSingle(): boolean;
|
|
37
|
+
get requireSingleFieldsInWhereUniqueInput(): boolean;
|
|
38
|
+
get omitModelsCount(): boolean;
|
|
39
|
+
get typeListNullable(): boolean;
|
|
40
|
+
get unsafeCompatibleWhereUniqueInput(): boolean;
|
|
41
|
+
get prismaClientImport(): string;
|
|
42
|
+
get emitBlocksModels(): boolean;
|
|
43
|
+
get emitBlocksPrismaEnums(): boolean;
|
|
44
|
+
get emitBlocksSchemaEnums(): boolean;
|
|
45
|
+
get emitBlocksOutputs(): boolean;
|
|
46
|
+
get emitBlocksInputs(): boolean;
|
|
47
|
+
get emitBlocksArgs(): boolean;
|
|
48
|
+
getGraphqlScalar(type: string): ImportNameSpec | undefined;
|
|
49
|
+
getField(namespace?: string): ConfigFieldRecord | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Get graphql for input type
|
|
52
|
+
*/
|
|
53
|
+
getInputType(args: GetInputTypeFunctionArgs): InputTypeRef | undefined;
|
|
54
|
+
get customImports(): CustomImportItem[];
|
|
55
|
+
shouldHideField(args: {
|
|
56
|
+
objectName: string;
|
|
57
|
+
propertyName: string;
|
|
58
|
+
propertyType: string;
|
|
59
|
+
location: FieldLocation;
|
|
60
|
+
typeName: string;
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Should not use
|
|
63
|
+
*/
|
|
64
|
+
settings?: ObjectSettings;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Legacy1
|
|
67
|
+
*/
|
|
68
|
+
output?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Legacy
|
|
71
|
+
*/
|
|
72
|
+
input?: boolean;
|
|
73
|
+
}): boolean;
|
|
74
|
+
getDecorators(): Generator<DecoratorItem>;
|
|
75
|
+
/**
|
|
76
|
+
* Get field override arguments for a specific field.
|
|
77
|
+
* Returns merged fieldArguments from all matching overrides.
|
|
78
|
+
*/
|
|
79
|
+
getFieldOverride(args: {
|
|
80
|
+
objectName: string;
|
|
81
|
+
propertyName: string;
|
|
82
|
+
propertyType: string;
|
|
83
|
+
location: FieldLocation;
|
|
84
|
+
typeName: string;
|
|
85
|
+
}): Record<string, unknown> | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Should be replaced by decorators
|
|
88
|
+
*/
|
|
89
|
+
get decorate(): LegacyDecorateElement[];
|
|
90
|
+
}
|
|
6
91
|
declare const ReExport: {
|
|
7
92
|
readonly All: "All";
|
|
8
93
|
readonly Directories: "Directories";
|
|
@@ -10,52 +95,6 @@ declare const ReExport: {
|
|
|
10
95
|
readonly Single: "Single";
|
|
11
96
|
};
|
|
12
97
|
export type ReExportType = ValueOf<typeof ReExport>;
|
|
13
|
-
export type DecorateElement = {
|
|
14
|
-
isMatchField: (s: string) => boolean;
|
|
15
|
-
isMatchType: (s: string) => boolean;
|
|
16
|
-
from: string;
|
|
17
|
-
name: string;
|
|
18
|
-
arguments?: string[];
|
|
19
|
-
namedImport: boolean;
|
|
20
|
-
defaultImport?: string | true;
|
|
21
|
-
namespaceImport?: string;
|
|
22
|
-
};
|
|
23
|
-
export type CustomImport = {
|
|
24
|
-
from: string;
|
|
25
|
-
name: string;
|
|
26
|
-
namedImport: boolean;
|
|
27
|
-
defaultImport?: string | true;
|
|
28
|
-
namespaceImport?: string;
|
|
29
|
-
};
|
|
30
|
-
declare function createConfig(data: Record<string, unknown>): {
|
|
31
|
-
$warnings: string[];
|
|
32
|
-
combineScalarFilters: boolean;
|
|
33
|
-
customImport: CustomImport[];
|
|
34
|
-
decorate: DecorateElement[];
|
|
35
|
-
emitBlocks: Record<"models" | "inputs" | "args" | "outputs" | "prismaEnums" | "schemaEnums", boolean>;
|
|
36
|
-
emitCompiled: boolean;
|
|
37
|
-
emitSingle: boolean;
|
|
38
|
-
fields: Record<string, Partial<Omit<ObjectSetting, "name">> | undefined>;
|
|
39
|
-
graphqlScalars: Record<string, ImportNameSpec | undefined>;
|
|
40
|
-
importExtension: string;
|
|
41
|
-
noAtomicOperations: boolean;
|
|
42
|
-
noTypeId: boolean;
|
|
43
|
-
omitModelsCount: boolean;
|
|
44
|
-
outputFilePattern: string;
|
|
45
|
-
prismaClientImport: string;
|
|
46
|
-
purgeOutput: boolean;
|
|
47
|
-
reExport: ReExportType;
|
|
48
|
-
requireSingleFieldsInWhereUniqueInput: boolean;
|
|
49
|
-
tsConfigFilePath: string | undefined;
|
|
50
|
-
typeListNullable: boolean;
|
|
51
|
-
unsafeCompatibleWhereUniqueInput: boolean;
|
|
52
|
-
useInputType: ConfigInputItem[];
|
|
53
|
-
};
|
|
54
|
-
export type ConfigInputItem = {
|
|
55
|
-
typeName: string;
|
|
56
|
-
ALL?: string;
|
|
57
|
-
[index: string]: string | undefined;
|
|
58
|
-
};
|
|
59
98
|
export type ObjectSetting = {
|
|
60
99
|
/**
|
|
61
100
|
* Act as named import or namespaceImport or defaultImport
|
|
@@ -86,16 +125,65 @@ declare class ObjectSettings extends Array<ObjectSetting> {
|
|
|
86
125
|
fieldArguments(): Record<string, unknown> | undefined;
|
|
87
126
|
}
|
|
88
127
|
export type TAwaitEventEmitter = AwaitEventEmitter.default;
|
|
128
|
+
export type FieldLocation = DMMF.FieldLocation;
|
|
89
129
|
export type Model = WritableDeep<DMMF.Model>;
|
|
90
130
|
export type Schema = WritableDeep<DMMF.Schema>;
|
|
91
|
-
export type
|
|
131
|
+
export type Field = DMMF.Field;
|
|
132
|
+
export type InputTypeRef = DMMF.InputTypeRef;
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated
|
|
135
|
+
*/
|
|
136
|
+
export type LegacyDecorateElement = {
|
|
137
|
+
isMatchField: (s: string) => boolean;
|
|
138
|
+
isMatchType: (s: string) => boolean;
|
|
139
|
+
from: string;
|
|
140
|
+
name: string;
|
|
141
|
+
arguments?: string[];
|
|
142
|
+
namedImport: boolean;
|
|
143
|
+
defaultImport?: string | true;
|
|
144
|
+
namespaceImport?: string;
|
|
145
|
+
type: string;
|
|
146
|
+
field: string;
|
|
147
|
+
};
|
|
148
|
+
export type FieldInfo = {
|
|
149
|
+
/**
|
|
150
|
+
* Prisma DMMF field location type
|
|
151
|
+
* Can be: 'scalar', 'inputObjectTypes', 'outputObjectTypes', 'enumTypes', 'fieldRefTypes'
|
|
152
|
+
*/
|
|
153
|
+
location: FieldLocation;
|
|
154
|
+
/**
|
|
155
|
+
* Class name
|
|
156
|
+
*/
|
|
157
|
+
objectName: string;
|
|
158
|
+
/**
|
|
159
|
+
* Property name
|
|
160
|
+
*/
|
|
161
|
+
propertyName: string;
|
|
162
|
+
/**
|
|
163
|
+
* Property type (may contain TypeScript elements, like parameters for generics, etc.)
|
|
164
|
+
*/
|
|
165
|
+
propertyType: string;
|
|
166
|
+
/**
|
|
167
|
+
* GraphQL/Prisma type name
|
|
168
|
+
*/
|
|
169
|
+
typeName: string;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Configuration lines defined in schema
|
|
173
|
+
*/
|
|
174
|
+
export type GeneratorConfigLine = string | string[] | undefined | null;
|
|
175
|
+
export type GetInputTypeFunctionArgs = {
|
|
176
|
+
inputTypeName: string;
|
|
177
|
+
fieldName: string;
|
|
178
|
+
fieldInputTypes: InputTypeRef[];
|
|
179
|
+
};
|
|
92
180
|
export type EventArguments = {
|
|
93
181
|
schema: Schema;
|
|
94
182
|
models: Map<string, Model>;
|
|
95
183
|
modelNames: string[];
|
|
96
184
|
modelFields: Map<string, Map<string, Field>>;
|
|
97
185
|
fieldSettings: Map<string, Map<string, ObjectSettings>>;
|
|
98
|
-
config:
|
|
186
|
+
config: Configuration;
|
|
99
187
|
project: Project;
|
|
100
188
|
output: string;
|
|
101
189
|
getSourceFile(args: {
|
|
@@ -116,7 +204,355 @@ export type ImportNameSpec = {
|
|
|
116
204
|
name: string;
|
|
117
205
|
specifier?: string;
|
|
118
206
|
};
|
|
119
|
-
export type
|
|
207
|
+
export type EmitBlocksOption = "enums" | "models" | "inputs" | "args" | "outputs";
|
|
208
|
+
export type ConfigFieldRecord = {
|
|
209
|
+
/** Arguments passed to the decorator.
|
|
210
|
+
* @default [] */
|
|
211
|
+
arguments?: string[];
|
|
212
|
+
/** Import as default export.
|
|
213
|
+
* Use `true` to import by the field namespace name. */
|
|
214
|
+
defaultImport?: string | true;
|
|
215
|
+
/** Module to import from (e.g. 'class-validator') */
|
|
216
|
+
from?: string;
|
|
217
|
+
/** Apply decorator on InputType classes.
|
|
218
|
+
* @default false */
|
|
219
|
+
input?: boolean;
|
|
220
|
+
/** Apply decorator only on model ObjectType classes.
|
|
221
|
+
* @default false */
|
|
222
|
+
model?: boolean;
|
|
223
|
+
/** Import entire module under this namespace.
|
|
224
|
+
* @default equals field namespace name */
|
|
225
|
+
namespaceImport?: string;
|
|
226
|
+
/** Apply decorator on ObjectType/output classes.
|
|
227
|
+
* @default false */
|
|
228
|
+
output?: boolean;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* @example
|
|
232
|
+
* WhereInput: { '*': 'WhereInput' },
|
|
233
|
+
* PostCreateInput: { author: 'UserCreateNestedOneWithoutPostsInput' },
|
|
234
|
+
*/
|
|
235
|
+
export type ConfigInputTypeMap = Record<string, Record<string, string>>;
|
|
236
|
+
export type GetInputTypeRefFunction = (args: GetInputTypeFunctionArgs) => InputTypeRef | undefined;
|
|
237
|
+
export type GetInputTypePatternFunction = (args: GetInputTypeFunctionArgs) => string | undefined;
|
|
238
|
+
export type GetInputTypeFunction = GetInputTypeRefFunction | GetInputTypePatternFunction;
|
|
239
|
+
export type CustomImportItem = {
|
|
240
|
+
/** Import as default export.
|
|
241
|
+
* Use `true` to import by name. */
|
|
242
|
+
defaultImport?: string | true;
|
|
243
|
+
/** Module specifier to import from (e.g. 'class-validator') */
|
|
244
|
+
from: string;
|
|
245
|
+
/** Name to import */
|
|
246
|
+
name: string;
|
|
247
|
+
/** Import as a named export.
|
|
248
|
+
* @default false */
|
|
249
|
+
namedImport?: boolean;
|
|
250
|
+
/** Import entire module under this namespace */
|
|
251
|
+
namespaceImport?: string;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Return `true` to generate `@HideField()` instead of `@Field()` for a field.
|
|
255
|
+
*/
|
|
256
|
+
export type ShouldHideFieldFunction = (args: FieldInfo) => boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Modern decorator rule for `ExternalConfig.decorators`.
|
|
259
|
+
* Prefer this over legacy `decorate_*` schema keys.
|
|
260
|
+
*/
|
|
261
|
+
export type DecoratorItem = {
|
|
262
|
+
/** Return `true` to apply this decorator to the current field. */
|
|
263
|
+
match: (args: FieldInfo) => boolean;
|
|
264
|
+
/** Arguments passed to the decorator call.
|
|
265
|
+
* Supports templates like `{propertyType.0}`. */
|
|
266
|
+
arguments?: string[];
|
|
267
|
+
/** Module specifier to import from (e.g. 'class-validator') */
|
|
268
|
+
from: string;
|
|
269
|
+
/** Decorator name. Can include namespace, e.g. `Transform.Type`. */
|
|
270
|
+
name: string;
|
|
271
|
+
/** Import as a named export. */
|
|
272
|
+
namedImport?: boolean;
|
|
273
|
+
/** Import as default export.
|
|
274
|
+
* Use `true` to import by decorator name. */
|
|
275
|
+
defaultImport?: string | true;
|
|
276
|
+
/** Import entire module under this namespace. */
|
|
277
|
+
namespaceImport?: string;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* Arguments passed to the `@Field()` decorator.
|
|
281
|
+
* Follows NestJS GraphQL's FieldOptions structure to avoid conflicts.
|
|
282
|
+
* These are merged into the generated `@Field()` options object.
|
|
283
|
+
*
|
|
284
|
+
* @see https://docs.nestjs.com/graphql/resolvers-map#field-decorator
|
|
285
|
+
*/
|
|
286
|
+
export type FieldDecoratorArguments = {
|
|
287
|
+
/**
|
|
288
|
+
* Custom name for the field in GraphQL schema (different from TypeScript property name).
|
|
289
|
+
*
|
|
290
|
+
* **Important:** When you rename a field (e.g., 'take' → 'first'), you must map the GraphQL
|
|
291
|
+
* argument names back to Prisma field names in your resolver, since Prisma expects the
|
|
292
|
+
* original field names.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* // Option 1: Manual mapping in resolver
|
|
296
|
+
* async findMany(args: FindManyArgs): Promise<Item[]> {
|
|
297
|
+
* const { first, ...restArgs } = args as any;
|
|
298
|
+
* return this.prisma.item.findMany({
|
|
299
|
+
* ...restArgs,
|
|
300
|
+
* ...(first !== undefined && { take: first }),
|
|
301
|
+
* });
|
|
302
|
+
* }
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* // Option 2: Use a helper function
|
|
306
|
+
* export function mapGraphQLArgsToPrisma(args: any): any {
|
|
307
|
+
* const { first, ...restArgs } = args;
|
|
308
|
+
* return {
|
|
309
|
+
* ...restArgs,
|
|
310
|
+
* ...(first !== undefined && { take: first }),
|
|
311
|
+
* };
|
|
312
|
+
* }
|
|
313
|
+
*
|
|
314
|
+
* async findMany(args: FindManyArgs): Promise<Item[]> {
|
|
315
|
+
* const prismaArgs = mapGraphQLArgsToPrisma(args);
|
|
316
|
+
* return this.prisma.item.findMany(prismaArgs);
|
|
317
|
+
* }
|
|
318
|
+
* export function mapGraphQLArgsToPrisma(args: any): any {
|
|
319
|
+
* const { first, ...restArgs } = args;
|
|
320
|
+
* return {
|
|
321
|
+
* ...restArgs,
|
|
322
|
+
* ...(first !== undefined && { take: first }),
|
|
323
|
+
* };
|
|
324
|
+
* }
|
|
325
|
+
*/
|
|
326
|
+
name?: string;
|
|
327
|
+
/** Description shown in GraphQL schema. */
|
|
328
|
+
description?: string;
|
|
329
|
+
/** Mark field as deprecated with optional reason. */
|
|
330
|
+
deprecationReason?: string;
|
|
331
|
+
/** Complexity for query complexity analysis. */
|
|
332
|
+
complexity?: unknown;
|
|
333
|
+
/** Array of middleware to apply to the field. */
|
|
334
|
+
middleware?: unknown[];
|
|
335
|
+
/** Mark field as nullable in GraphQL schema. */
|
|
336
|
+
nullable?: boolean;
|
|
337
|
+
/** Default value for the field. */
|
|
338
|
+
defaultValue?: unknown;
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Rule for overriding `@Field()` decorator arguments on generated fields.
|
|
342
|
+
* Use this to customize pagination fields (take, skip) or other generated Args fields.
|
|
343
|
+
*/
|
|
344
|
+
export type FieldDecoratorRule = {
|
|
345
|
+
/** Return `true` to apply this override to the current field. */
|
|
346
|
+
match: (args: FieldInfo) => boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Arguments to merge into the `@Field()` decorator options.
|
|
349
|
+
* These are merged with existing arguments (nullable, etc.).
|
|
350
|
+
*/
|
|
351
|
+
decoratorArguments: FieldDecoratorArguments;
|
|
352
|
+
};
|
|
353
|
+
export type ExternalConfig = Partial<{
|
|
354
|
+
/**
|
|
355
|
+
* Output folder for generated files.
|
|
356
|
+
* If path relative and defined in schema it will be relative to schema,
|
|
357
|
+
* if defined in config file it will be relative to this config file.
|
|
358
|
+
*/
|
|
359
|
+
output: string;
|
|
360
|
+
/**
|
|
361
|
+
* File path and name pattern for generated files.
|
|
362
|
+
* @type {string}
|
|
363
|
+
* Available tokens:
|
|
364
|
+
* - `{model}` — Model name in dashed-case, or 'prisma' if unknown
|
|
365
|
+
* - `{name}` — Dashed-case name of model/input/arg without suffix
|
|
366
|
+
* - `{type}` — Short type name (model, input, args, output)
|
|
367
|
+
* - `{plural.type}` — Plural short type name (models, inputs, enums)
|
|
368
|
+
* @default '{model}/{name}.{type}.ts'
|
|
369
|
+
*/
|
|
370
|
+
outputFilePattern: string;
|
|
371
|
+
/**
|
|
372
|
+
* Append an extension to relative import and export module specifiers.
|
|
373
|
+
* Useful when your project uses ESM or a custom module resolution.
|
|
374
|
+
* @example 'js', 'ts', 'mjs'
|
|
375
|
+
*/
|
|
376
|
+
importExtension: string;
|
|
377
|
+
/**
|
|
378
|
+
* Combine nested/nullable scalar filters into a single filter type.
|
|
379
|
+
* When enabled, reduces the number of generated filter classes by merging
|
|
380
|
+
* e.g. `StringNullableFilter` and `StringFilter` into one.
|
|
381
|
+
* @default true
|
|
382
|
+
*/
|
|
383
|
+
combineScalarFilters: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Remove input types for atomic operations.
|
|
386
|
+
* When enabled, types like `IntFieldUpdateOperationsInput` are not generated.
|
|
387
|
+
* @default true
|
|
388
|
+
*/
|
|
389
|
+
noAtomicOperations: boolean;
|
|
390
|
+
/**
|
|
391
|
+
* Emit only selected blocks. Some blocks depend on others
|
|
392
|
+
* (e.g. models requires schemaEnums, inputs requires prismaEnums).
|
|
393
|
+
* Valid block names: 'args', 'inputs', 'outputs', 'models', 'enums'
|
|
394
|
+
* @default All blocks enabled
|
|
395
|
+
*/
|
|
396
|
+
emitBlocks: EmitBlocksOption[];
|
|
397
|
+
/**
|
|
398
|
+
* Omit the `_count` field from model output types.
|
|
399
|
+
* @default false
|
|
400
|
+
*/
|
|
401
|
+
omitModelsCount: boolean;
|
|
402
|
+
/**
|
|
403
|
+
* Emit compiled JavaScript and definition files instead of TypeScript sources.
|
|
404
|
+
* @default false
|
|
405
|
+
*/
|
|
406
|
+
emitCompiled: boolean;
|
|
407
|
+
/**
|
|
408
|
+
* Path to tsconfig.json (absolute or relative to CWD).
|
|
409
|
+
* If not specified, auto-detects `tsconfig.json` if it exists.
|
|
410
|
+
*/
|
|
411
|
+
tsConfigFilePath: string;
|
|
412
|
+
/**
|
|
413
|
+
* Re-export strategy for generated files.
|
|
414
|
+
* - None — No re-export index files (default)
|
|
415
|
+
* - Directories — Index file in each root directory
|
|
416
|
+
* - Single — Single index file in the output directory
|
|
417
|
+
* - All — All of the above
|
|
418
|
+
* @default None
|
|
419
|
+
*/
|
|
420
|
+
reExport: ReExportType;
|
|
421
|
+
/**
|
|
422
|
+
* Delete all files in the output folder before each generation.
|
|
423
|
+
* @default false
|
|
424
|
+
*/
|
|
425
|
+
purgeOutput: boolean;
|
|
426
|
+
/**
|
|
427
|
+
* Mark single-field WhereUniqueInput fields as required (TypeScript)
|
|
428
|
+
* and non-nullable (GraphQL).
|
|
429
|
+
* NOTE: This will break compatibility between Prisma types and generated classes.
|
|
430
|
+
* @default false
|
|
431
|
+
*/
|
|
432
|
+
requireSingleFieldsInWhereUniqueInput: boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Generate a single merged file with all classes and enums
|
|
435
|
+
* instead of one file per model/input/arg.
|
|
436
|
+
* @default false
|
|
437
|
+
*/
|
|
438
|
+
emitSingle: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Make all fields in `*WhereUniqueInput` classes non-optional TypeScript properties.
|
|
441
|
+
* @default false
|
|
442
|
+
*/
|
|
443
|
+
unsafeCompatibleWhereUniqueInput: boolean;
|
|
444
|
+
/**
|
|
445
|
+
* Add `nullable: true` to relation list properties on output types.
|
|
446
|
+
* Changes `[Type!]!` → `[Type!]` in the GraphQL schema.
|
|
447
|
+
* @default false
|
|
448
|
+
*/
|
|
449
|
+
typeListNullable: boolean;
|
|
450
|
+
/**
|
|
451
|
+
* Import path used for Prisma Client imports in generated files.
|
|
452
|
+
* @default '@prisma/client'
|
|
453
|
+
*/
|
|
454
|
+
prismaClientImport: string;
|
|
455
|
+
/**
|
|
456
|
+
* Disable GraphQL ID type usage, using Int/Float for @id fields instead.
|
|
457
|
+
* @default false
|
|
458
|
+
*/
|
|
459
|
+
noTypeId: boolean;
|
|
460
|
+
/**
|
|
461
|
+
* Custom GraphQL scalar type mappings for Prisma scalar types.
|
|
462
|
+
* Keyed by Prisma scalar type name (e.g. 'BigInt', 'DateTime').
|
|
463
|
+
* @example
|
|
464
|
+
* // Override BigInt with graphql-scalars' GraphQLBigInt:
|
|
465
|
+
* { BigInt: { name: 'GraphQLBigInt', specifier: 'graphql-scalars' } }
|
|
466
|
+
*/
|
|
467
|
+
graphqlScalars: Record<string, ImportNameSpec | undefined>;
|
|
468
|
+
/**
|
|
469
|
+
* Per-field custom decorator configuration, keyed by namespace.
|
|
470
|
+
* Enables automatic decorator application from external modules
|
|
471
|
+
* on fields annotated with `@{namespace}.XXX` in the Prisma schema.
|
|
472
|
+
* Each namespace entry defines:
|
|
473
|
+
* - `from` — Module specifier to import (e.g. 'class-validator')
|
|
474
|
+
* - `input` — Apply to InputType classes
|
|
475
|
+
* - `output` — Apply to ObjectType/output classes
|
|
476
|
+
* - `model` — Apply only to model ObjectType classes
|
|
477
|
+
* - `defaultImport` — Import as default export (true = use namespace as name)
|
|
478
|
+
* - `namespaceImport` — Import entire module under this namespace
|
|
479
|
+
* - `namedImport` — Import as named export
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* // Schema: /// @Validator.MinLength(3)
|
|
483
|
+
* // Config: { from: 'class-validator', input: true }
|
|
484
|
+
* // Result: import * as Validator from 'class-validator'; @Validator.MinLength(3)
|
|
485
|
+
*/
|
|
486
|
+
fields: Record<string, ConfigFieldRecord | undefined>;
|
|
487
|
+
/**
|
|
488
|
+
* Input type mapping.
|
|
489
|
+
* Select which input type should be exposed when multiple candidates exist.
|
|
490
|
+
* Since GraphQL does not support input unions, this setting can resolve
|
|
491
|
+
* ambiguous fields (e.g. `UserRelationFilter` vs `UserWhereInput`).
|
|
492
|
+
*
|
|
493
|
+
* Supports two variants:
|
|
494
|
+
* - object map: `{ [inputTypeName]: { [fieldName|'*']: pattern } }`
|
|
495
|
+
* - function: return either an `InputTypeRef` or a string pattern
|
|
496
|
+
* (same matching behavior as map patterns, including `match:` syntax)
|
|
497
|
+
* @example
|
|
498
|
+
* // Force all WhereInput relation properties to use the plain WhereInput type:
|
|
499
|
+
* { WhereInput: { '*': 'WhereInput' } }
|
|
500
|
+
* // Or for a specific property in a specific type:
|
|
501
|
+
* { PostCreateInput: { author: 'UserCreateNestedOneWithoutPostsInput' } }
|
|
502
|
+
* // Function variant returning a pattern:
|
|
503
|
+
* ({ inputTypeName, fieldName }) =>
|
|
504
|
+
* inputTypeName.includes('CreateOne') && fieldName === 'data'
|
|
505
|
+
* ? 'UncheckedCreate'
|
|
506
|
+
* : undefined
|
|
507
|
+
*/
|
|
508
|
+
inputType: GetInputTypeFunction | ConfigInputTypeMap;
|
|
509
|
+
/**
|
|
510
|
+
* Custom import statements injected into generated files.
|
|
511
|
+
* Each element specifies:
|
|
512
|
+
* - `from` — Module specifier to import from
|
|
513
|
+
* - `name` — Name to import
|
|
514
|
+
* - `namedImport` — Import as named export
|
|
515
|
+
* - `defaultImport` — Import as default export
|
|
516
|
+
* - `namespaceImport` — Import entire module under this namespace
|
|
517
|
+
*/
|
|
518
|
+
customImports: CustomImportItem[];
|
|
519
|
+
/**
|
|
520
|
+
* Hook for deciding whether a generated field should be hidden in GraphQL schema.
|
|
521
|
+
* Called for each generated input/output/model field.
|
|
522
|
+
* Returning `true` adds `@HideField()` and skips `@Field()`.
|
|
523
|
+
* When set, this hook overrides hide settings from field comments and legacy `decorate`.
|
|
524
|
+
*/
|
|
525
|
+
shouldHideField: ShouldHideFieldFunction;
|
|
526
|
+
/**
|
|
527
|
+
* Modern way to attach decorators to generated fields.
|
|
528
|
+
* Each rule is evaluated against generated field metadata (`FieldInfo`) and
|
|
529
|
+
* applied when `match` returns `true`.
|
|
530
|
+
* Prefer this over legacy `decorate`/`decorate_*` schema configuration.
|
|
531
|
+
*/
|
|
532
|
+
decorators: DecoratorItem[];
|
|
533
|
+
/**
|
|
534
|
+
* Override `@Field()` decorator arguments for specific fields.
|
|
535
|
+
* Use this to customize pagination fields (take, skip, cursor) or other
|
|
536
|
+
* generated Args fields that don't come from your Prisma schema.
|
|
537
|
+
*
|
|
538
|
+
* Each rule is evaluated against generated field metadata (`FieldInfo`) and
|
|
539
|
+
* applied when `match` returns `true`.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* fieldDecoratorArguments: [
|
|
543
|
+
* {
|
|
544
|
+
* match: ({ objectName, propertyName }) =>
|
|
545
|
+
* objectName.endsWith('Args') && propertyName === 'take',
|
|
546
|
+
* decoratorArguments: {
|
|
547
|
+
* name: 'first',
|
|
548
|
+
* defaultValue: 10,
|
|
549
|
+
* description: 'Number of records to return',
|
|
550
|
+
* },
|
|
551
|
+
* },
|
|
552
|
+
* ]
|
|
553
|
+
*/
|
|
554
|
+
fieldDecoratorArguments: FieldDecoratorRule[];
|
|
555
|
+
}>;
|
|
120
556
|
export declare function generate(args: GeneratorOptions & {
|
|
121
557
|
skipAddOutputSourceFiles?: boolean;
|
|
122
558
|
connectCallback?: (emitter: TAwaitEventEmitter, eventArguments: EventArguments) => void | Promise<void>;
|