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/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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
#### `
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
191
|
-
|
|
192
|
-
- `
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
#### `
|
|
329
|
+
#### `decorators`
|
|
237
330
|
|
|
238
|
-
|
|
331
|
+
Modern way to attach custom decorators in config file (`decorators: DecoratorItem[]`).
|
|
239
332
|
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
277
|
-
it is necessary to add `@ValidateNested()` and `@Type()` from `class-transformer`.
|
|
382
|
+
Decorator item type:
|
|
278
383
|
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
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
|
-
|
|
422
|
+
**Legacy (`decorate` / `decorate_*`)**
|
|
308
423
|
|
|
309
|
-
|
|
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
|
-
|
|
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
|
-
|
|
335
|
-
@Field(() => ProfileCreateWithoutUserInput, { nullable: true })
|
|
336
|
-
create?: ProfileCreateWithoutUserInput;
|
|
443
|
+
Allow to set custom graphql type for Prisma scalar type.
|
|
337
444
|
|
|
338
|
-
|
|
339
|
-
connectOrCreate?: ProfileCreateOrConnectWithoutUserInput;
|
|
445
|
+
**New (config file)**:
|
|
340
446
|
|
|
341
|
-
|
|
342
|
-
|
|
447
|
+
```js
|
|
448
|
+
graphqlScalars: {
|
|
449
|
+
BigInt: { name: 'GraphQLBigInt', specifier: 'graphql-scalars' },
|
|
450
|
+
}
|
|
343
451
|
```
|
|
344
452
|
|
|
345
|
-
|
|
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
|
-
#### `
|
|
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
|
-
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
```
|
|
673
|
+
```prisma
|
|
674
|
+
// Legacy configuration, prefer config file
|
|
496
675
|
generator nestgraphql {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
559
|
-
|
|
737
|
+
fields_Validator_from = "class-validator"
|
|
738
|
+
fields_Validator_input = true
|
|
560
739
|
}
|
|
561
740
|
|
|
562
741
|
model User {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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
|
-
|
|
590
|
-
|
|
768
|
+
/// @NG.Directive('@external')
|
|
769
|
+
id String @id
|
|
591
770
|
}
|
|
592
771
|
|
|
593
772
|
generator nestgraphql {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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
|
-
|
|
609
|
-
|
|
610
|
-
|
|
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
|
-
|
|
623
|
-
|
|
624
|
-
|
|
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
|
-
|
|
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
|
-
|
|
657
|
-
|
|
658
|
-
|
|
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
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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
|
-
|
|
861
|
+
fields_TF_from = "type-fest"
|
|
683
862
|
}
|
|
684
863
|
|
|
685
864
|
model User {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
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
|
-
|
|
715
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
|
985
|
+
[MIT License](https://opensource.org/licenses/MIT) (c) 2026
|