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 CHANGED
@@ -20,20 +20,46 @@ npm install --save-dev prisma-nestjs-graphql @prisma/generator-helper identity-t
20
20
 
21
21
  ```prisma
22
22
  generator nestgraphql {
23
- provider = "prisma-nestjs-graphql"
24
- // Or explicit node execution
25
- provider = "node node_modules/prisma-nestjs-graphql/bin.mjs"
26
- output = "../src/@generated"
23
+ provider = "prisma-nestjs-graphql"
24
+ // Or explicit node execution
25
+ provider = "node node_modules/prisma-nestjs-graphql/bin.mjs"
26
+ output = "../src/@generated"
27
+ }
28
+ ```
29
+
30
+ 2. Add a configuration file
31
+
32
+ Create `prisma/nestgraphql.config.mjs` and reference it in your schema:
33
+
34
+ ```prisma
35
+ generator nestgraphql {
36
+ provider = "prisma-nestjs-graphql"
37
+ configFile = "./nestgraphql.config.mjs"
27
38
  }
28
39
  ```
29
40
 
30
- 2. Run prisma generate
41
+ ```js
42
+ // prisma/nestgraphql.config.mjs
43
+ /**
44
+ * @type {import('prisma-nestjs-graphql').ExternalConfig}
45
+ */
46
+ export default {
47
+ output: '../src/@generated',
48
+ };
49
+ ```
50
+
51
+ All generator options—including `decorators`, `fields`, `useInputType`, `customImport`,
52
+ and `graphqlScalars`—are defined as **structured JavaScript objects** in the config file
53
+ instead of using underscore-delimited keys (`decorate_1_*`, `fields_Validator_*`, etc.)
54
+ directly in the schema.
55
+
56
+ 3. Run prisma generate
31
57
 
32
58
  ```sh
33
59
  npx prisma generate
34
60
  ```
35
61
 
36
- 3. If your models have `Decimal` and `Json` types, you need install:
62
+ 4. If your models have `Decimal` and `Json` types, you need install:
37
63
 
