prisma-nestjs-graphql 14.4.1 → 14.6.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.
Files changed (3) hide show
  1. package/README.md +71 -3
  2. package/index.js +135 -107
  3. package/package.json +40 -43
package/README.md CHANGED
@@ -128,10 +128,11 @@ Default: `false`
128
128
 
129
129
  #### `requireSingleFieldsInWhereUniqueInput`
130
130
 
131
- When a `Model`s `WhereUniqueInput` class has only a single field, mark that field as **required** (TypeScript) and **not nullable** (GraphQL).
131
+ When a model `*WhereUniqueInput` class has only a single field, mark that field as **required** (TypeScript) and **not nullable** (GraphQL).
132
132
  See [#58](https://github.com/unlight/prisma-nestjs-graphql/issues/58) for more details.
133
133
  Type: `boolean`
134
- Default: `false`
134
+ Default: `false`
135
+ **Note**: It will break compatiblity between Prisma types and generated classes.
135
136
 
136
137
  #### `useInputType`
137
138
 
@@ -345,6 +346,7 @@ generator nestgraphql {
345
346
  fields_{namespace}_from = "module specifier"
346
347
  fields_{namespace}_input = true | false
347
348
  fields_{namespace}_output = true | false
349
+ fields_{namespace}_model = true | false
348
350
  fields_{namespace}_defaultImport = "default import name" | true
349
351
  fields_{namespace}_namespaceImport = "namespace import name"
350
352
  fields_{namespace}_namedImport = true | false
@@ -367,7 +369,14 @@ Default: `false`
367
369
 
368
370
  ##### `fields_{namespace}_output`
369
371
 
370
- Means that it will be applied on output types (classes decorated by `ObjectType`)
372
+ Means that it will be applied on output types (classes decorated by `ObjectType`),
373
+ including models
374
+ Type: `boolean`
375
+ Default: `false`
376
+
377
+ ##### `fields_{namespace}_model`
378
+
379
+ Means that it will be applied only on model types (classes decorated by `ObjectType`)
371
380
  Type: `boolean`
372
381
  Default: `false`
373
382
 
@@ -420,6 +429,36 @@ export class UserCreateInput {
420
429
  }
421
430
  ```
422
431
 
432
+ Custom decorators can be applied on classes (models):
433
+
434
+ ```
435
+ /// @NG.Directive('@extends')
436
+ /// @NG.Directive('@key(fields: "id")')
437
+ model User {
438
+ /// @NG.Directive('@external')
439
+ id String @id
440
+ }
441
+
442
+ generator nestgraphql {
443
+ fields_NG_from = "@nestjs/graphql"
444
+ fields_NG_output = false
445
+ fields_NG_model = true
446
+ }
447
+ ```
448
+
449
+ May generate:
450
+
451
+ ```ts
452
+ import * as NG from '@nestjs/graphql';
453
+
454
+ @NG.Directive('@extends')
455
+ @NG.Directive('@key(fields: "id")')
456
+ export class User {
457
+ @Field(() => ID, { nullable: false })
458
+ @NG.Directive('@external')
459
+ id!: string;
460
+ ```
461
+
423
462
  #### @FieldType()
424
463
 
425
464
  Allow set custom GraphQL scalar type for field
@@ -533,6 +572,34 @@ export class User {
533
572
  }
534
573
  ```
535
574
 
575
+ ### @Directive()
576
+
577
+ Allow attach `@Directive` decorator from `@nestjs/graphql`
578
+
579
+ GraphQL federation example:
580
+
581
+ ```
582
+ /// @Directive({ arguments: ['@extends'] })
583
+ /// @Directive({ arguments: ['@key(fields: "id")'] })
584
+ model User {
585
+ /// @Directive({ arguments: ['@external'] })
586
+ id String @id
587
+ }
588
+ ```
589
+
590
+ May generate:
591
+
592
+ ```ts
593
+ @ObjectType()
594
+ @Directive('@extends')
595
+ @Directive('@key(fields: "id")')
596
+ export class User {
597
+ @Field(() => ID, { nullable: false })
598
+ @Directive('@external')
599
+ id!: string;
600
+ }
601
+ ```
602
+
536
603
  #### @ObjectType()
537
604
 
538
605
  Allow rename type in schema and mark as abstract.
@@ -569,6 +636,7 @@ export class User {}
569
636
 
570
637
  ## Similar Projects
571
638
 
639
+ - https://github.com/kimjbstar/prisma-class-generator
572
640
  - https://github.com/odroe/nest-gql-mix
573
641
  - https://github.com/rfermann/nestjs-prisma-graphql-generator
574
642
  - https://github.com/madscience/graphql-codegen-nestjs
package/index.js CHANGED
@@ -22,32 +22,29 @@ var __spreadValues = (a, b) => {
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
24
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
- var __reExport = (target, module2, desc) => {
25
+ var __reExport = (target, module2, copyDefault, desc) => {
26
26
  if (module2 && typeof module2 === "object" || typeof module2 === "function") {
27
27
  for (let key of __getOwnPropNames(module2))
28
- if (!__hasOwnProp.call(target, key) && key !== "default")
28
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
29
29
  __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
30
30
  }
31
31
  return target;
32
32
  };
33
- var __toModule = (module2) => {
34
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
33
+ var __toESM = (module2, isNodeMode) => {
34
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
35
35
  };
36
36
 
37
- // ../../../../.npm/_npx/7d72304e626f8399/node_modules/tsup/assets/cjs_shims.js
38
- var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
39
-
40
37
  // src/index.ts
41
- var import_generator_helper = __toModule(require("@prisma/generator-helper"));
38
+ var import_generator_helper = require("@prisma/generator-helper");
42
39
 
43
40
  // src/generate.ts
44
- var import_assert6 = __toModule(require("assert"));
45
- var import_await_event_emitter = __toModule(require("await-event-emitter"));
46
- var import_lodash10 = __toModule(require("lodash"));
47
- var import_ts_morph9 = __toModule(require("ts-morph"));
41
+ var import_assert6 = require("assert");
42
+ var import_await_event_emitter = __toESM(require("await-event-emitter"));
43
+ var import_lodash10 = require("lodash");
44
+ var import_ts_morph9 = require("ts-morph");
48
45
 
49
46
  // src/helpers/pascal-case.ts
50
- var import_lodash = __toModule(require("lodash"));
47
+ var import_lodash = require("lodash");
51
48
  function pascalCase(string) {
52
49
  return (0, import_lodash.startCase)((0, import_lodash.camelCase)(string)).replace(/ /g, "");
53
50
  }
@@ -194,11 +191,11 @@ function classProperty(property, eventArguments) {
194
191
  }
195
192
 
196
193
  // src/handlers/generate-files.ts
197
- var import_assert = __toModule(require("assert"));
198
- var import_ts_morph2 = __toModule(require("ts-morph"));
194
+ var import_assert = require("assert");
195
+ var import_ts_morph2 = require("ts-morph");
199
196
 
200
197
  // src/helpers/import-declaration-map.ts
201
- var import_ts_morph = __toModule(require("ts-morph"));
198
+ var import_ts_morph = require("ts-morph");
202
199
  var ImportDeclarationMap = class extends Map {
203
200
  add(name, value) {
204
201
  if (!this.has(name)) {
@@ -341,11 +338,11 @@ async function generateFiles(args) {
341
338
  }
342
339
 
343
340
  // src/handlers/input-type.ts
344
- var import_assert2 = __toModule(require("assert"));
345
- var import_json5 = __toModule(require("json5"));
346
- var import_lodash3 = __toModule(require("lodash"));
347
- var import_pupa = __toModule(require("pupa"));
348
- var import_ts_morph4 = __toModule(require("ts-morph"));
341
+ var import_assert2 = require("assert");
342
+ var import_json5 = __toESM(require("json5"));
343
+ var import_lodash3 = require("lodash");
344
+ var import_pupa = __toESM(require("pupa"));
345
+ var import_ts_morph4 = require("ts-morph");
349
346
 
350
347
  // src/helpers/file-type-by-location.ts
351
348
  function fileTypeByLocation(fieldLocation) {
@@ -361,7 +358,7 @@ function fileTypeByLocation(fieldLocation) {
361
358
  }
362
359
 
363
360
  // src/helpers/relative-path.ts
364
- var import_get_relative_path = __toModule(require("get-relative-path"));
361
+ var import_get_relative_path = __toESM(require("get-relative-path"));
365
362
  function relativePath(from, to) {
366
363
  if (!from.startsWith("/")) {
367
364
  from = `/${from}`;
@@ -417,8 +414,8 @@ function getGraphqlImport(args) {
417
414
  }
418
415
 
419
416
  // src/helpers/get-graphql-input-type.ts
420
- var import_lodash2 = __toModule(require("lodash"));
421
- var import_outmatch = __toModule(require("outmatch"));
417
+ var import_lodash2 = require("lodash");
418
+ var import_outmatch = __toESM(require("outmatch"));
422
419
  function getGraphqlInputType(inputTypes, pattern) {
423
420
  let result;
424
421
  inputTypes = inputTypes.filter((t) => !["null", "Null"].includes(String(t.type)));
@@ -496,7 +493,7 @@ function getPropertyType(args) {
496
493
  }
497
494
 
498
495
  // src/helpers/property-structure.ts
499
- var import_ts_morph3 = __toModule(require("ts-morph"));
496
+ var import_ts_morph3 = require("ts-morph");
500
497
  function propertyStructure(args) {
501
498
  const {
502
499
  isNullable,
@@ -520,7 +517,7 @@ function propertyStructure(args) {
520
517
 
521
518
  // src/handlers/input-type.ts
522
519
  function inputType(args) {
523
- var _a, _b;
520
+ var _a, _b, _c, _d;
524
521
  const {
525
522
  inputType: inputType2,
526
523
  fileType,
@@ -612,7 +609,11 @@ function inputType(args) {
612
609
  getSourceFile
613
610
  });
614
611
  graphqlType = graphqlImport.name;
615
- if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== inputType2.name && !shouldHideField || shouldHideField && propertyType[0] === graphqlImport.name)) {
612
+ let referenceName = propertyType[0];
613
+ if (location === "enumTypes") {
614
+ referenceName = (0, import_lodash3.last)(referenceName.split(" "));
615
+ }
616
+ if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== inputType2.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
616
617
  importDeclarations.set(graphqlImport.name, {
617
618
  namedImports: [{ name: graphqlImport.name }],
618
619
  moduleSpecifier: graphqlImport.specifier
@@ -635,22 +636,21 @@ function inputType(args) {
635
636
  });
636
637
  if (isCustomsApplicable) {
637
638
  for (const options of settings || []) {
638
- if (!options.input || options.kind !== "Decorator") {
639
- continue;
639
+ if ((_c = options.kind === "Decorator" && options.input && ((_b = options.match) == null ? void 0 : _b.call(options, name))) != null ? _c : true) {
640
+ property.decorators.push({
641
+ name: options.name,
642
+ arguments: options.arguments
643
+ });
644
+ (0, import_assert2.ok)(options.from, "Missed 'from' part in configuration or field setting");
645
+ importDeclarations.create(options);
640
646
  }
641
- property.decorators.push({
642
- name: options.name,
643
- arguments: options.arguments
644
- });
645
- (0, import_assert2.ok)(options.from, "Missed 'from' part in configuration or field setting");
646
- importDeclarations.create(options);
647
647
  }
648
648
  }
649
649
  for (const decorate of config.decorate) {
650
650
  if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
651
651
  property.decorators.push({
652
652
  name: decorate.name,
653
- arguments: (_b = decorate.arguments) == null ? void 0 : _b.map((x) => (0, import_pupa.default)(x, { propertyType }))
653
+ arguments: (_d = decorate.arguments) == null ? void 0 : _d.map((x) => (0, import_pupa.default)(x, { propertyType }))
654
654
  });
655
655
  importDeclarations.create(decorate);
656
656
  }
@@ -668,9 +668,9 @@ function inputType(args) {
668
668
  }
669
669
 
670
670
  // src/helpers/object-settings.ts
671
- var import_json52 = __toModule(require("json5"));
672
- var import_lodash4 = __toModule(require("lodash"));
673
- var import_outmatch2 = __toModule(require("outmatch"));
671
+ var import_json52 = __toESM(require("json5"));
672
+ var import_lodash4 = require("lodash");
673
+ var import_outmatch2 = __toESM(require("outmatch"));
674
674
  var ObjectSettings = class extends Array {
675
675
  shouldHideField({
676
676
  name,
@@ -726,7 +726,7 @@ var ObjectSettings = class extends Array {
726
726
  }
727
727
  };
728
728
  function createObjectSettings(args) {
729
- var _a, _b, _c, _d;
729
+ var _a, _b, _c, _d, _e;
730
730
  const { config, text } = args;
731
731
  const result = new ObjectSettings();
732
732
  const textLines = text.split("\n");
@@ -744,6 +744,7 @@ function createObjectSettings(args) {
744
744
  arguments: [],
745
745
  input: false,
746
746
  output: false,
747
+ model: false,
747
748
  from: ""
748
749
  };
749
750
  if (name === "TypeGraphQL.omit" || name === "HideField") {
@@ -751,9 +752,6 @@ function createObjectSettings(args) {
751
752
  } else if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
752
753
  const options = customType(match.groups.args);
753
754
  (0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, { kind: name });
754
- } else if (name === "IsAbstract") {
755
- element.kind = "ObjectType";
756
- element.arguments = { isAbstract: true };
757
755
  } else if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
758
756
  element.kind = "ObjectType";
759
757
  const options = customType(match.groups.args);
@@ -767,14 +765,22 @@ function createObjectSettings(args) {
767
765
  name: options.name,
768
766
  isAbstract: options.isAbstract
769
767
  };
768
+ } else if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
769
+ const options = customType(match.groups.args);
770
+ (0, import_lodash4.merge)(element, { model: true, from: "@nestjs/graphql" }, options, {
771
+ name,
772
+ namespace: false,
773
+ kind: "Decorator",
774
+ arguments: Array.isArray(options.arguments) ? options.arguments.map((s) => import_json52.default.stringify(s)) : options.arguments
775
+ });
770
776
  } else {
771
777
  const namespace = getNamespace(name);
772
778
  element.namespaceImport = namespace;
773
779
  const options = {
774
780
  name,
775
- arguments: (((_d = match.groups) == null ? void 0 : _d.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
781
+ arguments: (((_e = match.groups) == null ? void 0 : _e.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
776
782
  };
777
- (0, import_lodash4.merge)(element, config.fields[namespace], options);
783
+ (0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
778
784
  }
779
785
  result.push(element);
780
786
  }
@@ -844,6 +850,9 @@ function parseArgs(string) {
844
850
  }
845
851
  }
846
852
  function getNamespace(name) {
853
+ if (name === void 0) {
854
+ return void 0;
855
+ }
847
856
  let result = String(name);
848
857
  if (result.includes(".")) {
849
858
  [result] = result.split(".");
@@ -856,9 +865,9 @@ function modelData(model, args) {
856
865
  const { config, modelNames, models, modelFields, fieldSettings } = args;
857
866
  modelNames.push(model.name);
858
867
  models.set(model.name, model);
859
- const modelFieldsValue = new Map();
868
+ const modelFieldsValue = /* @__PURE__ */ new Map();
860
869
  modelFields.set(model.name, modelFieldsValue);
861
- const fieldSettingsValue = new Map();
870
+ const fieldSettingsValue = /* @__PURE__ */ new Map();
862
871
  fieldSettings.set(model.name, fieldSettingsValue);
863
872
  for (const field of model.fields) {
864
873
  if (field.documentation) {
@@ -874,11 +883,11 @@ function modelData(model, args) {
874
883
  }
875
884
 
876
885
  // src/handlers/model-output-type.ts
877
- var import_assert3 = __toModule(require("assert"));
878
- var import_json53 = __toModule(require("json5"));
879
- var import_lodash5 = __toModule(require("lodash"));
880
- var import_pupa2 = __toModule(require("pupa"));
881
- var import_ts_morph5 = __toModule(require("ts-morph"));
886
+ var import_assert3 = require("assert");
887
+ var import_json53 = __toESM(require("json5"));
888
+ var import_lodash5 = require("lodash");
889
+ var import_pupa2 = __toESM(require("pupa"));
890
+ var import_ts_morph5 = require("ts-morph");
882
891
 
883
892
  // src/helpers/get-output-type-name.ts
884
893
  function getOutputTypeName(name) {
@@ -888,7 +897,7 @@ function getOutputTypeName(name) {
888
897
  // src/handlers/model-output-type.ts
889
898
  var nestjsGraphql = "@nestjs/graphql";
890
899
  function modelOutputType(outputType2, args) {
891
- var _a, _b, _c, _d, _e;
900
+ var _a, _b, _c, _d, _e, _f;
892
901
  const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
893
902
  const model = models.get(outputType2.name);
894
903
  (0, import_assert3.ok)(model, `Cannot find model by name ${outputType2.name}`);
@@ -912,8 +921,10 @@ function modelOutputType(outputType2, args) {
912
921
  properties: []
913
922
  };
914
923
  sourceFileStructure.statements.push(classStructure);
915
- const decorator = (_a = classStructure.decorators) == null ? void 0 : _a.find((d) => d.name === "ObjectType");
924
+ (0, import_assert3.ok)(classStructure.decorators, "classStructure.decorators is undefined");
925
+ const decorator = classStructure.decorators.find((d) => d.name === "ObjectType");
916
926
  (0, import_assert3.ok)(decorator, "ObjectType decorator not found");
927
+ let modelSettings;
917
928
  if (model.documentation) {
918
929
  const objectTypeOptions = {};
919
930
  const { documentation, settings } = createObjectSettings({
@@ -928,6 +939,7 @@ function modelOutputType(outputType2, args) {
928
939
  objectTypeOptions.description = documentation;
929
940
  }
930
941
  decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
942
+ modelSettings = settings;
931
943
  }
932
944
  importDeclarations.add("Field", nestjsGraphql);
933
945
  importDeclarations.add("ObjectType", nestjsGraphql);
@@ -939,8 +951,8 @@ function modelOutputType(outputType2, args) {
939
951
  fileType = "output";
940
952
  outputTypeName = getOutputTypeName(outputTypeName);
941
953
  }
942
- const modelField = (_b = modelFields.get(model.name)) == null ? void 0 : _b.get(field.name);
943
- const settings = (_c = fieldSettings.get(model.name)) == null ? void 0 : _c.get(field.name);
954
+ const modelField = (_a = modelFields.get(model.name)) == null ? void 0 : _a.get(field.name);
955
+ const settings = (_b = fieldSettings.get(model.name)) == null ? void 0 : _b.get(field.name);
944
956
  const fieldType = settings == null ? void 0 : settings.getFieldType({
945
957
  name: outputType2.name,
946
958
  output: true
@@ -988,7 +1000,7 @@ function modelOutputType(outputType2, args) {
988
1000
  property.leadingTrivia += `/** ${modelField.documentation} */
989
1001
  `;
990
1002
  }
991
- (_d = classStructure.properties) == null ? void 0 : _d.push(property);
1003
+ (_c = classStructure.properties) == null ? void 0 : _c.push(property);
992
1004
  if (propertySettings) {
993
1005
  importDeclarations.create(__spreadValues({}, propertySettings));
994
1006
  }
@@ -1008,22 +1020,21 @@ function modelOutputType(outputType2, args) {
1008
1020
  })
1009
1021
  ]
1010
1022
  });
1011
- for (const options of settings || []) {
1012
- if (!options.output || options.kind !== "Decorator") {
1013
- continue;
1023
+ for (const setting of settings || []) {
1024
+ if (shouldBeDecorated(setting) && ((_e = (_d = setting.match) == null ? void 0 : _d.call(setting, field.name)) != null ? _e : true)) {
1025
+ property.decorators.push({
1026
+ name: setting.name,
1027
+ arguments: setting.arguments
1028
+ });
1029
+ (0, import_assert3.ok)(setting.from, "Missed 'from' part in configuration or field setting");
1030
+ importDeclarations.create(setting);
1014
1031
  }
1015
- property.decorators.push({
1016
- name: options.name,
1017
- arguments: options.arguments
1018
- });
1019
- (0, import_assert3.ok)(options.from, "Missed 'from' part in configuration or field setting");
1020
- importDeclarations.create(options);
1021
1032
  }
1022
1033
  for (const decorate of config.decorate) {
1023
1034
  if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
1024
1035
  property.decorators.push({
1025
1036
  name: decorate.name,
1026
- arguments: (_e = decorate.arguments) == null ? void 0 : _e.map((x) => (0, import_pupa2.default)(x, { propertyType }))
1037
+ arguments: (_f = decorate.arguments) == null ? void 0 : _f.map((x) => (0, import_pupa2.default)(x, { propertyType }))
1027
1038
  });
1028
1039
  importDeclarations.create(decorate);
1029
1040
  }
@@ -1035,6 +1046,15 @@ function modelOutputType(outputType2, args) {
1035
1046
  propertyType
1036
1047
  });
1037
1048
  }
1049
+ for (const setting of modelSettings || []) {
1050
+ if (shouldBeDecorated(setting)) {
1051
+ classStructure.decorators.push({
1052
+ name: setting.name,
1053
+ arguments: setting.arguments
1054
+ });
1055
+ importDeclarations.create(setting);
1056
+ }
1057
+ }
1038
1058
  if (exportDeclaration) {
1039
1059
  sourceFile.set({
1040
1060
  statements: [exportDeclaration, "\n", classStructure]
@@ -1049,6 +1069,9 @@ function modelOutputType(outputType2, args) {
1049
1069
  });
1050
1070
  }
1051
1071
  }
1072
+ function shouldBeDecorated(setting) {
1073
+ return setting.kind === "Decorator" && (setting.output || setting.model) && !(setting.output && setting.model);
1074
+ }
1052
1075
  function getExportDeclaration(name, statements) {
1053
1076
  return statements.find((structure) => {
1054
1077
  return structure.kind === import_ts_morph5.StructureKind.ExportDeclaration && structure.namedExports.some((o) => (o.alias || o.name) === name);
@@ -1086,13 +1109,13 @@ function isAtomicOperation(name) {
1086
1109
  }
1087
1110
 
1088
1111
  // src/handlers/output-type.ts
1089
- var import_assert4 = __toModule(require("assert"));
1090
- var import_json54 = __toModule(require("json5"));
1091
- var import_lodash6 = __toModule(require("lodash"));
1092
- var import_ts_morph6 = __toModule(require("ts-morph"));
1112
+ var import_assert4 = require("assert");
1113
+ var import_json54 = __toESM(require("json5"));
1114
+ var import_lodash6 = require("lodash");
1115
+ var import_ts_morph6 = require("ts-morph");
1093
1116
  var nestjsGraphql2 = "@nestjs/graphql";
1094
1117
  function outputType(outputType2, args) {
1095
- var _a, _b, _c;
1118
+ var _a, _b, _c, _d, _e;
1096
1119
  const { getSourceFile, models, eventEmitter, fieldSettings, getModelName: getModelName2 } = args;
1097
1120
  const importDeclarations = new ImportDeclarationMap();
1098
1121
  const fileType = "output";
@@ -1139,6 +1162,7 @@ function outputType(outputType2, args) {
1139
1162
  const property = propertyStructure({
1140
1163
  name: field.name,
1141
1164
  isNullable: field.isNullable,
1165
+ hasQuestionToken: isCountOutput ? true : void 0,
1142
1166
  propertyType,
1143
1167
  isList
1144
1168
  });
@@ -1168,7 +1192,11 @@ function outputType(outputType2, args) {
1168
1192
  getSourceFile
1169
1193
  });
1170
1194
  graphqlType = graphqlImport.name;
1171
- if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType2.name && !shouldHideField || shouldHideField && propertyType[0] === graphqlImport.name)) {
1195
+ let referenceName = propertyType[0];
1196
+ if (location === "enumTypes") {
1197
+ referenceName = (0, import_lodash6.last)(referenceName.split(" "));
1198
+ }
1199
+ if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType2.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1172
1200
  importDeclarations.set(graphqlImport.name, {
1173
1201
  namedImports: [{ name: graphqlImport.name }],
1174
1202
  moduleSpecifier: graphqlImport.specifier
@@ -1191,15 +1219,14 @@ function outputType(outputType2, args) {
1191
1219
  });
1192
1220
  if (isCustomsApplicable) {
1193
1221
  for (const options of settings || []) {
1194
- if (!options.output || options.kind !== "Decorator") {
1195
- continue;
1222
+ if ((_e = options.kind === "Decorator" && options.output && ((_d = options.match) == null ? void 0 : _d.call(options, field.name))) != null ? _e : true) {
1223
+ property.decorators.push({
1224
+ name: options.name,
1225
+ arguments: options.arguments
1226
+ });
1227
+ (0, import_assert4.ok)(options.from, "Missed 'from' part in configuration or field setting");
1228
+ importDeclarations.create(options);
1196
1229
  }
1197
- property.decorators.push({
1198
- name: options.name,
1199
- arguments: options.arguments
1200
- });
1201
- (0, import_assert4.ok)(options.from, "Missed 'from' part in configuration or field setting");
1202
- importDeclarations.create(options);
1203
1230
  }
1204
1231
  }
1205
1232
  }
@@ -1215,7 +1242,7 @@ function outputType(outputType2, args) {
1215
1242
  }
1216
1243
 
1217
1244
  // src/handlers/purge-output.ts
1218
- var import_fs = __toModule(require("fs"));
1245
+ var import_fs = require("fs");
1219
1246
  function purgeOutput(emitter) {
1220
1247
  emitter.on("Begin", begin);
1221
1248
  emitter.on("End", end);
@@ -1241,21 +1268,21 @@ async function end({ project, output }) {
1241
1268
  }
1242
1269
 
1243
1270
  // src/handlers/re-export.ts
1244
- var import_ts_morph7 = __toModule(require("ts-morph"));
1245
- var ReExport;
1246
- (function(ReExport2) {
1271
+ var import_ts_morph7 = require("ts-morph");
1272
+ var ReExport = /* @__PURE__ */ ((ReExport2) => {
1247
1273
  ReExport2["None"] = "None";
1248
1274
  ReExport2["Directories"] = "Directories";
1249
1275
  ReExport2["Single"] = "Single";
1250
1276
  ReExport2["All"] = "All";
1251
- })(ReExport || (ReExport = {}));
1277
+ return ReExport2;
1278
+ })(ReExport || {});
1252
1279
  function reExport(emitter) {
1253
1280
  emitter.on("BeforeGenerateFiles", beforeGenerateFiles3);
1254
1281
  }
1255
1282
  function beforeGenerateFiles3(args) {
1256
1283
  const { project, output, config } = args;
1257
1284
  const rootDirectory = project.getDirectoryOrThrow(output);
1258
- if ([ReExport.Directories, ReExport.All].includes(config.reExport)) {
1285
+ if (["Directories" /* Directories */, "All" /* All */].includes(config.reExport)) {
1259
1286
  for (const directory of rootDirectory.getDirectories()) {
1260
1287
  const exportDeclarations = directory.getSourceFiles().filter((sourceFile) => {
1261
1288
  return sourceFile.getBaseName() !== "index.ts";
@@ -1267,7 +1294,7 @@ function beforeGenerateFiles3(args) {
1267
1294
  });
1268
1295
  }
1269
1296
  }
1270
- if (config.reExport === ReExport.Single) {
1297
+ if (config.reExport === "Single" /* Single */) {
1271
1298
  const exportDeclarations = project.getSourceFiles().filter((sourceFile) => {
1272
1299
  return sourceFile.getBaseName() !== "index.ts";
1273
1300
  }).map((sourceFile) => getExportDeclaration2(rootDirectory, sourceFile));
@@ -1277,7 +1304,7 @@ function beforeGenerateFiles3(args) {
1277
1304
  overwrite: true
1278
1305
  });
1279
1306
  }
1280
- if (config.reExport === ReExport.All) {
1307
+ if (config.reExport === "All" /* All */) {
1281
1308
  const exportDeclarations = [];
1282
1309
  for (const directory of rootDirectory.getDirectories()) {
1283
1310
  const sourceFile = directory.getSourceFileOrThrow("index.ts");
@@ -1299,7 +1326,7 @@ function getExportDeclaration2(directory, sourceFile) {
1299
1326
  }
1300
1327
 
1301
1328
  // src/handlers/register-enum.ts
1302
- var import_ts_morph8 = __toModule(require("ts-morph"));
1329
+ var import_ts_morph8 = require("ts-morph");
1303
1330
  function registerEnum(enumType, args) {
1304
1331
  const { getSourceFile, enums } = args;
1305
1332
  const dataModelEnum = enums[enumType.name];
@@ -1360,12 +1387,12 @@ function warning(message) {
1360
1387
  }
1361
1388
 
1362
1389
  // src/helpers/create-config.ts
1363
- var import_assert5 = __toModule(require("assert"));
1364
- var import_filenamify = __toModule(require("filenamify"));
1365
- var import_flat = __toModule(require("flat"));
1366
- var import_json55 = __toModule(require("json5"));
1367
- var import_lodash7 = __toModule(require("lodash"));
1368
- var import_outmatch3 = __toModule(require("outmatch"));
1390
+ var import_assert5 = require("assert");
1391
+ var import_filenamify = __toESM(require("filenamify"));
1392
+ var import_flat = require("flat");
1393
+ var import_json55 = __toESM(require("json5"));
1394
+ var import_lodash7 = require("lodash");
1395
+ var import_outmatch3 = __toESM(require("outmatch"));
1369
1396
  function createConfig(data) {
1370
1397
  var _a;
1371
1398
  const config = (0, import_lodash7.merge)({}, (0, import_flat.unflatten)(data, { delimiter: "_" }));
@@ -1389,6 +1416,7 @@ function createConfig(data) {
1389
1416
  arguments: [],
1390
1417
  output: toBoolean(value.output),
1391
1418
  input: toBoolean(value.input),
1419
+ model: toBoolean(value.model),
1392
1420
  from: value.from,
1393
1421
  defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
1394
1422
  namespaceImport: value.namespaceImport
@@ -1417,7 +1445,7 @@ function createConfig(data) {
1417
1445
  tsConfigFilePath: void 0,
1418
1446
  combineScalarFilters: toBoolean(config.combineScalarFilters),
1419
1447
  noAtomicOperations: toBoolean(config.noAtomicOperations),
1420
- reExport: ReExport[String(config.reExport)] || ReExport.None,
1448
+ reExport: ReExport[String(config.reExport)] || "None" /* None */,
1421
1449
  emitSingle: toBoolean(config.emitSingle),
1422
1450
  emitCompiled: toBoolean(config.emitCompiled),
1423
1451
  $warnings,
@@ -1455,9 +1483,9 @@ function toBoolean(value) {
1455
1483
  }
1456
1484
 
1457
1485
  // src/helpers/generate-file-name.ts
1458
- var import_lodash8 = __toModule(require("lodash"));
1459
- var import_pluralize = __toModule(require("pluralize"));
1460
- var import_pupa3 = __toModule(require("pupa"));
1486
+ var import_lodash8 = require("lodash");
1487
+ var import_pluralize = __toESM(require("pluralize"));
1488
+ var import_pupa3 = __toESM(require("pupa"));
1461
1489
  function generateFileName(args) {
1462
1490
  const { template, type, name, getModelName: getModelName2 } = args;
1463
1491
  return (0, import_pupa3.default)(template, {
@@ -1501,7 +1529,7 @@ function factoryGetSourceFile(args) {
1501
1529
  }
1502
1530
 
1503
1531
  // src/helpers/get-model-name.ts
1504
- var import_lodash9 = __toModule(require("lodash"));
1532
+ var import_lodash9 = require("lodash");
1505
1533
  function createGetModelName(modelNames) {
1506
1534
  return (0, import_lodash9.memoize)(tryGetName);
1507
1535
  function tryGetName(name) {
@@ -1652,14 +1680,14 @@ async function generate(args) {
1652
1680
  }
1653
1681
  config.combineScalarFilters && combineScalarFilters(eventEmitter);
1654
1682
  config.noAtomicOperations && noAtomicOperations(eventEmitter);
1655
- config.reExport !== ReExport.None && reExport(eventEmitter);
1683
+ config.reExport !== "None" /* None */ && reExport(eventEmitter);
1656
1684
  config.emitSingle && emitSingle(eventEmitter);
1657
1685
  config.purgeOutput && purgeOutput(eventEmitter);
1658
1686
  config.requireSingleFieldsInWhereUniqueInput && requireSingleFieldsInWhereUniqueInput(eventEmitter);
1659
- const models = new Map();
1687
+ const models = /* @__PURE__ */ new Map();
1660
1688
  const modelNames = [];
1661
- const modelFields = new Map();
1662
- const fieldSettings = new Map();
1689
+ const modelFields = /* @__PURE__ */ new Map();
1690
+ const fieldSettings = /* @__PURE__ */ new Map();
1663
1691
  const getModelName2 = createGetModelName(modelNames);
1664
1692
  const getSourceFile = factoryGetSourceFile({
1665
1693
  output: generatorOutputValue,
@@ -1672,7 +1700,7 @@ async function generate(args) {
1672
1700
  datamodel,
1673
1701
  schema: { inputObjectTypes, outputObjectTypes, enumTypes }
1674
1702
  } = JSON.parse(JSON.stringify(dmmf));
1675
- const removeTypes = new Set();
1703
+ const removeTypes = /* @__PURE__ */ new Set();
1676
1704
  const eventArguments = {
1677
1705
  models,
1678
1706
  config,
@@ -1683,7 +1711,7 @@ async function generate(args) {
1683
1711
  output: generatorOutputValue,
1684
1712
  getSourceFile,
1685
1713
  eventEmitter,
1686
- typeNames: new Set(),
1714
+ typeNames: /* @__PURE__ */ new Set(),
1687
1715
  enums: (0, import_lodash10.mapKeys)(datamodel.enums, (x) => x.name),
1688
1716
  getModelName: getModelName2,
1689
1717
  removeTypes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "14.4.1",
3
+ "version": "14.6.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",
@@ -47,12 +47,11 @@
47
47
  },
48
48
  "ghooks": {
49
49
  "pre-commit": "precise-commits",
50
- "commit-msg": "sh Taskfile commit_lint",
51
- "pre-push": "ultra test"
50
+ "commit-msg": "sh Taskfile commit_lint"
52
51
  }
53
52
  },
54
53
  "dependencies": {
55
- "@prisma/generator-helper": "^3.2.0",
54
+ "@prisma/generator-helper": "^3.9.2",
56
55
  "await-event-emitter": "^2.0.2",
57
56
  "filenamify": "4.X",
58
57
  "flat": "^5.0.2",
@@ -65,65 +64,63 @@
65
64
  "ts-morph": ">=11"
66
65
  },
67
66
  "devDependencies": {
68
- "@commitlint/cli": "^13.2.0",
69
- "@commitlint/config-conventional": "^13.2.0",
70
- "@nestjs/common": "^8.0.10",
71
- "@nestjs/core": "^8.0.10",
72
- "@nestjs/graphql": "^9.0.5",
73
- "@nestjs/platform-express": "^8.0.10",
74
- "@paljs/plugins": "^4.0.8",
75
- "@prisma/client": "^3.2.0",
76
- "@semantic-release/changelog": "^6.0.0",
77
- "@semantic-release/git": "^10.0.0",
67
+ "@commitlint/cli": "^16.2.1",
68
+ "@commitlint/config-conventional": "^16.2.1",
69
+ "@nestjs/common": "^8.3.1",
70
+ "@nestjs/core": "^8.3.1",
71
+ "@nestjs/graphql": "^10.0.4",
72
+ "@nestjs/platform-express": "^8.3.1",
73
+ "@paljs/plugins": "^4.0.13",
74
+ "@prisma/client": "^3.9.2",
75
+ "@semantic-release/changelog": "^6.0.1",
76
+ "@semantic-release/git": "^10.0.1",
78
77
  "@types/flat": "^5.0.2",
79
- "@types/lodash": "^4.14.175",
80
- "@types/mocha": "^9.0.0",
81
- "@types/node": "^16.10.2",
78
+ "@types/lodash": "^4.14.178",
79
+ "@types/mocha": "^9.1.0",
80
+ "@types/node": "^17.0.18",
82
81
  "@types/pluralize": "^0.0.29",
83
- "@typescript-eslint/eslint-plugin": "^4.33.0",
84
- "@typescript-eslint/parser": "^4.33.0",
85
- "apollo-server-express": "^3.3.0",
86
- "c8": "^7.9.0",
87
- "class-transformer": "^0.4.0",
88
- "class-validator": "^0.13.1",
82
+ "@typescript-eslint/eslint-plugin": "^5.12.0",
83
+ "@typescript-eslint/parser": "^5.12.0",
84
+ "apollo-server-express": "^3.6.3",
85
+ "c8": "^7.11.0",
86
+ "class-transformer": "^0.5.1",
87
+ "class-validator": "^0.13.2",
89
88
  "commitizen": "^4.2.4",
90
89
  "cz-customizable": "^6.3.0",
91
90
  "decimal.js": "^10.3.1",
92
- "eslint": "^7.32.0",
91
+ "eslint": "^8.9.0",
93
92
  "eslint-import-resolver-node": "^0.3.6",
94
- "eslint-plugin-etc": "^1.5.4",
95
- "eslint-plugin-import": "^2.24.2",
93
+ "eslint-plugin-etc": "^2.0.2",
94
+ "eslint-plugin-import": "^2.25.4",
96
95
  "eslint-plugin-only-warn": "^1.0.3",
97
96
  "eslint-plugin-prettier": "^4.0.0",
98
- "eslint-plugin-promise": "^5.1.0",
99
- "eslint-plugin-regexp": "^1.3.1",
97
+ "eslint-plugin-regexp": "^1.5.1",
100
98
  "eslint-plugin-simple-import-sort": "^7.0.0",
101
- "eslint-plugin-sonarjs": "^0.10.0",
102
- "eslint-plugin-sort-class-members": "^1.11.0",
103
- "eslint-plugin-total-functions": "^4.10.1",
104
- "eslint-plugin-unicorn": "^36.0.0",
99
+ "eslint-plugin-sort-class-members": "^1.14.1",
100
+ "eslint-plugin-unicorn": "^41.0.0",
105
101
  "eslint-plugin-wix-editor": "^3.3.0",
106
- "expect": "^27.2.4",
102
+ "expect": "^27.5.1",
107
103
  "ghooks": "^2.0.4",
108
104
  "git-branch-is": "^4.0.0",
109
- "graphql": "^15.6.1",
110
- "graphql-scalars": "^1.11.0",
105
+ "graphql": "^16.3.0",
106
+ "graphql-scalars": "^1.14.1",
111
107
  "graphql-type-json": "^0.3.2",
112
- "mocha": "^9.1.2",
108
+ "mocha": "^9.2.1",
113
109
  "ololog": "^1.1.175",
114
110
  "precise-commits": "^1.0.2",
115
- "prettier": "^2.4.1",
116
- "prisma": "^3.2.0",
117
- "prisma-graphql-type-decimal": "^1.0.0",
111
+ "prettier": "^2.5.1",
112
+ "prisma": "^3.9.2",
113
+ "prisma-graphql-type-decimal": "^2.0.0",
118
114
  "reflect-metadata": "^0.1.13",
119
- "rxjs": "^7.3.1",
120
- "semantic-release": "^18.0.0",
115
+ "request": "^2.88.2",
116
+ "rxjs": "^7.5.4",
117
+ "semantic-release": "^19.0.2",
121
118
  "simplytyped": "^3.3.0",
122
119
  "temp-dir": "^2.0.0",
123
- "ts-node": "^10.2.1",
120
+ "ts-node": "^10.5.0",
124
121
  "ts-node-dev": "^1.1.8",
125
122
  "tslib": "^2.3.1",
126
- "typescript": "^4.4.3",
123
+ "typescript": "^4.5.5",
127
124
  "watchexec-bin": "^1.0.0"
128
125
  }
129
126
  }