prisma-nestjs-graphql 23.0.1 → 23.1.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 +285 -156
- package/bin.mjs +1 -0
- package/package.json +9 -7
- package/prisma-nestjs-graphql.d.ts +378 -49
- package/prisma-nestjs-graphql.mjs +749 -370
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
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
2.
|
|
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"
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
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`
|
|
@@ -122,9 +191,7 @@ 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.
|
|
194
|
+
Emit compiled JavaScript and definitions instead of TypeScript sources.
|
|
128
195
|
Type: `boolean`
|
|
129
196
|
Default: `false`
|
|
130
197
|
|
|
@@ -174,25 +241,51 @@ See [#177](https://github.com/unlight/prisma-nestjs-graphql/issues/177) for more
|
|
|
174
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,28 @@ export class BigIntFilter {
|
|
|
374
479
|
|
|
375
480
|
It will affect all inputs and outputs types (including models).
|
|
376
481
|
|
|
377
|
-
#### `
|
|
482
|
+
#### `customImports`
|
|
378
483
|
|
|
379
484
|
Allow to declare custom import statements. (Only works with emitSingle = true)
|
|
380
485
|
|
|
486
|
+
**New (config file)**:
|
|
487
|
+
|
|
488
|
+
```js
|
|
489
|
+
customImports: [
|
|
490
|
+
{ from: 'nestjs-i18n', name: 'I18n', defaultImport: true },
|
|
491
|
+
{ from: 'class-transformer', name: 'Transform', namedImport: true },
|
|
492
|
+
];
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**Legacy (schema.prisma, flatten-style)**:
|
|
496
|
+
|
|
381
497
|
```sh
|
|
382
498
|
generator nestgraphql {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
499
|
+
customImport_{key}_from = "module specifier"
|
|
500
|
+
customImport_{key}_name = "import name"
|
|
501
|
+
customImport_{key}_defaultImport = "default import name" | true
|
|
502
|
+
customImport_{key}_namespaceImport = "namespace import name"
|
|
503
|
+
customImport_{key}_namedImport = "import name" | true
|
|
388
504
|
}
|
|
389
505
|
```
|
|
390
506
|
|
|
@@ -437,13 +553,25 @@ Special directives in triple slash comments for more precise code generation.
|
|
|
437
553
|
#### @HideField()
|
|
438
554
|
|
|
439
555
|
Removes field from GraphQL schema.
|
|
440
|
-
Alias: `@TypeGraphQL.omit(output: true)`
|
|
441
|
-
|
|
442
556
|
By default (without arguments) field will be decorated for hide only in output types (type in schema).
|
|
443
557
|
To hide field in input types add `input: true`.
|
|
444
558
|
To hide field in specific type you can use glob pattern `match: string | string[]`
|
|
445
559
|
see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
446
560
|
|
|
561
|
+
For config-file based rules, use `shouldHideField`:
|
|
562
|
+
|
|
563
|
+
```js
|
|
564
|
+
export default {
|
|
565
|
+
shouldHideField: ({ location, objectName, propertyName }) =>
|
|
566
|
+
location === 'inputObjectTypes' &&
|
|
567
|
+
objectName.endsWith('CreateInput') &&
|
|
568
|
+
['id', 'createdAt', 'updatedAt'].includes(propertyName),
|
|
569
|
+
};
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
The callback receives `FieldInfo` (`location`, `objectName`, `propertyName`, `propertyType`, `typeName`).
|
|
573
|
+
When `shouldHideField` is defined, it overrides `@HideField(...)` settings from field comments and legacy `decorate` rules.
|
|
574
|
+
|
|
447
575
|
Examples:
|
|
448
576
|
|
|
449
577
|
- `@HideField()` same as `@HideField({ output: true })`
|
|
@@ -452,13 +580,13 @@ Examples:
|
|
|
452
580
|
|
|
453
581
|
```prisma
|
|
454
582
|
model User {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
583
|
+
id String @id @default(cuid())
|
|
584
|
+
/// @HideField()
|
|
585
|
+
password String
|
|
586
|
+
/// @HideField({ output: true, input: true })
|
|
587
|
+
secret String
|
|
588
|
+
/// @HideField({ match: '@(User|Comment)Create*Input' })
|
|
589
|
+
createdAt DateTime @default(now())
|
|
462
590
|
}
|
|
463
591
|
```
|
|
464
592
|
|
|
@@ -492,15 +620,16 @@ export class UserCreateInput {
|
|
|
492
620
|
|
|
493
621
|
Applying custom decorators requires configuration of generator.
|
|
494
622
|
|
|
495
|
-
```
|
|
623
|
+
```prisma
|
|
624
|
+
// Legacy configuration, prefer config file
|
|
496
625
|
generator nestgraphql {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
626
|
+
fields_{namespace}_from = "module specifier"
|
|
627
|
+
fields_{namespace}_input = true | false
|
|
628
|
+
fields_{namespace}_output = true | false
|
|
629
|
+
fields_{namespace}_model = true | false
|
|
630
|
+
fields_{namespace}_defaultImport = "default import name" | true
|
|
631
|
+
fields_{namespace}_namespaceImport = "namespace import name"
|
|
632
|
+
fields_{namespace}_namedImport = true | false
|
|
504
633
|
}
|
|
505
634
|
```
|
|
506
635
|
|
|
@@ -555,14 +684,14 @@ Custom decorators example:
|
|
|
555
684
|
|
|
556
685
|
```prisma
|
|
557
686
|
generator nestgraphql {
|
|
558
|
-
|
|
559
|
-
|
|
687
|
+
fields_Validator_from = "class-validator"
|
|
688
|
+
fields_Validator_input = true
|
|
560
689
|
}
|
|
561
690
|
|
|
562
691
|
model User {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
692
|
+
id Int @id
|
|
693
|
+
/// @Validator.MinLength(3)
|
|
694
|
+
name String
|
|
566
695
|
}
|
|
567
696
|
```
|
|
568
697
|
|
|
@@ -586,14 +715,14 @@ Custom decorators can be applied on classes (models):
|
|
|
586
715
|
/// @NG.Directive('@extends')
|
|
587
716
|
/// @NG.Directive('@key(fields: "id")')
|
|
588
717
|
model User {
|
|
589
|
-
|
|
590
|
-
|
|
718
|
+
/// @NG.Directive('@external')
|
|
719
|
+
id String @id
|
|
591
720
|
}
|
|
592
721
|
|
|
593
722
|
generator nestgraphql {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
723
|
+
fields_NG_from = "@nestjs/graphql"
|
|
724
|
+
fields_NG_output = false
|
|
725
|
+
fields_NG_model = true
|
|
597
726
|
}
|
|
598
727
|
```
|
|
599
728
|
|
|
@@ -605,9 +734,9 @@ import * as NG from '@nestjs/graphql';
|
|
|
605
734
|
@NG.Directive('@extends')
|
|
606
735
|
@NG.Directive('@key(fields: "id")')
|
|
607
736
|
export class User {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
737
|
+
@Field(() => ID, { nullable: false })
|
|
738
|
+
@NG.Directive('@external')
|
|
739
|
+
id!: string;
|
|
611
740
|
```
|
|
612
741
|
|
|
613
742
|
#### @FieldType()
|
|
@@ -619,9 +748,9 @@ see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
|
619
748
|
|
|
620
749
|
```prisma
|
|
621
750
|
model User {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
751
|
+
id Int @id
|
|
752
|
+
/// @FieldType({ name: 'Scalars.GraphQLEmailAddress', from: 'graphql-scalars', input: true })
|
|
753
|
+
email String
|
|
625
754
|
}
|
|
626
755
|
```
|
|
627
756
|
|
|
@@ -644,7 +773,7 @@ And following GraphQL schema:
|
|
|
644
773
|
scalar EmailAddress
|
|
645
774
|
|
|
646
775
|
input UserCreateInput {
|
|
647
|
-
|
|
776
|
+
email: EmailAddress!
|
|
648
777
|
}
|
|
649
778
|
```
|
|
650
779
|
|
|
@@ -653,15 +782,15 @@ There is a shortcut:
|
|
|
653
782
|
|
|
654
783
|
```grapqhl
|
|
655
784
|
generator nestgraphql {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
785
|
+
fields_Scalars_from = "graphql-scalars"
|
|
786
|
+
fields_Scalars_input = true
|
|
787
|
+
fields_Scalars_output = true
|
|
659
788
|
}
|
|
660
789
|
|
|
661
790
|
model User {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
791
|
+
id Int @id
|
|
792
|
+
/// @FieldType('Scalars.GraphQLEmailAddress')
|
|
793
|
+
email String
|
|
665
794
|
}
|
|
666
795
|
```
|
|
667
796
|
|
|
@@ -679,13 +808,13 @@ Example:
|
|
|
679
808
|
|
|
680
809
|
```
|
|
681
810
|
generator nestgraphql {
|
|
682
|
-
|
|
811
|
+
fields_TF_from = "type-fest"
|
|
683
812
|
}
|
|
684
813
|
|
|
685
814
|
model User {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
815
|
+
id String @id
|
|
816
|
+
/// @PropertyType('TF.JsonObject')
|
|
817
|
+
data Json
|
|
689
818
|
}
|
|
690
819
|
```
|
|
691
820
|
|
|
@@ -711,8 +840,8 @@ GraphQL federation example:
|
|
|
711
840
|
/// @Directive({ arguments: ['@extends'] })
|
|
712
841
|
/// @Directive({ arguments: ['@key(fields: "id")'] })
|
|
713
842
|
model User {
|
|
714
|
-
|
|
715
|
-
|
|
843
|
+
/// @Directive({ arguments: ['@external'] })
|
|
844
|
+
id String @id
|
|
716
845
|
}
|
|
717
846
|
```
|
|
718
847
|
|
|
@@ -739,7 +868,7 @@ Example 1:
|
|
|
739
868
|
// schema.prisma
|
|
740
869
|
/// @ObjectType({ isAbstract: true })
|
|
741
870
|
model User {
|
|
742
|
-
|
|
871
|
+
id Int @id
|
|
743
872
|
}
|
|
744
873
|
```
|
|
745
874
|
|
|
@@ -754,7 +883,7 @@ Example 2:
|
|
|
754
883
|
// schema.prisma
|
|
755
884
|
/// @ObjectType('Human', { isAbstract: true })
|
|
756
885
|
model User {
|
|
757
|
-
|
|
886
|
+
id Int @id
|
|
758
887
|
}
|
|
759
888
|
```
|
|
760
889
|
|
|
@@ -795,12 +924,12 @@ import { generate } from 'prisma-nestjs-graphql';
|
|
|
795
924
|
|
|
796
925
|
## TODO
|
|
797
926
|
|
|
798
|
-
- noAtomicOperations = 1, IntFieldUpdateOperationsInput exists
|
|
799
927
|
- CommentUncheckedUpdateManyWithoutAuthorNestedInput and CommentUpdateManyWithoutAuthorNestedInput are same
|
|
800
928
|
- 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
929
|
- dummy-createfriends.input.ts -> `create-friends`
|
|
802
930
|
- check 'TODO FIXME'
|
|
931
|
+
- rework test, use setup file
|
|
803
932
|
|
|
804
933
|
## License
|
|
805
934
|
|
|
806
|
-
[MIT License](https://opensource.org/licenses/MIT) (c)
|
|
935
|
+
[MIT License](https://opensource.org/licenses/MIT) (c) 2026
|