38
64
  ```sh
39
65
  npm install graphql-type-json prisma-graphql-type-decimal
@@ -45,11 +71,54 @@ npm install graphql-type-json prisma-graphql-type-decimal
45
71
 
46
72
  Or write you own graphql scalar types, [read more on docs.nestjs.com](https://docs.nestjs.com/graphql/scalars).
47
73
 
74
+ ## Configuration File
75
+
76
+ Instead of defining all options as flat keys in `schema.prisma`, you can use a structured JavaScript config file
77
+ for better readability, validation, and IDE autocompletion.
78
+
79
+ ### Migration from flatten-style keys
80
+
81
+ **Before** (underscore-delimited keys in `schema.prisma`):
82
+
83
+ ```
84
+ fields_Validator_from = "class-validator"
85
+ fields_Validator_input = true
86
+ decorate_1_type = "CreateOneUserArgs"
87
+ decorate_1_field = data
88
+ decorate_1_from = "class-validator"
89
+ decorate_1_name = ValidateNested
90
+ decorate_1_arguments = "[]"
91
+ ```
92
+
93
+ **After** (structured objects in `nestgraphql.config.mjs`):
94
+
95
+ ```js
96
+ fields: {
97
+ Validator: { from: 'class-validator', input: true },
98
+ },
99
+ decorators: [
100
+ {
101
+ match: ({ objectName, propertyName }) =>
102
+ objectName === 'CreateOneUserArgs' && propertyName === 'data',
103
+ from: 'class-validator',
104
+ name: 'ValidateNested',
105
+ arguments: [],
106
+ namedImport: true,
107
+ },
108
+ ],
109
+ ```
110
+
111
+ ### Backward compatibility
112
+
113
+ The old flatten-style keys still work if no `configFile` is specified.
114
+ Options from the config file take precedence.
115
+
48
116
  ## Generator options
49
117
 
50
118
  #### `output`
51
119
 
52
- Output folder relative to this schema file
120
+ Output folder, if path relative and defined in schema it will be relative to schema,
121
+ if defined in config file it will be relative to this config file.
53
122
  Type: `string`
54
123
 
55
124
  #### `outputFilePattern`
@@ -84,24 +153,24 @@ Default: `''` (empty string)
84
153
 
85
154
  #### `combineScalarFilters`
86
155
 
87
- Combine nested/nullable scalar filters to single
88
- Type: `boolean`
156
+ Combine nested/nullable scalar filters to single
157
+ Type: `boolean`
89
158
  Default: `true`
90
159
 
91
160
  #### `noAtomicOperations`
92
161
 
93
- Remove input types for atomic operations
94
- Type: `boolean`
162
+ Remove input types for atomic operations
163
+ Type: `boolean`
95
164
  Default: `true`
96
165
 
97
166
  #### `reExport`
98
167
 
99
- Create `index.ts` file with re-export
100
- Type: `enum`
101
- Values:
102
- `None` Default, create nothing
103
- `Directories` Create index file in all root directories
104
- `Single` Create single index file in output directory
168
+ Create `index.ts` file with re-export
169
+ Type: `enum`
170
+ Values:
171
+ `None` Default, create nothing
172
+ `Directories` Create index file in all root directories
173
+ `Single` Create single index file in output directory
105
174
  `All` Create index file in all root directories and in output directory
106
175
 
107
176
  Example configuration:
@@ -116,83 +185,107 @@ generator nestgraphql {
116
185
 
117
186
  #### `emitSingle`
118
187
 
119
- Generate single file with merged classes and enums.
120
- Type: `boolean`
188
+ Generate single file with merged classes and enums.
189
+ Type: `boolean`
121
190
  Default: `false`
122
191
 
123
192
  #### `emitCompiled`
124
193
 
125
- Emit compiled JavaScript and definitions instead of TypeScript sources,
126
- files will be compiled with `emitDecoratorMetadata:false`, because there is a problem
127
- with temporal dead zone when generating merged file.
128
- Type: `boolean`
194
+ Emit compiled JavaScript and definitions instead of TypeScript sources.
195
+ Type: `boolean`
129
196
  Default: `false`
130
197
 
131
198
  #### `emitBlocks`
132
199
 
133
- Emit only selected blocks. Be aware, that some blocks do depend on others, e.g. one can't emit `models` without emitting `enums`.
134
- Type: `("args" | "inputs" | "outputs" | "models" | "enums")[]`
200
+ Emit only selected blocks. Be aware, that some blocks do depend on others, e.g. one can't emit `models` without emitting `enums`.
201
+ Type: `("args" | "inputs" | "outputs" | "models" | "enums")[]`
135
202
  Default: `["args", "inputs", "outputs", "models", "enums"]`
136
203
 
137
204
  #### `omitModelsCount`
138
205
 
139
- Omit `_count` field from models.
140
- Type: `boolean`
206
+ Omit `_count` field from models.
207
+ Type: `boolean`
141
208
  Default: `false`
142
209
 
143
210
  #### `purgeOutput`
144
211
 
145
- Delete all files in `output` folder.
146
- Type: `boolean`
212
+ Delete all files in `output` folder.
213
+ Type: `boolean`
147
214
  Default: `false`
148
215
 
149
216
  #### `noTypeId`
150
217
 
151
- Disable usage of graphql `ID` type and use `Int/Float` for fields marked as `@id` in schema.
152
- Type: `boolean`
218
+ Disable usage of graphql `ID` type and use `Int/Float` for fields marked as `@id` in schema.
219
+ Type: `boolean`
153
220
  Default: `false`
154
221
 
155
222
  #### `typeListNullable`
156
223
 
157
224
  Adds `nullable: true` for relation list properties out output models,
158
225
  it makes graphql field looks like `[Type!]`, default `[Type!]!`
159
- Type: `boolean`
226
+ Type: `boolean`
160
227
  Default: `false`
161
228
 
162
229
  #### `requireSingleFieldsInWhereUniqueInput`
163
230
 
164
- When a model `*WhereUniqueInput` class has only a single field, mark that field as **required** (TypeScript) and **not nullable** (GraphQL).
165
- See [#58](https://github.com/unlight/prisma-nestjs-graphql/issues/58) for more details.
166
- Type: `boolean`
167
- Default: `false`
231
+ When a model `*WhereUniqueInput` class has only a single field, mark that field as **required** (TypeScript) and **not nullable** (GraphQL).
232
+ See [#58](https://github.com/unlight/prisma-nestjs-graphql/issues/58) for more details.
233
+ Type: `boolean`
234
+ Default: `false`
168
235
  **Note**: It will break compatiblity between Prisma types and generated classes.
169
236
 
170
237
  #### `unsafeCompatibleWhereUniqueInput`
171
238
 
172
239
  Set TypeScript property type as non optional for all fields in `*WhereUniqueInput` classes.
173
- See [#177](https://github.com/unlight/prisma-nestjs-graphql/issues/177) for more details.
174
- Type: `boolean`
240
+ See [#177](https://github.com/unlight/prisma-nestjs-graphql/issues/177) for more details.
241
+ Type: `boolean`
175
242
  Default: `false`
176
243
 
177
- #### `useInputType`
244
+ #### `inputType`
178
245
 
179
246
  Since GraphQL does not support input union type, this setting map
180
247
  allow to choose which input type is preferable.
181
248
 
182
- ```sh
183
- generator nestgraphql {
184
- useInputType_{typeName}_{property} = "{pattern}"
185
- }
249
+ **New (config file)**:
250
+
251
+ ```js
252
+ /**
253
+ * Input type mapping.
254
+ * Select which input type should be exposed when multiple candidates exist.
255
+ * Since GraphQL does not support input unions, this setting can resolve
256
+ * ambiguous fields (e.g. `UserRelationFilter` vs `UserWhereInput`).
257
+ *
258
+ * Supports two variants:
259
+ * - object map: `{ [inputTypeName]: { [fieldName|'*']: pattern } }`
260
+ * - function: return either an `InputTypeRef` or a string pattern
261
+ * (same matching behavior as map patterns, including `match:` syntax)
262
+ * @example
263
+ * // Force all WhereInput relation properties to use the plain WhereInput type:
264
+ * { WhereInput: { '*': 'WhereInput' } }
265
+ * // Or for a specific property in a specific type:
266
+ * { PostCreateInput: { author: 'UserCreateNestedOneWithoutPostsInput' } }
267
+ * // Function variant returning a pattern:
268
+ * ({ inputTypeName, fieldName }) =>
269
+ * inputTypeName.includes('CreateOne') && fieldName === 'data'
270
+ * ? 'UncheckedCreate'
271
+ * : undefined
272
+ */
273
+ inputType: GetInputTypeFunction | ConfigInputTypeMap;
186
274
  ```
