prisma-nestjs-graphql 15.2.6 → 15.3.2
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/LICENSE +1 -1
- package/README.md +116 -83
- package/index.js +151 -68
- package/package.json +15 -15
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Generate object types, inputs, args, etc. from prisma schema file for usage with
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- Generates only necessary imports
|
|
8
|
+
- Combines zoo of nested/nullable filters
|
|
9
|
+
- Does not generate resolvers, since it's application specific
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -40,8 +40,8 @@ npm install graphql-type-json prisma-graphql-type-decimal
|
|
|
40
40
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
-
|
|
44
|
-
-
|
|
43
|
+
- [graphql-type-json](https://github.com/taion/graphql-type-json)
|
|
44
|
+
- [prisma-graphql-type-decimal](https://github.com/unlight/prisma-graphql-type-decimal)
|
|
45
45
|
|
|
46
46
|
Or write you own graphql scalar types, [read more on docs.nestjs.com](https://docs.nestjs.com/graphql/scalars).
|
|
47
47
|
|
|
@@ -59,10 +59,10 @@ Type: `string`
|
|
|
59
59
|
Default: `{model}/{name}.{type}.ts`
|
|
60
60
|
Possible tokens:
|
|
61
61
|
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
62
|
+
- `{model}` Model name in dashed case or 'prisma' if unknown
|
|
63
|
+
- `{name}` Dashed-case name of model/input/arg without suffix
|
|
64
|
+
- `{type}` Short type name (model, input, args, output)
|
|
65
|
+
- `{plural.type}` Plural short type name (models, inputs, enums)
|
|
66
66
|
|
|
67
67
|
#### `tsConfigFilePath`
|
|
68
68
|
|
|
@@ -149,30 +149,30 @@ generator nestgraphql {
|
|
|
149
149
|
|
|
150
150
|
Where:
|
|
151
151
|
|
|
152
|
-
-
|
|
153
|
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
- `typeName` Full name or partial name of the class where need to choose input type.
|
|
153
|
+
Example: `UserCreateInput` full name, `WhereInput` partial name, matches `UserWhereInput`, `PostWhereInput`, etc.
|
|
154
|
+
- `property` Property of the class for which need to choose type. Special case name `ALL` means any / all properties.
|
|
155
|
+
- `pattern` Part of name (or full) of type which should be chosen, you can use
|
|
156
|
+
wild card or negate symbols, in this case pattern should starts with `match:`,
|
|
157
|
+
e.g. `match:*UncheckedCreateInput` see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
158
158
|
|
|
159
159
|
Example:
|
|
160
160
|
|
|
161
161
|
```ts
|
|
162
162
|
export type PostWhereInput = {
|
|
163
|
-
|
|
163
|
+
author?: XOR<UserRelationFilter, UserWhereInput>;
|
|
164
164
|
};
|
|
165
165
|
export type UserRelationFilter = {
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
is?: UserWhereInput;
|
|
167
|
+
isNot?: UserWhereInput;
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
export type UserWhereInput = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
AND?: Enumerable<UserWhereInput>;
|
|
172
|
+
OR?: Enumerable<UserWhereInput>;
|
|
173
|
+
NOT?: Enumerable<UserWhereInput>;
|
|
174
|
+
id?: StringFilter | string;
|
|
175
|
+
name?: StringFilter | string;
|
|
176
176
|
};
|
|
177
177
|
```
|
|
178
178
|
|
|
@@ -190,8 +190,8 @@ generator nestgraphql {
|
|
|
190
190
|
```ts
|
|
191
191
|
@InputType()
|
|
192
192
|
export class PostWhereInput {
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
@Field(() => UserWhereInput, { nullable: true })
|
|
194
|
+
author?: UserWhereInput;
|
|
195
195
|
}
|
|
196
196
|
```
|
|
197
197
|
|
|
@@ -214,24 +214,24 @@ generator nestgraphql {
|
|
|
214
214
|
|
|
215
215
|
Where `{key}` any identifier to group values (written in [flatten](https://github.com/hughsk/flat) style)
|
|
216
216
|
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
223
|
-
-
|
|
224
|
-
-
|
|
225
|
-
|
|
226
|
-
|
|
217
|
+
- `decorate_{key}_type` - outmatch pattern to match class name
|
|
218
|
+
- `decorate_{key}_field` - outmatch pattern to match field name
|
|
219
|
+
- `decorate_{key}_from` - module specifier to import from (e.g `class-validator`)
|
|
220
|
+
- `decorate_{key}_name` - import name or name with namespace
|
|
221
|
+
- `decorate_{key}_defaultImport` - import as default
|
|
222
|
+
- `decorate_{key}_namespaceImport` - use this name as import namespace
|
|
223
|
+
- `decorate_{key}_namedImport` - named import (without namespace)
|
|
224
|
+
- `decorate_{key}_arguments` - arguments for decorator (if decorator need to be called as function)
|
|
225
|
+
Special tokens can be used:
|
|
226
|
+
- `{propertyType.0}` - field's type (TypeScript type annotation)
|
|
227
227
|
|
|
228
228
|
Example of generated class:
|
|
229
229
|
|
|
230
230
|
```ts
|
|
231
231
|
@ArgsType()
|
|
232
232
|
export class CreateOneUserArgs {
|
|
233
|
-
|
|
234
|
-
|
|
233
|
+
@Field(() => UserCreateInput, { nullable: false })
|
|
234
|
+
data!: UserCreateInput;
|
|
235
235
|
}
|
|
236
236
|
```
|
|
237
237
|
|
|
@@ -259,10 +259,10 @@ import { Type } from 'class-transformer';
|
|
|
259
259
|
|
|
260
260
|
@ArgsType()
|
|
261
261
|
export class CreateOneUserArgs {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
@Field(() => UserCreateInput, { nullable: false })
|
|
263
|
+
@ValidateNested()
|
|
264
|
+
@Type(() => UserCreateInput)
|
|
265
|
+
data!: UserCreateInput;
|
|
266
266
|
}
|
|
267
267
|
```
|
|
268
268
|
|
|
@@ -329,13 +329,45 @@ May generate:
|
|
|
329
329
|
import { GraphQLBigInt } from 'graphql-scalars';
|
|
330
330
|
|
|
331
331
|
export class BigIntFilter {
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
@Field(() => GraphQLBigInt, { nullable: true })
|
|
333
|
+
equals?: bigint | number;
|
|
334
334
|
}
|
|
335
335
|
```
|
|
336
336
|
|
|
337
337
|
It will affect all inputs and outputs types (including models).
|
|
338
338
|
|
|
339
|
+
## Documentation and field options
|
|
340
|
+
|
|
341
|
+
Comments with triple slash will projected to typescript code comments
|
|
342
|
+
and some `@Field()` decorator options
|
|
343
|
+
|
|
344
|
+
For example:
|
|
345
|
+
|
|
346
|
+
```prisma
|
|
347
|
+
model Product {
|
|
348
|
+
/// Old description
|
|
349
|
+
/// @deprecated Use new name instead
|
|
350
|
+
oldName String
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
May produce:
|
|
355
|
+
|
|
356
|
+
```ts
|
|
357
|
+
@ObjectType()
|
|
358
|
+
export class Product {
|
|
359
|
+
/**
|
|
360
|
+
* Old description
|
|
361
|
+
* @deprecated Use new name instead
|
|
362
|
+
*/
|
|
363
|
+
@Field(() => String, {
|
|
364
|
+
description: 'Old description',
|
|
365
|
+
deprecationReason: 'Use new name instead',
|
|
366
|
+
})
|
|
367
|
+
oldName: string;
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
339
371
|
## Field Settings
|
|
340
372
|
|
|
341
373
|
Special directives in triple slash comments for more precise code generation.
|
|
@@ -352,9 +384,9 @@ see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
|
|
|
352
384
|
|
|
353
385
|
Examples:
|
|
354
386
|
|
|
355
|
-
-
|
|
356
|
-
-
|
|
357
|
-
-
|
|
387
|
+
- `@HideField()` same as `@HideField({ output: true })`
|
|
388
|
+
- `@HideField({ input: true, output: true })`
|
|
389
|
+
- `@HideField({ match: 'UserCreate*Input' })`
|
|
358
390
|
|
|
359
391
|
```prisma
|
|
360
392
|
model User {
|
|
@@ -373,24 +405,24 @@ May generate classes:
|
|
|
373
405
|
```ts
|
|
374
406
|
@ObjectType()
|
|
375
407
|
export class User {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
408
|
+
@HideField()
|
|
409
|
+
password: string;
|
|
410
|
+
@HideField()
|
|
411
|
+
secret: string;
|
|
412
|
+
@Field(() => Date, { nullable: false })
|
|
413
|
+
createdAt: Date;
|
|
382
414
|
}
|
|
383
415
|
```
|
|
384
416
|
|
|
385
417
|
```ts
|
|
386
418
|
@InputType()
|
|
387
419
|
export class UserCreateInput {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
420
|
+
@Field()
|
|
421
|
+
password: string;
|
|
422
|
+
@HideField()
|
|
423
|
+
secret: string;
|
|
424
|
+
@HideField()
|
|
425
|
+
createdAt: Date;
|
|
394
426
|
}
|
|
395
427
|
```
|
|
396
428
|
|
|
@@ -480,9 +512,9 @@ import * as Validator from 'class-validator';
|
|
|
480
512
|
|
|
481
513
|
@InputType()
|
|
482
514
|
export class UserCreateInput {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
515
|
+
@Field(() => String, { nullable: false })
|
|
516
|
+
@Validator.MinLength(3)
|
|
517
|
+
name!: string;
|
|
486
518
|
}
|
|
487
519
|
```
|
|
488
520
|
|
|
@@ -539,8 +571,8 @@ import * as Scalars from 'graphql-scalars';
|
|
|
539
571
|
|
|
540
572
|
@InputType()
|
|
541
573
|
export class UserCreateInput {
|
|
542
|
-
|
|
543
|
-
|
|
574
|
+
@Field(() => Scalars.GraphQLEmailAddress, { nullable: false })
|
|
575
|
+
email!: string;
|
|
544
576
|
}
|
|
545
577
|
```
|
|
546
578
|
|
|
@@ -602,8 +634,8 @@ import * as TF from 'type-fest';
|
|
|
602
634
|
|
|
603
635
|
@ObjectType()
|
|
604
636
|
export class User {
|
|
605
|
-
|
|
606
|
-
|
|
637
|
+
@Field(() => GraphQLJSON)
|
|
638
|
+
data!: TF.JsonObject;
|
|
607
639
|
}
|
|
608
640
|
```
|
|
609
641
|
|
|
@@ -629,9 +661,9 @@ May generate:
|
|
|
629
661
|
@Directive('@extends')
|
|
630
662
|
@Directive('@key(fields: "id")')
|
|
631
663
|
export class User {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
664
|
+
@Field(() => ID, { nullable: false })
|
|
665
|
+
@Directive('@external')
|
|
666
|
+
id!: string;
|
|
635
667
|
}
|
|
636
668
|
```
|
|
637
669
|
|
|
@@ -671,21 +703,22 @@ export class User {}
|
|
|
671
703
|
|
|
672
704
|
## Similar Projects
|
|
673
705
|
|
|
674
|
-
-
|
|
675
|
-
-
|
|
676
|
-
-
|
|
677
|
-
-
|
|
678
|
-
-
|
|
679
|
-
-
|
|
680
|
-
-
|
|
706
|
+
- https://github.com/omar-dulaimi/prisma-class-validator-generator
|
|
707
|
+
- https://github.com/kimjbstar/prisma-class-generator
|
|
708
|
+
- https://github.com/odroe/nest-gql-mix
|
|
709
|
+
- https://github.com/rfermann/nestjs-prisma-graphql-generator
|
|
710
|
+
- https://github.com/madscience/graphql-codegen-nestjs
|
|
711
|
+
- https://github.com/wSedlacek/prisma-generators/tree/master/libs/nestjs
|
|
712
|
+
- https://github.com/EndyKaufman/typegraphql-prisma-nestjs
|
|
713
|
+
- https://github.com/MichalLytek/typegraphql-prisma
|
|
681
714
|
|
|
682
715
|
## Resources
|
|
683
716
|
|
|
684
|
-
-
|
|
685
|
-
-
|
|
686
|
-
-
|
|
687
|
-
-
|
|
688
|
-
-
|
|
689
|
-
-
|
|
690
|
-
-
|
|
691
|
-
-
|
|
717
|
+
- Todo - https://github.com/unlight/prisma-nestjs-graphql/issues/2
|
|
718
|
+
- https://github.com/prisma/prisma/blob/main/packages/client/src/generation/TSClient/TSClient.ts
|
|
719
|
+
- https://ts-ast-viewer.com/
|
|
720
|
+
- https://github.com/unlight/nestjs-graphql-prisma-realworld-example-app
|
|
721
|
+
- https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/data-model
|
|
722
|
+
- JSON type for the code first approach - https://github.com/nestjs/graphql/issues/111#issuecomment-631452899
|
|
723
|
+
- https://github.com/paljs/prisma-tools/tree/master/packages/plugins
|
|
724
|
+
- https://github.com/wasp-lang/wasp
|
package/index.js
CHANGED
|
@@ -749,6 +749,7 @@ function inputType(args) {
|
|
|
749
749
|
arguments: [
|
|
750
750
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
751
751
|
import_json5.default.stringify({
|
|
752
|
+
...settings == null ? void 0 : settings.fieldArguments(),
|
|
752
753
|
nullable: !isRequired
|
|
753
754
|
})
|
|
754
755
|
]
|
|
@@ -849,81 +850,126 @@ var ObjectSettings = class extends Array {
|
|
|
849
850
|
}
|
|
850
851
|
return resultArguments.map((x) => import_json52.default.stringify(x));
|
|
851
852
|
}
|
|
853
|
+
fieldArguments() {
|
|
854
|
+
const item1 = this.find((item) => item.kind === "Field");
|
|
855
|
+
if (item1) {
|
|
856
|
+
return item1.arguments;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
852
859
|
};
|
|
853
860
|
__name(ObjectSettings, "ObjectSettings");
|
|
854
861
|
function createObjectSettings(args) {
|
|
855
|
-
var _a, _b, _c, _d, _e;
|
|
856
862
|
const { config, text } = args;
|
|
857
863
|
const result = new ObjectSettings();
|
|
858
864
|
const textLines = text.split("\n");
|
|
859
865
|
const documentationLines = [];
|
|
866
|
+
let fieldElement = result.find((item) => item.kind === "Field");
|
|
867
|
+
if (!fieldElement) {
|
|
868
|
+
fieldElement = {
|
|
869
|
+
name: "",
|
|
870
|
+
kind: "Field",
|
|
871
|
+
arguments: {}
|
|
872
|
+
};
|
|
873
|
+
}
|
|
860
874
|
for (const line of textLines) {
|
|
861
875
|
const match = /^@(?<name>\w+(\.(\w+))?)\((?<args>.*)\)/.exec(line);
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
876
|
+
const { element, documentLine } = createSettingElement({
|
|
877
|
+
line,
|
|
878
|
+
config,
|
|
879
|
+
fieldElement,
|
|
880
|
+
match
|
|
881
|
+
});
|
|
882
|
+
if (element) {
|
|
883
|
+
result.push(element);
|
|
866
884
|
}
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
name: "",
|
|
870
|
-
arguments: [],
|
|
871
|
-
input: false,
|
|
872
|
-
output: false,
|
|
873
|
-
model: false,
|
|
874
|
-
from: ""
|
|
875
|
-
};
|
|
876
|
-
if (name === "TypeGraphQL.omit" || name === "HideField") {
|
|
877
|
-
Object.assign(element, hideFieldDecorator(match));
|
|
878
|
-
} else if ([
|
|
879
|
-
"FieldType",
|
|
880
|
-
"PropertyType"
|
|
881
|
-
].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
|
|
882
|
-
const options = customType(match.groups.args);
|
|
883
|
-
(0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, {
|
|
884
|
-
kind: name
|
|
885
|
-
});
|
|
886
|
-
} else if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
|
|
887
|
-
element.kind = "ObjectType";
|
|
888
|
-
const options = customType(match.groups.args);
|
|
889
|
-
if (typeof options[0] === "string" && options[0]) {
|
|
890
|
-
options.name = options[0];
|
|
891
|
-
}
|
|
892
|
-
if ((0, import_lodash4.isObject)(options[1])) {
|
|
893
|
-
(0, import_lodash4.merge)(options, options[1]);
|
|
894
|
-
}
|
|
895
|
-
element.arguments = {
|
|
896
|
-
name: options.name,
|
|
897
|
-
isAbstract: options.isAbstract
|
|
898
|
-
};
|
|
899
|
-
} else if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
|
|
900
|
-
const options = customType(match.groups.args);
|
|
901
|
-
(0, import_lodash4.merge)(element, {
|
|
902
|
-
model: true,
|
|
903
|
-
from: "@nestjs/graphql"
|
|
904
|
-
}, options, {
|
|
905
|
-
name,
|
|
906
|
-
namespace: false,
|
|
907
|
-
kind: "Decorator",
|
|
908
|
-
arguments: Array.isArray(options.arguments) ? options.arguments.map((s) => import_json52.default.stringify(s)) : options.arguments
|
|
909
|
-
});
|
|
910
|
-
} else {
|
|
911
|
-
const namespace = getNamespace(name);
|
|
912
|
-
element.namespaceImport = namespace;
|
|
913
|
-
const options = {
|
|
914
|
-
name,
|
|
915
|
-
arguments: (((_e = match.groups) == null ? void 0 : _e.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
|
|
916
|
-
};
|
|
917
|
-
(0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
|
|
885
|
+
if (documentLine) {
|
|
886
|
+
documentationLines.push(line);
|
|
918
887
|
}
|
|
919
|
-
result.push(element);
|
|
920
888
|
}
|
|
921
889
|
return {
|
|
922
890
|
settings: result,
|
|
923
|
-
documentation: documentationLines.filter(Boolean).join("
|
|
891
|
+
documentation: documentationLines.filter(Boolean).join("\n") || void 0
|
|
924
892
|
};
|
|
925
893
|
}
|
|
926
894
|
__name(createObjectSettings, "createObjectSettings");
|
|
895
|
+
function createSettingElement({ line, config, fieldElement, match }) {
|
|
896
|
+
var _a, _b, _c, _d, _e;
|
|
897
|
+
const result = {
|
|
898
|
+
documentLine: "",
|
|
899
|
+
element: void 0
|
|
900
|
+
};
|
|
901
|
+
if (line.startsWith("@deprecated")) {
|
|
902
|
+
fieldElement.arguments["deprecationReason"] = (0, import_lodash4.trim)(line.slice(11));
|
|
903
|
+
result.element = fieldElement;
|
|
904
|
+
return result;
|
|
905
|
+
}
|
|
906
|
+
const name = (_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.name;
|
|
907
|
+
if (!(match && name)) {
|
|
908
|
+
result.documentLine = line;
|
|
909
|
+
return result;
|
|
910
|
+
}
|
|
911
|
+
const element = {
|
|
912
|
+
kind: "Decorator",
|
|
913
|
+
name: "",
|
|
914
|
+
arguments: [],
|
|
915
|
+
input: false,
|
|
916
|
+
output: false,
|
|
917
|
+
model: false,
|
|
918
|
+
from: ""
|
|
919
|
+
};
|
|
920
|
+
result.element = element;
|
|
921
|
+
if (name === "TypeGraphQL.omit" || name === "HideField") {
|
|
922
|
+
Object.assign(element, hideFieldDecorator(match));
|
|
923
|
+
return result;
|
|
924
|
+
}
|
|
925
|
+
if ([
|
|
926
|
+
"FieldType",
|
|
927
|
+
"PropertyType"
|
|
928
|
+
].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
|
|
929
|
+
const options2 = customType(match.groups.args);
|
|
930
|
+
(0, import_lodash4.merge)(element, options2.namespace && config.fields[options2.namespace], options2, {
|
|
931
|
+
kind: name
|
|
932
|
+
});
|
|
933
|
+
return result;
|
|
934
|
+
}
|
|
935
|
+
if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
|
|
936
|
+
element.kind = "ObjectType";
|
|
937
|
+
const options2 = customType(match.groups.args);
|
|
938
|
+
if (typeof options2[0] === "string" && options2[0]) {
|
|
939
|
+
options2.name = options2[0];
|
|
940
|
+
}
|
|
941
|
+
if ((0, import_lodash4.isObject)(options2[1])) {
|
|
942
|
+
(0, import_lodash4.merge)(options2, options2[1]);
|
|
943
|
+
}
|
|
944
|
+
element.arguments = {
|
|
945
|
+
name: options2.name,
|
|
946
|
+
isAbstract: options2.isAbstract
|
|
947
|
+
};
|
|
948
|
+
return result;
|
|
949
|
+
}
|
|
950
|
+
if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
|
|
951
|
+
const options2 = customType(match.groups.args);
|
|
952
|
+
(0, import_lodash4.merge)(element, {
|
|
953
|
+
model: true,
|
|
954
|
+
from: "@nestjs/graphql"
|
|
955
|
+
}, options2, {
|
|
956
|
+
name,
|
|
957
|
+
namespace: false,
|
|
958
|
+
kind: "Decorator",
|
|
959
|
+
arguments: Array.isArray(options2.arguments) ? options2.arguments.map((s) => import_json52.default.stringify(s)) : options2.arguments
|
|
960
|
+
});
|
|
961
|
+
return result;
|
|
962
|
+
}
|
|
963
|
+
const namespace = getNamespace(name);
|
|
964
|
+
element.namespaceImport = namespace;
|
|
965
|
+
const options = {
|
|
966
|
+
name,
|
|
967
|
+
arguments: (((_e = match.groups) == null ? void 0 : _e.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
|
|
968
|
+
};
|
|
969
|
+
(0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
|
|
970
|
+
return result;
|
|
971
|
+
}
|
|
972
|
+
__name(createSettingElement, "createSettingElement");
|
|
927
973
|
function customType(args) {
|
|
928
974
|
var _a;
|
|
929
975
|
const result = {};
|
|
@@ -1035,6 +1081,25 @@ var import_lodash5 = require("lodash");
|
|
|
1035
1081
|
var import_pupa2 = __toESM(require("pupa"));
|
|
1036
1082
|
var import_ts_morph5 = require("ts-morph");
|
|
1037
1083
|
|
|
1084
|
+
// src/helpers/create-comment.ts
|
|
1085
|
+
function createComment(documentation, settings) {
|
|
1086
|
+
var _a;
|
|
1087
|
+
const documentationLines = documentation.split("\n");
|
|
1088
|
+
const commentLines = [
|
|
1089
|
+
"/**"
|
|
1090
|
+
];
|
|
1091
|
+
for (const line of documentationLines) {
|
|
1092
|
+
commentLines.push(` * ${line}`);
|
|
1093
|
+
}
|
|
1094
|
+
const deprecationReason = (_a = settings == null ? void 0 : settings.fieldArguments()) == null ? void 0 : _a.deprecationReason;
|
|
1095
|
+
if (deprecationReason) {
|
|
1096
|
+
commentLines.push(` * @deprecated ${deprecationReason}`);
|
|
1097
|
+
}
|
|
1098
|
+
commentLines.push(" */\n");
|
|
1099
|
+
return commentLines.join("\n");
|
|
1100
|
+
}
|
|
1101
|
+
__name(createComment, "createComment");
|
|
1102
|
+
|
|
1038
1103
|
// src/helpers/get-output-type-name.ts
|
|
1039
1104
|
function getOutputTypeName(name) {
|
|
1040
1105
|
return name.replace(/(?:OutputType|Output)$/, "");
|
|
@@ -1080,8 +1145,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1080
1145
|
});
|
|
1081
1146
|
if (documentation) {
|
|
1082
1147
|
if (!classStructure.leadingTrivia) {
|
|
1083
|
-
classStructure.leadingTrivia =
|
|
1084
|
-
`;
|
|
1148
|
+
classStructure.leadingTrivia = createComment(documentation);
|
|
1085
1149
|
}
|
|
1086
1150
|
objectTypeOptions.description = documentation;
|
|
1087
1151
|
}
|
|
@@ -1147,15 +1211,14 @@ function modelOutputType(outputType2, args) {
|
|
|
1147
1211
|
isList
|
|
1148
1212
|
});
|
|
1149
1213
|
if (typeof property.leadingTrivia === "string" && (modelField == null ? void 0 : modelField.documentation)) {
|
|
1150
|
-
property.leadingTrivia +=
|
|
1151
|
-
`;
|
|
1214
|
+
property.leadingTrivia += createComment(modelField.documentation, settings);
|
|
1152
1215
|
}
|
|
1153
1216
|
(_c = classStructure.properties) == null ? void 0 : _c.push(property);
|
|
1154
1217
|
if (propertySettings) {
|
|
1155
1218
|
importDeclarations.create({
|
|
1156
1219
|
...propertySettings
|
|
1157
1220
|
});
|
|
1158
|
-
} else if (
|
|
1221
|
+
} else if (propertyType.includes("Decimal")) {
|
|
1159
1222
|
importDeclarations.add("Decimal", "@prisma/client/runtime");
|
|
1160
1223
|
}
|
|
1161
1224
|
(0, import_assert3.ok)(property.decorators, "property.decorators is undefined");
|
|
@@ -1174,6 +1237,7 @@ function modelOutputType(outputType2, args) {
|
|
|
1174
1237
|
arguments: [
|
|
1175
1238
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1176
1239
|
import_json53.default.stringify({
|
|
1240
|
+
...settings == null ? void 0 : settings.fieldArguments(),
|
|
1177
1241
|
nullable: Boolean(field.isNullable),
|
|
1178
1242
|
defaultValue: [
|
|
1179
1243
|
"number",
|
|
@@ -1257,6 +1321,12 @@ function getExportDeclaration(name, statements) {
|
|
|
1257
1321
|
}
|
|
1258
1322
|
__name(getExportDeclaration, "getExportDeclaration");
|
|
1259
1323
|
|
|
1324
|
+
// src/helpers/is-list-input.ts
|
|
1325
|
+
function isListInput(typeName, model) {
|
|
1326
|
+
return typeName.startsWith(`${model}Create`) || typeName.startsWith(`${model}Update`);
|
|
1327
|
+
}
|
|
1328
|
+
__name(isListInput, "isListInput");
|
|
1329
|
+
|
|
1260
1330
|
// src/handlers/no-atomic-operations.ts
|
|
1261
1331
|
function noAtomicOperations(eventEmitter) {
|
|
1262
1332
|
eventEmitter.on("BeforeInputType", beforeInputType2);
|
|
@@ -1264,10 +1334,12 @@ function noAtomicOperations(eventEmitter) {
|
|
|
1264
1334
|
}
|
|
1265
1335
|
__name(noAtomicOperations, "noAtomicOperations");
|
|
1266
1336
|
function beforeInputType2(args) {
|
|
1267
|
-
const { inputType: inputType1 } = args;
|
|
1337
|
+
const { inputType: inputType1, getModelName: getModelName2 } = args;
|
|
1268
1338
|
for (const field of inputType1.fields) {
|
|
1269
1339
|
field.inputTypes = field.inputTypes.filter((inputType2) => {
|
|
1270
|
-
|
|
1340
|
+
const inputTypeName = String(inputType2.type);
|
|
1341
|
+
const modelName = getModelName2(inputTypeName);
|
|
1342
|
+
if (isAtomicOperation(inputTypeName) || modelName && isListInput(inputTypeName, modelName)) {
|
|
1271
1343
|
return false;
|
|
1272
1344
|
}
|
|
1273
1345
|
return true;
|
|
@@ -1286,8 +1358,11 @@ function beforeGenerateFiles(args) {
|
|
|
1286
1358
|
}
|
|
1287
1359
|
}
|
|
1288
1360
|
__name(beforeGenerateFiles, "beforeGenerateFiles");
|
|
1289
|
-
function isAtomicOperation(
|
|
1290
|
-
|
|
1361
|
+
function isAtomicOperation(typeName) {
|
|
1362
|
+
if (typeName.endsWith("FieldUpdateOperationsInput")) {
|
|
1363
|
+
return true;
|
|
1364
|
+
}
|
|
1365
|
+
return false;
|
|
1291
1366
|
}
|
|
1292
1367
|
__name(isAtomicOperation, "isAtomicOperation");
|
|
1293
1368
|
|
|
@@ -1413,6 +1488,7 @@ function outputType(outputType1, args) {
|
|
|
1413
1488
|
arguments: [
|
|
1414
1489
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1415
1490
|
import_json54.default.stringify({
|
|
1491
|
+
...settings == null ? void 0 : settings.fieldArguments(),
|
|
1416
1492
|
nullable: Boolean(field.isNullable)
|
|
1417
1493
|
})
|
|
1418
1494
|
]
|
|
@@ -1855,6 +1931,13 @@ function getModelName(args) {
|
|
|
1855
1931
|
return test;
|
|
1856
1932
|
}
|
|
1857
1933
|
}
|
|
1934
|
+
if (name.slice(-5) === "Input") {
|
|
1935
|
+
for (const model of modelNames) {
|
|
1936
|
+
if (isListInput(name, model)) {
|
|
1937
|
+
return model;
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1858
1941
|
return void 0;
|
|
1859
1942
|
}
|
|
1860
1943
|
__name(getModelName, "getModelName");
|
|
@@ -2043,7 +2126,7 @@ async function generate(args) {
|
|
|
2043
2126
|
for (const model of datamodel.models) {
|
|
2044
2127
|
await eventEmitter.emit("Model", model, eventArguments);
|
|
2045
2128
|
}
|
|
2046
|
-
for (const model1 of datamodel.types) {
|
|
2129
|
+
for (const model1 of datamodel.types || []) {
|
|
2047
2130
|
await eventEmitter.emit("Model", model1, eventArguments);
|
|
2048
2131
|
}
|
|
2049
2132
|
await eventEmitter.emit("PostBegin", eventArguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-nestjs-graphql",
|
|
3
|
-
"version": "15.2
|
|
3
|
+
"version": "15.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -51,8 +51,7 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@
|
|
55
|
-
"@prisma/generator-helper": "^3.13.0",
|
|
54
|
+
"@prisma/generator-helper": "^3.14.0",
|
|
56
55
|
"await-event-emitter": "^2.0.2",
|
|
57
56
|
"filenamify": "4.X",
|
|
58
57
|
"flat": "^5.0.2",
|
|
@@ -65,34 +64,35 @@
|
|
|
65
64
|
"ts-morph": ">=11"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
|
67
|
+
"@nestjs/apollo": "^10.0.11",
|
|
68
68
|
"@commitlint/cli": "^16.2.4",
|
|
69
69
|
"@commitlint/config-conventional": "^16.2.4",
|
|
70
70
|
"@nestjs/common": "^8.4.4",
|
|
71
71
|
"@nestjs/core": "^8.4.4",
|
|
72
|
-
"@nestjs/graphql": "^10.0.
|
|
72
|
+
"@nestjs/graphql": "^10.0.11",
|
|
73
73
|
"@nestjs/platform-express": "^8.4.4",
|
|
74
|
-
"@paljs/plugins": "^4.0
|
|
75
|
-
"@prisma/client": "^3.
|
|
74
|
+
"@paljs/plugins": "^4.1.0",
|
|
75
|
+
"@prisma/client": "^3.14.0",
|
|
76
76
|
"@semantic-release/changelog": "^6.0.1",
|
|
77
77
|
"@semantic-release/git": "^10.0.1",
|
|
78
|
-
"@swc/core": "^1.2.
|
|
79
|
-
"@swc/helpers": "^0.3.
|
|
78
|
+
"@swc/core": "^1.2.181",
|
|
79
|
+
"@swc/helpers": "^0.3.13",
|
|
80
80
|
"@swc/register": "^0.1.10",
|
|
81
81
|
"@types/flat": "^5.0.2",
|
|
82
82
|
"@types/lodash": "^4.14.182",
|
|
83
83
|
"@types/mocha": "^9.1.1",
|
|
84
84
|
"@types/node": "^17.0.31",
|
|
85
85
|
"@types/pluralize": "^0.0.29",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
87
|
-
"@typescript-eslint/parser": "^5.
|
|
88
|
-
"apollo-server-express": "^3.
|
|
86
|
+
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
|
87
|
+
"@typescript-eslint/parser": "^5.23.0",
|
|
88
|
+
"apollo-server-express": "^3.7.0",
|
|
89
89
|
"c8": "^7.11.2",
|
|
90
90
|
"class-transformer": "^0.5.1",
|
|
91
91
|
"class-validator": "^0.13.2",
|
|
92
92
|
"commitizen": "^4.2.4",
|
|
93
93
|
"cz-customizable": "^6.3.0",
|
|
94
94
|
"decimal.js": "^10.3.1",
|
|
95
|
-
"eslint": "^8.
|
|
95
|
+
"eslint": "^8.15.0",
|
|
96
96
|
"eslint-import-resolver-node": "^0.3.6",
|
|
97
97
|
"eslint-plugin-etc": "^2.0.2",
|
|
98
98
|
"eslint-plugin-import": "^2.26.0",
|
|
@@ -103,17 +103,17 @@
|
|
|
103
103
|
"eslint-plugin-sort-class-members": "^1.14.1",
|
|
104
104
|
"eslint-plugin-unicorn": "^42.0.0",
|
|
105
105
|
"eslint-plugin-wix-editor": "^3.3.0",
|
|
106
|
-
"expect": "^28.0
|
|
106
|
+
"expect": "^28.1.0",
|
|
107
107
|
"ghooks": "^2.0.4",
|
|
108
108
|
"git-branch-is": "^4.0.0",
|
|
109
|
-
"graphql": "^16.
|
|
109
|
+
"graphql": "^16.5.0",
|
|
110
110
|
"graphql-scalars": "^1.17.0",
|
|
111
111
|
"graphql-type-json": "^0.3.2",
|
|
112
112
|
"mocha": "^10.0.0",
|
|
113
113
|
"ololog": "^1.1.175",
|
|
114
114
|
"precise-commits": "^1.0.2",
|
|
115
115
|
"prettier": "^2.6.2",
|
|
116
|
-
"prisma": "^3.
|
|
116
|
+
"prisma": "^3.14.0",
|
|
117
117
|
"prisma-graphql-type-decimal": "^2.0.0",
|
|
118
118
|
"reflect-metadata": "^0.1.13",
|
|
119
119
|
"request": "^2.88.2",
|