prisma-nestjs-graphql 23.0.0 → 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 +292 -156
- package/bin.mjs +1 -0
- package/package.json +9 -7
- package/prisma-nestjs-graphql.d.ts +378 -48
- package/prisma-nestjs-graphql.mjs +800 -382
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`
|
|
@@ -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
|
|
|
@@ -152,6 +219,13 @@ Disable usage of graphql `ID` type and use `Int/Float` for fields marked as `@id
|
|
|
152
219
|
Type: `boolean`
|
|
153
220
|
Default: `false`
|
|
154
221
|
|
|
222
|
+
#### `typeListNullable`
|
|
223
|
+
|
|
224
|
+
Adds `nullable: true` for relation list properties out output models,
|
|
225
|
+
it makes graphql field looks like `[Type!]`, default `[Type!]!`
|
|
226
|
+
Type: `boolean`
|
|
227
|
+
Default: `false`
|
|
228
|
+
|
|
155
229
|
#### `requireSingleFieldsInWhereUniqueInput`
|
|
156
230
|
|
|
157
231
|
When a model `*WhereUniqueInput` class has only a single field, mark that field as **required** (TypeScript) and **not nullable** (GraphQL).
|
|
@@ -167,25 +241,51 @@ See [#177](https://github.com/unlight/prisma-nestjs-graphql/issues/177) for more
|
|
|
167
241
|
Type: `boolean`
|
|
168
242
|
Default: `false`
|
|
169
243
|
|
|
170
|
-
#### `
|
|
244
|
+
#### `inputType`
|
|
171
245
|
|
|
172
246
|
Since GraphQL does not support input union type, this setting map
|
|
173
247
|
allow to choose which input type is preferable.
|
|
174
248
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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;
|
|
179
274
|
```
|
|
180
275
|
|
|
181
276
|
Where:
|
|
182
277
|
|
|
183
|
-
- `typeName` Full
|
|
184
|
-
|
|
185
|
-
- `
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
+
```
|
|
189
289
|
|
|
190
290
|
Example:
|
|
191
291
|
|
|
@@ -208,7 +308,7 @@ export type UserWhereInput = {
|
|
|
208
308
|
```
|
|
209
309
|
|
|
210
310
|
We have generated types above, by default property `author` will be decorated as `UserRelationFilter`,
|
|
211
|
-
to set `UserWhereInput` need to configure generator the following way:
|
|
311
|
+
to set `UserWhereInput` need to configure generator the following way (legacy way):
|
|
212
312
|
|
|
213
313
|
```prisma
|
|
214
314
|
generator nestgraphql {
|
|
@@ -226,63 +326,85 @@ export class PostWhereInput {
|
|
|
226
326
|
}
|
|
227
327
|
```
|
|
228
328
|
|
|
229
|
-
#### `
|
|
329
|
+
#### `decorators`
|
|
230
330
|
|
|
231
|
-
|
|
331
|
+
Modern way to attach custom decorators in config file (`decorators: DecoratorItem[]`).
|
|
232
332
|
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
+
];
|
|
244
352
|
```
|
|
245
353
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
- `decorate_{key}_type` - outmatch pattern to match class name
|
|
249
|
-
- `decorate_{key}_field` - outmatch pattern to match field name
|
|
250
|
-
- `decorate_{key}_from` - module specifier to import from (e.g `class-validator`)
|
|
251
|
-
- `decorate_{key}_name` - import name or name with namespace
|
|
252
|
-
- `decorate_{key}_defaultImport` - import as default
|
|
253
|
-
- `decorate_{key}_namespaceImport` - use this name as import namespace
|
|
254
|
-
- `decorate_{key}_namedImport` - named import (without namespace)
|
|
255
|
-
- `decorate_{key}_arguments` - arguments for decorator (if decorator need to be called as function)
|
|
256
|
-
Special tokens can be used:
|
|
257
|
-
- `{propertyType.0}` - field's type (TypeScript type annotation)
|
|
258
|
-
|
|
259
|
-
Example of generated class:
|
|
354
|
+
`match` receives one argument `FieldInfo`:
|
|
260
355
|
|
|
261
356
|
```ts
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
+
};
|
|
267
380
|
```
|
|
268
381
|
|
|
269
|
-
|
|
270
|
-
it is necessary to add `@ValidateNested()` and `@Type()` from `class-transformer`.
|
|
382
|
+
Decorator item type:
|
|
271
383
|
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
+
};
|
|
283
403
|
```
|
|
284
404
|
|
|
285
|
-
|
|
405
|
+
Special token in arguments: `{propertyType.0}` resolves to the field's TypeScript type.
|
|
406
|
+
|
|
407
|
+
Example result:
|
|
286
408
|
|
|
287
409
|
```ts
|
|
288
410
|
import { ValidateNested } from 'class-validator';
|
|
@@ -297,48 +419,38 @@ export class CreateOneUserArgs {
|
|
|
297
419
|
}
|
|
298
420
|
```
|
|
299
421
|
|
|
300
|
-
|
|
422
|
+
**Legacy (`decorate` / `decorate_*`)**
|
|
301
423
|
|
|
302
|
-
|
|
303
|
-
decorate_2_namespaceImport = "Transform"
|
|
304
|
-
decorate_2_name = "Transform.Type"
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
```ts
|
|
308
|
-
import * as Transform from 'class-transformer';
|
|
309
|
-
|
|
310
|
-
@Transform.Type(() => UserCreateInput)
|
|
311
|
-
data!: UserCreateInput;
|
|
424
|
+
Legacy flatten-style keys in `schema.prisma` are still supported for backward compatibility:
|
|
312
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
|
+
}
|
|
313
437
|
```
|
|
314
438
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
```
|
|
318
|
-
decorate_3_type = "*CreateNestedOneWithoutUserInput"
|
|
319
|
-
decorate_3_field = "!(create)"
|
|
320
|
-
decorate_3_name = "HideField"
|
|
321
|
-
decorate_3_from = "@nestjs/graphql"
|
|
322
|
-
decorate_3_arguments = "[]"
|
|
323
|
-
```
|
|
439
|
+
Prefer `decorators` in `nestgraphql.config.*` for new configuration.
|
|
324
440
|
|
|
325
|
-
|
|
441
|
+
#### `graphqlScalars`
|
|
326
442
|
|
|
327
|
-
|
|
328
|
-
@Field(() => ProfileCreateWithoutUserInput, { nullable: true })
|
|
329
|
-
create?: ProfileCreateWithoutUserInput;
|
|
443
|
+
Allow to set custom graphql type for Prisma scalar type.
|
|
330
444
|
|
|
331
|
-
|
|
332
|
-
connectOrCreate?: ProfileCreateOrConnectWithoutUserInput;
|
|
445
|
+
**New (config file)**:
|
|
333
446
|
|
|
334
|
-
|
|
335
|
-
|
|
447
|
+
```js
|
|
448
|
+
graphqlScalars: {
|
|
449
|
+
BigInt: { name: 'GraphQLBigInt', specifier: 'graphql-scalars' },
|
|
450
|
+
}
|
|
336
451
|
```
|
|
337
452
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
Allow to set custom graphql type for Prisma scalar type.
|
|
341
|
-
Format:
|
|
453
|
+
**Legacy (schema.prisma, flatten-style)**:
|
|
342
454
|
|
|
343
455
|
```
|
|
344
456
|
graphqlScalars_{type}_name = "string"
|
|
@@ -367,17 +479,28 @@ export class BigIntFilter {
|
|
|
367
479
|
|
|
368
480
|
It will affect all inputs and outputs types (including models).
|
|
369
481
|
|
|
370
|
-
#### `
|
|
482
|
+
#### `customImports`
|
|
371
483
|
|
|
372
484
|
Allow to declare custom import statements. (Only works with emitSingle = true)
|
|
373
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
|
+
|
|
374
497
|
```sh
|
|
375
498
|
generator nestgraphql {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
|
381
504
|
}
|
|
382
505
|
```
|
|
383
506
|
|
|
@@ -430,13 +553,25 @@ Special directives in triple slash comments for more precise code generation.
|
|
|
430
553
|
#### @HideField()
|
|
431
554
|
|
|
432
555
|
Removes field from GraphQL schema.
|
|
433
|
-
Alias: `@TypeGraphQL.omit(output: true)`
|
|
434
|
-
|
|
435
556
|
By default (without arguments) field will be decorated for hide only in output types (type in schema).
|
|
436
557
|
To hide field in input types add `input: true`.
|
|
437
558
|
To hide field in specific type you can use glob pattern `match: string | string[]`
|
|
438
559
|
see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
439
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
|
+
|
|
440
575
|
Examples:
|
|
441
576
|
|
|
442
577
|
- `@HideField()` same as `@HideField({ output: true })`
|
|
@@ -445,13 +580,13 @@ Examples:
|
|
|
445
580
|
|
|
446
581
|
```prisma
|
|
447
582
|
model User {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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())
|
|
455
590
|
}
|
|
456
591
|
```
|
|
457
592
|
|
|
@@ -485,15 +620,16 @@ export class UserCreateInput {
|
|
|
485
620
|
|
|
486
621
|
Applying custom decorators requires configuration of generator.
|
|
487
622
|
|
|
488
|
-
```
|
|
623
|
+
```prisma
|
|
624
|
+
// Legacy configuration, prefer config file
|
|
489
625
|
generator nestgraphql {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
|
497
633
|
}
|
|
498
634
|
```
|
|
499
635
|
|
|
@@ -548,14 +684,14 @@ Custom decorators example:
|
|
|
548
684
|
|
|
549
685
|
```prisma
|
|
550
686
|
generator nestgraphql {
|
|
551
|
-
|
|
552
|
-
|
|
687
|
+
fields_Validator_from = "class-validator"
|
|
688
|
+
fields_Validator_input = true
|
|
553
689
|
}
|
|
554
690
|
|
|
555
691
|
model User {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
692
|
+
id Int @id
|
|
693
|
+
/// @Validator.MinLength(3)
|
|
694
|
+
name String
|
|
559
695
|
}
|
|
560
696
|
```
|
|
561
697
|
|
|
@@ -579,14 +715,14 @@ Custom decorators can be applied on classes (models):
|
|
|
579
715
|
/// @NG.Directive('@extends')
|
|
580
716
|
/// @NG.Directive('@key(fields: "id")')
|
|
581
717
|
model User {
|
|
582
|
-
|
|
583
|
-
|
|
718
|
+
/// @NG.Directive('@external')
|
|
719
|
+
id String @id
|
|
584
720
|
}
|
|
585
721
|
|
|
586
722
|
generator nestgraphql {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
723
|
+
fields_NG_from = "@nestjs/graphql"
|
|
724
|
+
fields_NG_output = false
|
|
725
|
+
fields_NG_model = true
|
|
590
726
|
}
|
|
591
727
|
```
|
|
592
728
|
|
|
@@ -598,9 +734,9 @@ import * as NG from '@nestjs/graphql';
|
|
|
598
734
|
@NG.Directive('@extends')
|
|
599
735
|
@NG.Directive('@key(fields: "id")')
|
|
600
736
|
export class User {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
737
|
+
@Field(() => ID, { nullable: false })
|
|
738
|
+
@NG.Directive('@external')
|
|
739
|
+
id!: string;
|
|
604
740
|
```
|
|
605
741
|
|
|
606
742
|
#### @FieldType()
|
|
@@ -612,9 +748,9 @@ see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
|
612
748
|
|
|
613
749
|
```prisma
|
|
614
750
|
model User {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
751
|
+
id Int @id
|
|
752
|
+
/// @FieldType({ name: 'Scalars.GraphQLEmailAddress', from: 'graphql-scalars', input: true })
|
|
753
|
+
email String
|
|
618
754
|
}
|
|
619
755
|
```
|
|
620
756
|
|
|
@@ -637,7 +773,7 @@ And following GraphQL schema:
|
|
|
637
773
|
scalar EmailAddress
|
|
638
774
|
|
|
639
775
|
input UserCreateInput {
|
|
640
|
-
|
|
776
|
+
email: EmailAddress!
|
|
641
777
|
}
|
|
642
778
|
```
|
|
643
779
|
|
|
@@ -646,15 +782,15 @@ There is a shortcut:
|
|
|
646
782
|
|
|
647
783
|
```grapqhl
|
|
648
784
|
generator nestgraphql {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
785
|
+
fields_Scalars_from = "graphql-scalars"
|
|
786
|
+
fields_Scalars_input = true
|
|
787
|
+
fields_Scalars_output = true
|
|
652
788
|
}
|
|
653
789
|
|
|
654
790
|
model User {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
791
|
+
id Int @id
|
|
792
|
+
/// @FieldType('Scalars.GraphQLEmailAddress')
|
|
793
|
+
email String
|
|
658
794
|
}
|
|
659
795
|
```
|
|
660
796
|
|
|
@@ -672,13 +808,13 @@ Example:
|
|
|
672
808
|
|
|
673
809
|
```
|
|
674
810
|
generator nestgraphql {
|
|
675
|
-
|
|
811
|
+
fields_TF_from = "type-fest"
|
|
676
812
|
}
|
|
677
813
|
|
|
678
814
|
model User {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
815
|
+
id String @id
|
|
816
|
+
/// @PropertyType('TF.JsonObject')
|
|
817
|
+
data Json
|
|
682
818
|
}
|
|
683
819
|
```
|
|
684
820
|
|
|
@@ -704,8 +840,8 @@ GraphQL federation example:
|
|
|
704
840
|
/// @Directive({ arguments: ['@extends'] })
|
|
705
841
|
/// @Directive({ arguments: ['@key(fields: "id")'] })
|
|
706
842
|
model User {
|
|
707
|
-
|
|
708
|
-
|
|
843
|
+
/// @Directive({ arguments: ['@external'] })
|
|
844
|
+
id String @id
|
|
709
845
|
}
|
|
710
846
|
```
|
|
711
847
|
|
|
@@ -732,7 +868,7 @@ Example 1:
|
|
|
732
868
|
// schema.prisma
|
|
733
869
|
/// @ObjectType({ isAbstract: true })
|
|
734
870
|
model User {
|
|
735
|
-
|
|
871
|
+
id Int @id
|
|
736
872
|
}
|
|
737
873
|
```
|
|
738
874
|
|
|
@@ -747,7 +883,7 @@ Example 2:
|
|
|
747
883
|
// schema.prisma
|
|
748
884
|
/// @ObjectType('Human', { isAbstract: true })
|
|
749
885
|
model User {
|
|
750
|
-
|
|
886
|
+
id Int @id
|
|
751
887
|
}
|
|
752
888
|
```
|
|
753
889
|
|
|
@@ -788,12 +924,12 @@ import { generate } from 'prisma-nestjs-graphql';
|
|
|
788
924
|
|
|
789
925
|
## TODO
|
|
790
926
|
|
|
791
|
-
- noAtomicOperations = 1, IntFieldUpdateOperationsInput exists
|
|
792
927
|
- CommentUncheckedUpdateManyWithoutAuthorNestedInput and CommentUpdateManyWithoutAuthorNestedInput are same
|
|
793
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
|
|
794
929
|
- dummy-createfriends.input.ts -> `create-friends`
|
|
795
930
|
- check 'TODO FIXME'
|
|
931
|
+
- rework test, use setup file
|
|
796
932
|
|
|
797
933
|
## License
|
|
798
934
|
|
|
799
|
-
[MIT License](https://opensource.org/licenses/MIT) (c)
|
|
935
|
+
[MIT License](https://opensource.org/licenses/MIT) (c) 2026
|