187
275
 
188
276
  Where:
189
277
 
190
- - `typeName` Full name or partial name of the class where need to choose input type.
191
- Example: `UserCreateInput` full name, `WhereInput` partial name, matches `UserWhereInput`, `PostWhereInput`, etc.
192
- - `property` Property of the class for which need to choose type. Special case name `ALL` means any / all properties.
193
- - `pattern` Part of name (or full) of type which should be chosen, you can use
194
- wild card or negate symbols, in this case pattern should starts with `match:`,
195
- e.g. `match:*UncheckedCreateInput` see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
278
+ - `typeName` Full or partial name of the class where need to choose input type
279
+ - `property` Property of the class. Special case `ALL` means any/all properties
280
+ - `pattern` Part of name (or full) of type to choose; use `match:*UncheckedCreateInput` for wildcard/negation matching
281
+
282
+ **Legacy (schema.prisma, flatten-style)**:
283
+
284
+ ```sh
285
+ generator nestgraphql {
286
+ useInputType_{typeName}_{property} = "{pattern}"
287
+ }
288
+ ```
196
289
 
197
290
  Example:
198
291
 
@@ -215,7 +308,7 @@ export type UserWhereInput = {
215
308
  ```
216
309
 
217
310
  We have generated types above, by default property `author` will be decorated as `UserRelationFilter`,
218
- to set `UserWhereInput` need to configure generator the following way:
311
+ to set `UserWhereInput` need to configure generator the following way (legacy way):
219
312
 
220
313
  ```prisma
221
314
  generator nestgraphql {
@@ -233,63 +326,85 @@ export class PostWhereInput {
233
326
  }
234
327
  ```
235
328
 
236
- #### `decorate`
329
+ #### `decorators`
237
330
 
238
- Allow to attach multiple decorators to any field of any type.
331
+ Modern way to attach custom decorators in config file (`decorators: DecoratorItem[]`).
239
332
 
240
- ```sh
241
- generator nestgraphql {
242
- decorate_{key}_type = "outmatch pattern"
243
- decorate_{key}_field = "outmatch pattern"
244
- decorate_{key}_from = "module specifier"
245
- decorate_{key}_name = "import name"
246
- decorate_{key}_arguments = "[argument1, argument2]"
247
- decorate_{key}_defaultImport = "default import name" | true
248
- decorate_{key}_namespaceImport = "namespace import name"
249
- decorate_{key}_namedImport = "import name" | true
250
- }
333
+ ```js
334
+ decorators: [
335
+ {
336
+ match: ({ objectName, propertyName }) =>
337
+ objectName === 'CreateOneUserArgs' && propertyName === 'data',
338
+ from: 'class-validator',
339
+ name: 'ValidateNested',
340
+ arguments: [],
341
+ namedImport: true,
342
+ },
343
+ {
344
+ match: ({ objectName, propertyName }) =>
345
+ objectName === 'CreateOneUserArgs' && propertyName === 'data',
346
+ from: 'class-transformer',
347
+ name: 'Type',
348
+ arguments: ['() => {propertyType.0}'],
349
+ namedImport: true,
350
+ },
351
+ ];
251
352
  ```
252
353
 
253
- Where `{key}` any identifier to group values (written in [flatten](https://github.com/hughsk/flat) style)
254
-
255
- - `decorate_{key}_type` - outmatch pattern to match class name
256
- - `decorate_{key}_field` - outmatch pattern to match field name
257
- - `decorate_{key}_from` - module specifier to import from (e.g `class-validator`)
258
- - `decorate_{key}_name` - import name or name with namespace
259
- - `decorate_{key}_defaultImport` - import as default
260
- - `decorate_{key}_namespaceImport` - use this name as import namespace
261
- - `decorate_{key}_namedImport` - named import (without namespace)
262
- - `decorate_{key}_arguments` - arguments for decorator (if decorator need to be called as function)
263
- Special tokens can be used:
264
- - `{propertyType.0}` - field's type (TypeScript type annotation)
265
-
266
- Example of generated class:
354
+ `match` receives one argument `FieldInfo`:
267
355
 
268
356
  ```ts
269
- @ArgsType()
270
- export class CreateOneUserArgs {
271
- @Field(() => UserCreateInput, { nullable: false })
272
- data!: UserCreateInput;
273
- }
357
+ type FieldInfo = {
358
+ /**
359
+ * Prisma DMMF field location type
360
+ * Can be: 'scalar', 'inputObjectTypes', 'outputObjectTypes', 'enumTypes', 'fieldRefTypes'
361
+ */
362
+ location: FieldLocation;
363
+ /**
364
+ * Class name
365
+ */
366
+ objectName: string;
367
+ /**
368
+ * Property name
369
+ */
370
+ propertyName: string;
371
+ /**
372
+ * Property type (may contain TypeScript elements, like parameters for generics, etc.)
373
+ */
374
+ propertyType: string;
375
+ /**
376
+ * GraphQL/Prisma type name
377
+ */
378
+ typeName: string;
379
+ };
274
380
  ```
275
381
 
276
- To make it validateable (assuming `UserCreateInput` already contains validation decorators from `class-validator`),
277
- it is necessary to add `@ValidateNested()` and `@Type()` from `class-transformer`.
382
+ Decorator item type:
278
383
 
279
- ```sh
280
- decorate_1_type = "CreateOneUserArgs"
281
- decorate_1_field = data
282
- decorate_1_name = ValidateNested
283
- decorate_1_from = "class-validator"
284
- decorate_1_arguments = "[]"
285
- decorate_2_type = "CreateOneUserArgs"
286
- decorate_2_field = data
287
- decorate_2_from = "class-transformer"
288
- decorate_2_arguments = "['() => {propertyType.0}']"
289
- decorate_2_name = Type
384
+ ```ts
385
+ type DecoratorItem = {
386
+ /** Return `true` to apply this decorator to the current field. */
387
+ match: (args: FieldInfo) => boolean;
388
+ /** Arguments passed to the decorator call.
389
+ * Supports templates like `{propertyType.0}`. */
390
+ arguments?: string[];
391
+ /** Module specifier to import from (e.g. 'class-validator') */
392
+ from: string;
393
+ /** Decorator name. Can include namespace, e.g. `Transform.Type`. */
394
+ name: string;
395
+ /** Import as a named export. */
396
+ namedImport: boolean;
397
+ /** Import as default export.
398
+ * Use `true` to import by decorator name. */
399
+ defaultImport?: string | true;
400
+ /** Import entire module under this namespace. */
401
+ namespaceImport?: string;
402
+ };
290
403
  ```
291
404
 
292
- Result:
405
+ Special token in arguments: `{propertyType.0}` resolves to the field's TypeScript type.
406
+
407
+ Example result:
293
408
 
294
409
  ```ts
295
410
  import { ValidateNested } from 'class-validator';
@@ -304,48 +419,38 @@ export class CreateOneUserArgs {
304
419
  }
305
420
  ```
306
421
 
307
- Another example:
422
+ **Legacy (`decorate` / `decorate_*`)**
308
423
 
309
- ```sh
310
- decorate_2_namespaceImport = "Transform"
311
- decorate_2_name = "Transform.Type"
312
- ```
313
-
314
- ```ts
315
- import * as Transform from 'class-transformer';
316
-
317
- @Transform.Type(() => UserCreateInput)
318
- data!: UserCreateInput;
424
+ Legacy flatten-style keys in `schema.prisma` are still supported for backward compatibility:
319
425
 
426
+ ```sh
427
+ generator nestgraphql {
428
+ decorate_{key}_type = "outmatch pattern"
429
+ decorate_{key}_field = "outmatch pattern"
430
+ decorate_{key}_from = "module specifier"
431
+ decorate_{key}_name = "import name"
432
+ decorate_{key}_arguments = "[argument1, argument2]"
433
+ decorate_{key}_defaultImport = "default import name" | true
434
+ decorate_{key}_namespaceImport = "namespace import name"
435
+ decorate_{key}_namedImport = "import name" | true
436
+ }
320
437
  ```
321
438
 
322
- Add `@HideField()` decorator to nested types:
439
+ Prefer `decorators` in `nestgraphql.config.*` for new configuration.
323
440
 
324
- ```
325
- decorate_3_type = "*CreateNestedOneWithoutUserInput"
326
- decorate_3_field = "!(create)"
327
- decorate_3_name = "HideField"
328
- decorate_3_from = "@nestjs/graphql"
329
- decorate_3_arguments = "[]"
330
- ```
331
-
332
- May generate following class:
441
+ #### `graphqlScalars`
333
442
 
334
- ```ts
335
- @Field(() => ProfileCreateWithoutUserInput, { nullable: true })
336
- create?: ProfileCreateWithoutUserInput;
443
+ Allow to set custom graphql type for Prisma scalar type.
337
444
 
338
- @HideField()
339
- connectOrCreate?: ProfileCreateOrConnectWithoutUserInput;
445
+ **New (config file)**:
340
446
 
341
- @HideField()
342
- connect?: ProfileWhereUniqueInput;
447
+ ```js
448
+ graphqlScalars: {
449
+ BigInt: { name: 'GraphQLBigInt', specifier: 'graphql-scalars' },
450
+ }
343
451
  ```
344
452
 
345
- #### `graphqlScalars`
346
-
347
- Allow to set custom graphql type for Prisma scalar type.
348
- Format:
453
+ **Legacy (schema.prisma, flatten-style)**:
349
454
 
350
455
  ```
351
456
  graphqlScalars_{type}_name = "string"
@@ -374,17 +479,29 @@ export class BigIntFilter {
374
479
 
375
480
  It will affect all inputs and outputs types (including models).
376
481
 
377
- #### `customImport`
482
+ #### `customImports`
483
+
484
+ Allow to declare custom import statements.
485
+ **Note**: Only works with `emitSingle = true`
486
+
487
+ **New (config file)**:
378
488
 
379
- Allow to declare custom import statements. (Only works with emitSingle = true)
489
+ ```js
490
+ customImports: [
491
+ { from: 'nestjs-i18n', name: 'I18n', defaultImport: true },
492
+ { from: 'class-transformer', name: 'Transform', namedImport: true },
493
+ ];
494
+ ```
495
+
496
+ **Legacy (schema.prisma, flatten-style)**:
380
497
 
381
498
  ```sh
382
499
  generator nestgraphql {
383
- customImport_{key}_from = "module specifier"
384
- customImport_{key}_name = "import name"
385
- customImport_{key}_defaultImport = "default import name" | true
386
- customImport_{key}_namespaceImport = "namespace import name"
387
- customImport_{key}_namedImport = "import name" | true
500
+ customImport_{key}_from = "module specifier"
501
+ customImport_{key}_name = "import name"
502
+ customImport_{key}_defaultImport = "default import name" | true
503
+ customImport_{key}_namespaceImport = "namespace import name"
504
+ customImport_{key}_namedImport = "import name" | true
388
505
  }
389
506
  ```
390
507
 
@@ -396,6 +513,55 @@ Where `{key}` any identifier to group values (written in [flatten](https://githu
396
513
  - `customImport_{key}_namespaceImport` - use this name as import namespace
397
514
  - `customImport_{key}_namedImport` - named import (without namespace)
398
515
 
516
+ #### `fieldDecoratorArguments`
517
+
518
+ Override `@Field()` decorator arguments for specific fields. Use this to customize pagination fields (take, skip, cursor) or other generated Args fields that don't come from your Prisma schema.
519
+
520
+ Each rule is evaluated against generated field metadata and applied when the `match` function returns `true`. Multiple matching rules are merged in order.
521
+
522
+ **New (config file)**:
523
+
524
+ ```js
525
+ fieldDecoratorArguments: [
526
+ {
527
+ match: ({ objectName, propertyName }) =>
528
+ objectName.endsWith('Args') && propertyName === 'take',
529
+ decoratorArguments: {
530
+ name: 'first',
531
+ defaultValue: 10,
532
+ description: 'Number of records to return',
533
+ },
534
+ },
535
+ {
536
+ match: ({ objectName, propertyName }) =>
537
+ objectName.endsWith('Args') && propertyName === 'skip',
538
+ decoratorArguments: {
539
+ name: 'offset',
540
+ defaultValue: 0,
541
+ description: 'Number of records to skip',
542
+ },
543
+ },
544
+ ]
545
+ ```
546
+
547
+ **Available `decoratorArguments` options:**
548
+ - `nullable` — Mark field as nullable in GraphQL schema
549
+ - `defaultValue` — Default value for the field
550
+ - `description` — Description shown in GraphQL schema
551
+ - `deprecationReason` — Mark field as deprecated
552
+ - `name` — Custom name for the field in GraphQL schema (TypeScript property name stays the same)
553
+ - `complexity` — Complexity value for query cost analysis
554
+ - `middleware` — Array of field middleware functions
555
+
556
+ **Note:** When using the `name` option to override a field name in GraphQL, ensure you understand Prisma field mapping. For example, if you override the `take` field name to `first`, you must update any Prisma query logic that references the field by its original name. Consider using a mapping helper if doing this across multiple queries.
557
+
558
+ The `match` function receives `FieldInfo` with:
559
+ - `objectName` — Class name (e.g., 'FindManyUserArgs')
560
+ - `propertyName` — Property name (e.g., 'take', 'skip')
561
+ - `propertyType` — TypeScript property type
562
+ - `typeName` — GraphQL/Prisma type name
563
+ - `location` — Prisma field location ('scalar', 'inputObjectTypes', etc.)
564
+
399
565
  ## Documentation and field options
400
566
 
401
567
  Comments with triple slash will projected to typescript code comments
@@ -436,14 +602,26 @@ Special directives in triple slash comments for more precise code generation.
436
602
 
437
603
  #### @HideField()
438
604
 
439
- Removes field from GraphQL schema.
440
- Alias: `@TypeGraphQL.omit(output: true)`
441
-
442
- By default (without arguments) field will be decorated for hide only in output types (type in schema).
443
- To hide field in input types add `input: true`.
605
+ Removes field from GraphQL schema.
606
+ By default (without arguments) field will be decorated for hide only in output types (type in schema).
607
+ To hide field in input types add `input: true`.
444
608
  To hide field in specific type you can use glob pattern `match: string | string[]`
445
609
  see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
446
610
 
611
+ For config-file based rules, use `shouldHideField`:
612
+
613
+ ```js
614
+ export default {
615
+ shouldHideField: ({ location, objectName, propertyName }) =>
616
+ location === 'inputObjectTypes' &&
617
+ objectName.endsWith('CreateInput') &&
618
+ ['id', 'createdAt', 'updatedAt'].includes(propertyName),
619
+ };
620
+ ```
621
+
622
+ The callback receives `FieldInfo` (`location`, `objectName`, `propertyName`, `propertyType`, `typeName`).
623
+ When `shouldHideField` is defined, it overrides `@HideField(...)` settings from field comments and legacy `decorate` rules.
624
+
447
625
  Examples:
448
626
 
449
627
  - `@HideField()` same as `@HideField({ output: true })`
@@ -452,13 +630,13 @@ Examples:
452
630
 
453
631
  ```prisma
454
632
  model User {
455
- id String @id @default(cuid())
456
- /// @HideField()
457
- password String
458
- /// @HideField({ output: true, input: true })
459
- secret String
460
- /// @HideField({ match: '@(User|Comment)Create*Input' })
461
- createdAt DateTime @default(now())
633
+ id String @id @default(cuid())
634
+ /// @HideField()
635
+ password String
636
+ /// @HideField({ output: true, input: true })
637
+ secret String
638
+ /// @HideField({ match: '@(User|Comment)Create*Input' })
639
+ createdAt DateTime @default(now())
462
640
  }
463
641
  ```
464
642
 
@@ -492,77 +670,78 @@ export class UserCreateInput {
492
670
 
493
671
  Applying custom decorators requires configuration of generator.
494
672
 
495
- ```sh
673
+ ```prisma
674
+ // Legacy configuration, prefer config file
496
675
  generator nestgraphql {
497
- fields_{namespace}_from = "module specifier"
498
- fields_{namespace}_input = true | false
499
- fields_{namespace}_output = true | false
500
- fields_{namespace}_model = true | false
501
- fields_{namespace}_defaultImport = "default import name" | true
502
- fields_{namespace}_namespaceImport = "namespace import name"
503
- fields_{namespace}_namedImport = true | false
676
+ fields_{namespace}_from = "module specifier"
677
+ fields_{namespace}_input = true | false
678
+ fields_{namespace}_output = true | false
679
+ fields_{namespace}_model = true | false
680
+ fields_{namespace}_defaultImport = "default import name" | true
681
+ fields_{namespace}_namespaceImport = "namespace import name"
682
+ fields_{namespace}_namedImport = true | false
504
683
  }
505
684
  ```
506
685
 
507
- Create configuration map in [flatten](https://github.com/hughsk/flat) style for `{namespace}`.
686
+ Create configuration map in [flatten](https://github.com/hughsk/flat) style for `{namespace}`.
508
687
  Where `{namespace}` is a namespace used in field triple slash comment.
509
688
 
510
689
  ##### `fields_{namespace}_from`
511
690
 
512
- Required. Name of the module, which will be used in import (`class-validator`, `graphql-scalars`, etc.)
691
+ Required. Name of the module, which will be used in import (`class-validator`, `graphql-scalars`, etc.)
513
692
  Type: `string`
514
693
 
515
694
  ##### `fields_{namespace}_input`
516
695
 
517
- Means that it will be applied on input types (classes decorated by `InputType`)
518
- Type: `boolean`
696
+ Means that it will be applied on input types (classes decorated by `InputType`)
697
+ Type: `boolean`
519
698
  Default: `false`
520
699
 
521
700
  ##### `fields_{namespace}_output`
522
701
 
523
702
  Means that it will be applied on output types (classes decorated by `ObjectType`),
524
- including models
525
- Type: `boolean`
703
+ including models
704
+ Type: `boolean`
526
705
  Default: `false`
527
706
 
528
707
  ##### `fields_{namespace}_model`
529
708
 
530
- Means that it will be applied only on model types (classes decorated by `ObjectType`)
531
- Type: `boolean`
709
+ Means that it will be applied only on model types (classes decorated by `ObjectType`)
710
+ Type: `boolean`
532
711
  Default: `false`
533
712
 
534
713
  ##### `fields_{namespace}_defaultImport`
535
714
 
536
- Default import name, if module have no namespace.
537
- Type: `undefined | string | true`
538
- Default: `undefined`
715
+ Default import name, if module have no namespace.
716
+ Type: `undefined | string | true`
717
+ Default: `undefined`
539
718
  If defined as `true` then import name will be same as `{namespace}`
540
719
 
541
720
  ##### `fields_{namespace}_namespaceImport`
542
721
 
543
- Import all as this namespace from module
544
- Type: `undefined | string`
722
+ Import all as this namespace from module
723
+ Type: `undefined | string`
545
724
  Default: Equals to `{namespace}`
546
725
 
547
726
  ##### `fields_{namespace}_namedImport`
548
727
 
549
- If imported module has internal namespace, this allow to generate named import,
550
- imported name will be equal to `{namespace}`, see [example of usage](#propertytype)
551
- Type: `boolean`
728
+ If imported module has internal namespace, this allow to generate named import,
729
+ imported name will be equal to `{namespace}`, see [example of usage](#propertytype)
730
+ Type: `boolean`
552
731
  Default: `false`
553
732
 
554
733
  Custom decorators example:
555
734
 
556
735
  ```prisma
557
736
  generator nestgraphql {
558
- fields_Validator_from = "class-validator"
559
- fields_Validator_input = true
737
+ fields_Validator_from = "class-validator"
738
+ fields_Validator_input = true
560
739
  }
561
740
 
562
741
  model User {
563
- id Int @id
564
- /// @Validator.MinLength(3)
565
- name String
742
+ id Int @id
743
+ /// @Validator.MinLength(3)
744
+ name String
566
745
  }
567
746
  ```
568
747
 
@@ -586,14 +765,14 @@ Custom decorators can be applied on classes (models):
586
765
  /// @NG.Directive('@extends')
587
766
  /// @NG.Directive('@key(fields: "id")')
588
767
  model User {
589
- /// @NG.Directive('@external')
590
- id String @id
768
+ /// @NG.Directive('@external')
769
+ id String @id
591
770
  }
592
771
 
593
772
  generator nestgraphql {
594
- fields_NG_from = "@nestjs/graphql"
595
- fields_NG_output = false
596
- fields_NG_model = true
773
+ fields_NG_from = "@nestjs/graphql"
774
+ fields_NG_output = false
775
+ fields_NG_model = true
597
776
  }
598
777
  ```
599
778
 
@@ -605,9 +784,9 @@ import * as NG from '@nestjs/graphql';
605
784
  @NG.Directive('@extends')
606
785
  @NG.Directive('@key(fields: "id")')
607
786
  export class User {
608
- @Field(() => ID, { nullable: false })
609
- @NG.Directive('@external')
610
- id!: string;
787
+ @Field(() => ID, { nullable: false })
788
+ @NG.Directive('@external')
789
+ id!: string;
611
790
  ```
612
791
 
613
792
  #### @FieldType()
@@ -619,9 +798,9 @@ see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
619
798
 
620
799
  ```prisma
621
800
  model User {
622
- id Int @id
623
- /// @FieldType({ name: 'Scalars.GraphQLEmailAddress', from: 'graphql-scalars', input: true })
624
- email String
801
+ id Int @id
802
+ /// @FieldType({ name: 'Scalars.GraphQLEmailAddress', from: 'graphql-scalars', input: true })
803
+ email String
625
804
  }
626
805
  ```
627
806
 
@@ -644,7 +823,7 @@ And following GraphQL schema:
644
823
  scalar EmailAddress
645
824
 
646
825
  input UserCreateInput {
647
- email: EmailAddress!
826
+ email: EmailAddress!
648
827
  }
649
828
  ```
650
829
 
@@ -653,15 +832,15 @@ There is a shortcut:
653
832
 
654
833
  ```grapqhl
655
834
  generator nestgraphql {
656
- fields_Scalars_from = "graphql-scalars"
657
- fields_Scalars_input = true
658
- fields_Scalars_output = true
835
+ fields_Scalars_from = "graphql-scalars"
836
+ fields_Scalars_input = true
837
+ fields_Scalars_output = true
659
838
  }
660
839
 
661
840
  model User {
662
- id Int @id
663
- /// @FieldType('Scalars.GraphQLEmailAddress')
664
- email String
841
+ id Int @id
842
+ /// @FieldType('Scalars.GraphQLEmailAddress')
843
+ email String
665
844
  }
666
845
  ```
667
846
 
@@ -679,13 +858,13 @@ Example:
679
858
 
680
859
  ```
681
860
  generator nestgraphql {
682
- fields_TF_from = "type-fest"
861
+ fields_TF_from = "type-fest"
683
862
  }
684
863
 
685
864
  model User {
686
- id String @id
687
- /// @PropertyType('TF.JsonObject')
688
- data Json
865
+ id String @id
866
+ /// @PropertyType('TF.JsonObject')
867
+ data Json
689
868
  }
690
869
  ```
691
870
 
@@ -711,8 +890,8 @@ GraphQL federation example:
711
890
  /// @Directive({ arguments: ['@extends'] })
712
891
  /// @Directive({ arguments: ['@key(fields: "id")'] })
713
892
  model User {
714
- /// @Directive({ arguments: ['@external'] })
715
- id String @id
893
+ /// @Directive({ arguments: ['@external'] })
894
+ id String @id
716
895
  }
717
896
  ```
718
897
 
@@ -739,7 +918,7 @@ Example 1:
739
918
  // schema.prisma
740
919
  /// @ObjectType({ isAbstract: true })
741
920
  model User {
742
- id Int @id
921
+ id Int @id
743
922
  }
744
923
  ```
745
924
 
@@ -754,7 +933,7 @@ Example 2:
754
933
  // schema.prisma
755
934
  /// @ObjectType('Human', { isAbstract: true })
756
935
  model User {
757
- id Int @id
936
+ id Int @id
758
937
  }
759
938
  ```
760
939
 
@@ -795,12 +974,12 @@ import { generate } from 'prisma-nestjs-graphql';
795
974
 
796
975
  ## TODO
797
976
 
798
- - noAtomicOperations = 1, IntFieldUpdateOperationsInput exists
799
977
  - CommentUncheckedUpdateManyWithoutAuthorNestedInput and CommentUpdateManyWithoutAuthorNestedInput are same
800
978
  - Add logic to detect view models and skip generation of mutation inputs/args for them https://github.com/unlight/prisma-nestjs-graphql/issues/248
801
979
  - dummy-createfriends.input.ts -> `create-friends`
802
980
  - check 'TODO FIXME'
981
+ - rework test, use setup file
803
982
 
804
983
  ## License
805
984
 
806
- [MIT License](https://opensource.org/licenses/MIT) (c) 2025
985
+ [MIT License](https://opensource.org/licenses/MIT) (c) 2026