prisma-nestjs-graphql 14.3.0 → 14.6.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.
Files changed (3) hide show
  1. package/README.md +75 -2
  2. package/index.js +168 -93
  3. package/package.json +33 -28
package/README.md CHANGED
@@ -345,6 +345,7 @@ generator nestgraphql {
345
345
  fields_{namespace}_from = "module specifier"
346
346
  fields_{namespace}_input = true | false
347
347
  fields_{namespace}_output = true | false
348
+ fields_{namespace}_model = true | false
348
349
  fields_{namespace}_defaultImport = "default import name" | true
349
350
  fields_{namespace}_namespaceImport = "namespace import name"
350
351
  fields_{namespace}_namedImport = true | false
@@ -367,7 +368,14 @@ Default: `false`
367
368
 
368
369
  ##### `fields_{namespace}_output`
369
370
 
370
- Means that it will be applied on output types (classes decorated by `ObjectType`)
371
+ Means that it will be applied on output types (classes decorated by `ObjectType`),
372
+ including models
373
+ Type: `boolean`
374
+ Default: `false`
375
+
376
+ ##### `fields_{namespace}_model`
377
+
378
+ Means that it will be applied only on model types (classes decorated by `ObjectType`)
371
379
  Type: `boolean`
372
380
  Default: `false`
373
381
 
@@ -420,9 +428,42 @@ export class UserCreateInput {
420
428
  }
421
429
  ```
422
430
 
431
+ Custom decorators can be applied on classes (models):
432
+
433
+ ```
434
+ /// @NG.Directive('@extends')
435
+ /// @NG.Directive('@key(fields: "id")')
436
+ model User {
437
+ /// @NG.Directive('@external')
438
+ id String @id
439
+ }
440
+
441
+ generator nestgraphql {
442
+ fields_NG_from = "@nestjs/graphql"
443
+ fields_NG_output = false
444
+ fields_NG_model = true
445
+ }
446
+ ```
447
+
448
+ May generate:
449
+
450
+ ```ts
451
+ import * as NG from '@nestjs/graphql';
452
+
453
+ @NG.Directive('@extends')
454
+ @NG.Directive('@key(fields: "id")')
455
+ export class User {
456
+ @Field(() => ID, { nullable: false })
457
+ @NG.Directive('@external')
458
+ id!: string;
459
+ ```
460
+
423
461
  #### @FieldType()
424
462
 
425
- Allow set custom type for field
463
+ Allow set custom GraphQL scalar type for field
464
+
465
+ To override scalar type in specific classes, you can use glob pattern `match: string | string[]`
466
+ see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
426
467
 
427
468
  ```prisma
428
469
  model User {
@@ -479,6 +520,9 @@ Missing field options will merged from generator configuration.
479
520
 
480
521
  Similar to `@FieldType()` but refer to TypeScript property (actually field too).
481
522
 
523
+ To override TypeScript type in specific classes, you can use glob pattern `match: string | string[]`
524
+ see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
525
+
482
526
  Named import example:
483
527
 
484
528
  ```prisma
@@ -527,6 +571,34 @@ export class User {
527
571
  }
528
572
  ```
529
573
 
574
+ ### @Directive()
575
+
576
+ Allow attach `@Directive` decorator from `@nestjs/graphql`
577
+
578
+ GraphQL federation example:
579
+
580
+ ```
581
+ /// @Directive({ arguments: ['@extends'] })
582
+ /// @Directive({ arguments: ['@key(fields: "id")'] })
583
+ model User {
584
+ /// @Directive({ arguments: ['@external'] })
585
+ id String @id
586
+ }
587
+ ```
588
+
589
+ May generate:
590
+
591
+ ```ts
592
+ @ObjectType()
593
+ @Directive('@extends')
594
+ @Directive('@key(fields: "id")')
595
+ export class User {
596
+ @Field(() => ID, { nullable: false })
597
+ @Directive('@external')
598
+ id!: string;
599
+ }
600
+ ```
601
+
530
602
  #### @ObjectType()
531
603
 
532
604
  Allow rename type in schema and mark as abstract.
@@ -563,6 +635,7 @@ export class User {}
563
635
 
564
636
  ## Similar Projects
565
637
 
638
+ - https://github.com/odroe/nest-gql-mix
566
639
  - https://github.com/rfermann/nestjs-prisma-graphql-generator
567
640
  - https://github.com/madscience/graphql-codegen-nestjs
568
641
  - https://github.com/wSedlacek/prisma-generators/tree/master/libs/nestjs
package/index.js CHANGED
@@ -573,7 +573,10 @@ function inputType(args) {
573
573
  const { isList, location, type } = graphqlInputType;
574
574
  const typeName = String(type);
575
575
  const settings = modelFieldSettings == null ? void 0 : modelFieldSettings.get(name);
576
- const propertySettings = settings == null ? void 0 : settings.getPropertyType();
576
+ const propertySettings = settings == null ? void 0 : settings.getPropertyType({
577
+ name: inputType2.name,
578
+ input: true
579
+ });
577
580
  const isCustomsApplicable = typeName === ((_a = model == null ? void 0 : model.fields.find((f) => f.name === name)) == null ? void 0 : _a.type);
578
581
  const propertyType = (0, import_lodash3.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
579
582
  location,
@@ -585,35 +588,42 @@ function inputType(args) {
585
588
  propertyType,
586
589
  isList
587
590
  });
588
- (_b = classStructure.properties) == null ? void 0 : _b.push(property);
591
+ classStructure.properties.push(property);
589
592
  if (propertySettings) {
590
593
  importDeclarations.create(__spreadValues({}, propertySettings));
591
594
  }
592
- if (settings == null ? void 0 : settings.shouldHideField({ name: inputType2.name, input: true })) {
593
- importDeclarations.add("HideField", "@nestjs/graphql");
594
- (_c = property.decorators) == null ? void 0 : _c.push({ name: "HideField", arguments: [] });
595
+ let graphqlType;
596
+ const shouldHideField = settings == null ? void 0 : settings.shouldHideField({
597
+ name: inputType2.name,
598
+ input: true
599
+ });
600
+ const fieldType = settings == null ? void 0 : settings.getFieldType({
601
+ name: inputType2.name,
602
+ input: true
603
+ });
604
+ if (fieldType && isCustomsApplicable && !shouldHideField) {
605
+ graphqlType = fieldType.name;
606
+ importDeclarations.create(__spreadValues({}, fieldType));
595
607
  } else {
596
- (0, import_assert2.ok)(property.decorators);
597
- let graphqlType;
598
- const fieldType = settings == null ? void 0 : settings.getFieldType();
599
- if (fieldType && fieldType.input && isCustomsApplicable) {
600
- graphqlType = fieldType.name;
601
- importDeclarations.create(__spreadValues({}, fieldType));
602
- } else {
603
- const graphqlImport = getGraphqlImport({
604
- sourceFile,
605
- location,
606
- typeName,
607
- getSourceFile
608
+ const graphqlImport = getGraphqlImport({
609
+ sourceFile,
610
+ location,
611
+ typeName,
612
+ getSourceFile
613
+ });
614
+ graphqlType = graphqlImport.name;
615
+ if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== inputType2.name && !shouldHideField || shouldHideField && propertyType[0] === graphqlImport.name)) {
616
+ importDeclarations.set(graphqlImport.name, {
617
+ namedImports: [{ name: graphqlImport.name }],
618
+ moduleSpecifier: graphqlImport.specifier
608
619
  });
609
- graphqlType = graphqlImport.name;
610
- if (graphqlImport.name !== inputType2.name && graphqlImport.specifier && !importDeclarations.has(graphqlImport.name)) {
611
- importDeclarations.set(graphqlImport.name, {
612
- namedImports: [{ name: graphqlImport.name }],
613
- moduleSpecifier: graphqlImport.specifier
614
- });
615
- }
616
620
  }
621
+ }
622
+ (0, import_assert2.ok)(property.decorators, "property.decorators is undefined");
623
+ if (shouldHideField) {
624
+ importDeclarations.add("HideField", "@nestjs/graphql");
625
+ property.decorators.push({ name: "HideField", arguments: [] });
626
+ } else {
617
627
  property.decorators.push({
618
628
  name: "Field",
619
629
  arguments: [
@@ -625,15 +635,14 @@ function inputType(args) {
625
635
  });
626
636
  if (isCustomsApplicable) {
627
637
  for (const options of settings || []) {
628
- if (!options.input || options.kind !== "Decorator") {
629
- continue;
638
+ if ((_c = options.kind === "Decorator" && options.input && ((_b = options.match) == null ? void 0 : _b.call(options, name))) != null ? _c : true) {
639
+ property.decorators.push({
640
+ name: options.name,
641
+ arguments: options.arguments
642
+ });
643
+ (0, import_assert2.ok)(options.from, "Missed 'from' part in configuration or field setting");
644
+ importDeclarations.create(options);
630
645
  }
631
- property.decorators.push({
632
- name: options.name,
633
- arguments: options.arguments
634
- });
635
- (0, import_assert2.ok)(options.from, "Missed 'from' part in configuration or field setting");
636
- importDeclarations.create(options);
637
646
  }
638
647
  }
639
648
  for (const decorate of config.decorate) {
@@ -671,11 +680,35 @@ var ObjectSettings = class extends Array {
671
680
  const hideField = this.find((s) => s.name === "HideField");
672
681
  return Boolean((hideField == null ? void 0 : hideField.input) && input || (hideField == null ? void 0 : hideField.output) && output || ((_a = hideField == null ? void 0 : hideField.match) == null ? void 0 : _a.call(hideField, name)));
673
682
  }
674
- getFieldType() {
675
- return this.find((s) => s.kind === "FieldType");
683
+ getFieldType({
684
+ name,
685
+ input,
686
+ output
687
+ }) {
688
+ const fieldType = this.find((s) => s.kind === "FieldType");
689
+ if (!fieldType) {
690
+ return void 0;
691
+ }
692
+ if (fieldType.match) {
693
+ return fieldType.match(name) ? fieldType : void 0;
694
+ }
695
+ if (input && !fieldType.input) {
696
+ return void 0;
697
+ }
698
+ if (output && !fieldType.output) {
699
+ return void 0;
700
+ }
701
+ return fieldType;
676
702
  }
677
- getPropertyType() {
678
- return this.find((s) => s.kind === "PropertyType");
703
+ getPropertyType({ name }) {
704
+ const propertyType = this.find((s) => s.kind === "PropertyType");
705
+ if (!propertyType) {
706
+ return void 0;
707
+ }
708
+ if (propertyType.match && !propertyType.match(name)) {
709
+ return void 0;
710
+ }
711
+ return propertyType;
679
712
  }
680
713
  getObjectTypeArguments(options) {
681
714
  const objectTypeOptions = (0, import_lodash4.merge)({}, options);
@@ -692,7 +725,7 @@ var ObjectSettings = class extends Array {
692
725
  }
693
726
  };
694
727
  function createObjectSettings(args) {
695
- var _a, _b, _c, _d;
728
+ var _a, _b, _c, _d, _e;
696
729
  const { config, text } = args;
697
730
  const result = new ObjectSettings();
698
731
  const textLines = text.split("\n");
@@ -710,6 +743,7 @@ function createObjectSettings(args) {
710
743
  arguments: [],
711
744
  input: false,
712
745
  output: false,
746
+ model: false,
713
747
  from: ""
714
748
  };
715
749
  if (name === "TypeGraphQL.omit" || name === "HideField") {
@@ -717,9 +751,6 @@ function createObjectSettings(args) {
717
751
  } else if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? void 0 : _b.args)) {
718
752
  const options = customType(match.groups.args);
719
753
  (0, import_lodash4.merge)(element, options.namespace && config.fields[options.namespace], options, { kind: name });
720
- } else if (name === "IsAbstract") {
721
- element.kind = "ObjectType";
722
- element.arguments = { isAbstract: true };
723
754
  } else if (name === "ObjectType" && ((_c = match.groups) == null ? void 0 : _c.args)) {
724
755
  element.kind = "ObjectType";
725
756
  const options = customType(match.groups.args);
@@ -733,14 +764,22 @@ function createObjectSettings(args) {
733
764
  name: options.name,
734
765
  isAbstract: options.isAbstract
735
766
  };
767
+ } else if (name === "Directive" && ((_d = match.groups) == null ? void 0 : _d.args)) {
768
+ const options = customType(match.groups.args);
769
+ (0, import_lodash4.merge)(element, { model: true, from: "@nestjs/graphql" }, options, {
770
+ name,
771
+ namespace: false,
772
+ kind: "Decorator",
773
+ arguments: Array.isArray(options.arguments) ? options.arguments.map((s) => import_json52.default.stringify(s)) : options.arguments
774
+ });
736
775
  } else {
737
776
  const namespace = getNamespace(name);
738
777
  element.namespaceImport = namespace;
739
778
  const options = {
740
779
  name,
741
- arguments: (((_d = match.groups) == null ? void 0 : _d.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
780
+ arguments: (((_e = match.groups) == null ? void 0 : _e.args) || "").split(",").map((s) => (0, import_lodash4.trim)(s)).filter(Boolean)
742
781
  };
743
- (0, import_lodash4.merge)(element, config.fields[namespace], options);
782
+ (0, import_lodash4.merge)(element, namespace && config.fields[namespace], options);
744
783
  }
745
784
  result.push(element);
746
785
  }
@@ -762,6 +801,9 @@ function customType(args) {
762
801
  if ((_a = options.name) == null ? void 0 : _a.includes(".")) {
763
802
  result.namespaceImport = namespace;
764
803
  }
804
+ if (typeof options.match === "string" || Array.isArray(options.match)) {
805
+ result.match = (0, import_outmatch2.default)(options.match, { separator: false });
806
+ }
765
807
  return result;
766
808
  }
767
809
  function hideFieldDecorator(match) {
@@ -807,6 +849,9 @@ function parseArgs(string) {
807
849
  }
808
850
  }
809
851
  function getNamespace(name) {
852
+ if (name === void 0) {
853
+ return void 0;
854
+ }
810
855
  let result = String(name);
811
856
  if (result.includes(".")) {
812
857
  [result] = result.split(".");
@@ -851,7 +896,7 @@ function getOutputTypeName(name) {
851
896
  // src/handlers/model-output-type.ts
852
897
  var nestjsGraphql = "@nestjs/graphql";
853
898
  function modelOutputType(outputType2, args) {
854
- var _a, _b, _c, _d, _e;
899
+ var _a, _b, _c, _d, _e, _f;
855
900
  const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
856
901
  const model = models.get(outputType2.name);
857
902
  (0, import_assert3.ok)(model, `Cannot find model by name ${outputType2.name}`);
@@ -875,8 +920,10 @@ function modelOutputType(outputType2, args) {
875
920
  properties: []
876
921
  };
877
922
  sourceFileStructure.statements.push(classStructure);
878
- const decorator = (_a = classStructure.decorators) == null ? void 0 : _a.find((d) => d.name === "ObjectType");
923
+ (0, import_assert3.ok)(classStructure.decorators, "classStructure.decorators is undefined");
924
+ const decorator = classStructure.decorators.find((d) => d.name === "ObjectType");
879
925
  (0, import_assert3.ok)(decorator, "ObjectType decorator not found");
926
+ let modelSettings;
880
927
  if (model.documentation) {
881
928
  const objectTypeOptions = {};
882
929
  const { documentation, settings } = createObjectSettings({
@@ -891,6 +938,7 @@ function modelOutputType(outputType2, args) {
891
938
  objectTypeOptions.description = documentation;
892
939
  }
893
940
  decorator.arguments = settings.getObjectTypeArguments(objectTypeOptions);
941
+ modelSettings = settings;
894
942
  }
895
943
  importDeclarations.add("Field", nestjsGraphql);
896
944
  importDeclarations.add("ObjectType", nestjsGraphql);
@@ -902,10 +950,16 @@ function modelOutputType(outputType2, args) {
902
950
  fileType = "output";
903
951
  outputTypeName = getOutputTypeName(outputTypeName);
904
952
  }
905
- const modelField = (_b = modelFields.get(model.name)) == null ? void 0 : _b.get(field.name);
906
- const settings = (_c = fieldSettings.get(model.name)) == null ? void 0 : _c.get(field.name);
907
- const fieldType = settings == null ? void 0 : settings.getFieldType();
908
- const propertySettings = settings == null ? void 0 : settings.getPropertyType();
953
+ const modelField = (_a = modelFields.get(model.name)) == null ? void 0 : _a.get(field.name);
954
+ const settings = (_b = fieldSettings.get(model.name)) == null ? void 0 : _b.get(field.name);
955
+ const fieldType = settings == null ? void 0 : settings.getFieldType({
956
+ name: outputType2.name,
957
+ output: true
958
+ });
959
+ const propertySettings = settings == null ? void 0 : settings.getPropertyType({
960
+ name: outputType2.name,
961
+ output: true
962
+ });
909
963
  const propertyType = (0, import_lodash5.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
910
964
  location,
911
965
  type: outputTypeName
@@ -915,7 +969,7 @@ function modelOutputType(outputType2, args) {
915
969
  propertyType.push("null");
916
970
  }
917
971
  let graphqlType;
918
- if (fieldType && fieldType.output) {
972
+ if (fieldType) {
919
973
  graphqlType = fieldType.name;
920
974
  importDeclarations.create(__spreadValues({}, fieldType));
921
975
  } else {
@@ -945,7 +999,7 @@ function modelOutputType(outputType2, args) {
945
999
  property.leadingTrivia += `/** ${modelField.documentation} */
946
1000
  `;
947
1001
  }
948
- (_d = classStructure.properties) == null ? void 0 : _d.push(property);
1002
+ (_c = classStructure.properties) == null ? void 0 : _c.push(property);
949
1003
  if (propertySettings) {
950
1004
  importDeclarations.create(__spreadValues({}, propertySettings));
951
1005
  }
@@ -965,22 +1019,21 @@ function modelOutputType(outputType2, args) {
965
1019
  })
966
1020
  ]
967
1021
  });
968
- for (const options of settings || []) {
969
- if (!options.output || options.kind !== "Decorator") {
970
- continue;
1022
+ for (const setting of settings || []) {
1023
+ if (shouldBeDecorated(setting) && ((_e = (_d = setting.match) == null ? void 0 : _d.call(setting, field.name)) != null ? _e : true)) {
1024
+ property.decorators.push({
1025
+ name: setting.name,
1026
+ arguments: setting.arguments
1027
+ });
1028
+ (0, import_assert3.ok)(setting.from, "Missed 'from' part in configuration or field setting");
1029
+ importDeclarations.create(setting);
971
1030
  }
972
- property.decorators.push({
973
- name: options.name,
974
- arguments: options.arguments
975
- });
976
- (0, import_assert3.ok)(options.from, "Missed 'from' part in configuration or field setting");
977
- importDeclarations.create(options);
978
1031
  }
979
1032
  for (const decorate of config.decorate) {
980
1033
  if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
981
1034
  property.decorators.push({
982
1035
  name: decorate.name,
983
- arguments: (_e = decorate.arguments) == null ? void 0 : _e.map((x) => (0, import_pupa2.default)(x, { propertyType }))
1036
+ arguments: (_f = decorate.arguments) == null ? void 0 : _f.map((x) => (0, import_pupa2.default)(x, { propertyType }))
984
1037
  });
985
1038
  importDeclarations.create(decorate);
986
1039
  }
@@ -992,6 +1045,15 @@ function modelOutputType(outputType2, args) {
992
1045
  propertyType
993
1046
  });
994
1047
  }
1048
+ for (const setting of modelSettings || []) {
1049
+ if (shouldBeDecorated(setting)) {
1050
+ classStructure.decorators.push({
1051
+ name: setting.name,
1052
+ arguments: setting.arguments
1053
+ });
1054
+ importDeclarations.create(setting);
1055
+ }
1056
+ }
995
1057
  if (exportDeclaration) {
996
1058
  sourceFile.set({
997
1059
  statements: [exportDeclaration, "\n", classStructure]
@@ -1006,6 +1068,9 @@ function modelOutputType(outputType2, args) {
1006
1068
  });
1007
1069
  }
1008
1070
  }
1071
+ function shouldBeDecorated(setting) {
1072
+ return setting.kind === "Decorator" && (setting.output || setting.model) && !(setting.output && setting.model);
1073
+ }
1009
1074
  function getExportDeclaration(name, statements) {
1010
1075
  return statements.find((structure) => {
1011
1076
  return structure.kind === import_ts_morph5.StructureKind.ExportDeclaration && structure.namedExports.some((o) => (o.alias || o.name) === name);
@@ -1049,7 +1114,7 @@ var import_lodash6 = __toModule(require("lodash"));
1049
1114
  var import_ts_morph6 = __toModule(require("ts-morph"));
1050
1115
  var nestjsGraphql2 = "@nestjs/graphql";
1051
1116
  function outputType(outputType2, args) {
1052
- var _a, _b, _c;
1117
+ var _a, _b, _c, _d, _e;
1053
1118
  const { getSourceFile, models, eventEmitter, fieldSettings, getModelName: getModelName2 } = args;
1054
1119
  const importDeclarations = new ImportDeclarationMap();
1055
1120
  const fileType = "output";
@@ -1083,7 +1148,10 @@ function outputType(outputType2, args) {
1083
1148
  const { location, isList, type } = field.outputType;
1084
1149
  const outputTypeName = getOutputTypeName(String(type));
1085
1150
  const settings = isCountOutput ? void 0 : model && ((_a = fieldSettings.get(model.name)) == null ? void 0 : _a.get(field.name));
1086
- const propertySettings = settings == null ? void 0 : settings.getPropertyType();
1151
+ const propertySettings = settings == null ? void 0 : settings.getPropertyType({
1152
+ name: outputType2.name,
1153
+ output: true
1154
+ });
1087
1155
  const isCustomsApplicable = outputTypeName === ((_b = model == null ? void 0 : model.fields.find((f) => f.name === field.name)) == null ? void 0 : _b.type);
1088
1156
  field.outputType.type = outputTypeName;
1089
1157
  const propertyType = (0, import_lodash6.castArray)((propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
@@ -1100,33 +1168,40 @@ function outputType(outputType2, args) {
1100
1168
  if (propertySettings) {
1101
1169
  importDeclarations.create(__spreadValues({}, propertySettings));
1102
1170
  }
1171
+ let graphqlType;
1172
+ const shouldHideField = settings == null ? void 0 : settings.shouldHideField({
1173
+ name: outputType2.name,
1174
+ output: true
1175
+ });
1176
+ const fieldType = settings == null ? void 0 : settings.getFieldType({
1177
+ name: outputType2.name,
1178
+ output: true
1179
+ });
1180
+ if (fieldType && isCustomsApplicable && !shouldHideField) {
1181
+ graphqlType = fieldType.name;
1182
+ importDeclarations.create(__spreadValues({}, fieldType));
1183
+ } else {
1184
+ const graphqlImport = getGraphqlImport({
1185
+ sourceFile,
1186
+ fileType,
1187
+ location,
1188
+ isId: false,
1189
+ typeName: outputTypeName,
1190
+ getSourceFile
1191
+ });
1192
+ graphqlType = graphqlImport.name;
1193
+ if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType2.name && !shouldHideField || shouldHideField && propertyType[0] === graphqlImport.name)) {
1194
+ importDeclarations.set(graphqlImport.name, {
1195
+ namedImports: [{ name: graphqlImport.name }],
1196
+ moduleSpecifier: graphqlImport.specifier
1197
+ });
1198
+ }
1199
+ }
1103
1200
  (0, import_assert4.ok)(property.decorators, "property.decorators is undefined");
1104
- if (settings == null ? void 0 : settings.shouldHideField({ name: outputType2.name, output: true })) {
1201
+ if (shouldHideField) {
1105
1202
  importDeclarations.add("HideField", nestjsGraphql2);
1106
1203
  property.decorators.push({ name: "HideField", arguments: [] });
1107
1204
  } else {
1108
- let graphqlType;
1109
- const fieldType = settings == null ? void 0 : settings.getFieldType();
1110
- if (fieldType && fieldType.output && isCustomsApplicable) {
1111
- graphqlType = fieldType.name;
1112
- importDeclarations.create(__spreadValues({}, fieldType));
1113
- } else {
1114
- const graphqlImport = getGraphqlImport({
1115
- sourceFile,
1116
- fileType,
1117
- location,
1118
- isId: false,
1119
- typeName: outputTypeName,
1120
- getSourceFile
1121
- });
1122
- graphqlType = graphqlImport.name;
1123
- if (graphqlImport.name !== outputType2.name && graphqlImport.specifier && !importDeclarations.has(graphqlImport.name)) {
1124
- importDeclarations.set(graphqlImport.name, {
1125
- namedImports: [{ name: graphqlImport.name }],
1126
- moduleSpecifier: graphqlImport.specifier
1127
- });
1128
- }
1129
- }
1130
1205
  property.decorators.push({
1131
1206
  name: "Field",
1132
1207
  arguments: [
@@ -1138,15 +1213,14 @@ function outputType(outputType2, args) {
1138
1213
  });
1139
1214
  if (isCustomsApplicable) {
1140
1215
  for (const options of settings || []) {
1141
- if (!options.output || options.kind !== "Decorator") {
1142
- continue;
1216
+ if ((_e = options.kind === "Decorator" && options.output && ((_d = options.match) == null ? void 0 : _d.call(options, field.name))) != null ? _e : true) {
1217
+ property.decorators.push({
1218
+ name: options.name,
1219
+ arguments: options.arguments
1220
+ });
1221
+ (0, import_assert4.ok)(options.from, "Missed 'from' part in configuration or field setting");
1222
+ importDeclarations.create(options);
1143
1223
  }
1144
- property.decorators.push({
1145
- name: options.name,
1146
- arguments: options.arguments
1147
- });
1148
- (0, import_assert4.ok)(options.from, "Missed 'from' part in configuration or field setting");
1149
- importDeclarations.create(options);
1150
1224
  }
1151
1225
  }
1152
1226
  }
@@ -1336,6 +1410,7 @@ function createConfig(data) {
1336
1410
  arguments: [],
1337
1411
  output: toBoolean(value.output),
1338
1412
  input: toBoolean(value.input),
1413
+ model: toBoolean(value.model),
1339
1414
  from: value.from,
1340
1415
  defaultImport: toBoolean(value.defaultImport) ? true : value.defaultImport,
1341
1416
  namespaceImport: value.namespaceImport
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "14.3.0",
3
+ "version": "14.6.0",
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",
@@ -44,10 +44,15 @@
44
44
  "config": {
45
45
  "commitizen": {
46
46
  "path": "node_modules/cz-customizable"
47
+ },
48
+ "ghooks": {
49
+ "pre-commit": "precise-commits",
50
+ "commit-msg": "sh Taskfile commit_lint",
51
+ "pre-push": "ultra test"
47
52
  }
48
53
  },
49
54
  "dependencies": {
50
- "@prisma/generator-helper": "^3.1.1",
55
+ "@prisma/generator-helper": "^3.2.1",
51
56
  "await-event-emitter": "^2.0.2",
52
57
  "filenamify": "4.X",
53
58
  "flat": "^5.0.2",
@@ -57,29 +62,28 @@
57
62
  "outmatch": "^0.7.0",
58
63
  "pluralize": "^8.0.0",
59
64
  "pupa": "2.X",
60
- "ts-morph": ">=11 <=12"
65
+ "ts-morph": ">=11"
61
66
  },
62
67
  "devDependencies": {
63
- "@arkweid/lefthook": "0.7.6",
64
- "@commitlint/cli": "^13.1.0",
65
- "@commitlint/config-conventional": "^13.1.0",
66
- "@nestjs/common": "^8.0.6",
67
- "@nestjs/core": "^8.0.6",
68
- "@nestjs/graphql": "^9.0.4",
69
- "@nestjs/platform-express": "^8.0.6",
68
+ "@commitlint/cli": "^13.2.1",
69
+ "@commitlint/config-conventional": "^13.2.0",
70
+ "@nestjs/common": "^8.1.1",
71
+ "@nestjs/core": "^8.1.1",
72
+ "@nestjs/graphql": "^9.0.6",
73
+ "@nestjs/platform-express": "^8.1.1",
70
74
  "@paljs/plugins": "^4.0.8",
71
- "@prisma/client": "^3.1.1",
75
+ "@prisma/client": "^3.2.1",
72
76
  "@semantic-release/changelog": "^6.0.0",
73
77
  "@semantic-release/git": "^10.0.0",
74
78
  "@types/flat": "^5.0.2",
75
- "@types/lodash": "^4.14.173",
79
+ "@types/lodash": "^4.14.175",
76
80
  "@types/mocha": "^9.0.0",
77
- "@types/node": "^16.9.6",
81
+ "@types/node": "^16.11.0",
78
82
  "@types/pluralize": "^0.0.29",
79
- "@typescript-eslint/eslint-plugin": "^4.31.2",
80
- "@typescript-eslint/parser": "^4.31.2",
81
- "apollo-server-express": "^3.3.0",
82
- "c8": "^7.9.0",
83
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
84
+ "@typescript-eslint/parser": "^4.33.0",
85
+ "apollo-server-express": "^3.4.0",
86
+ "c8": "^7.10.0",
83
87
  "class-transformer": "^0.4.0",
84
88
  "class-validator": "^0.13.1",
85
89
  "commitizen": "^4.2.4",
@@ -88,37 +92,38 @@
88
92
  "eslint": "^7.32.0",
89
93
  "eslint-import-resolver-node": "^0.3.6",
90
94
  "eslint-plugin-etc": "^1.5.4",
91
- "eslint-plugin-import": "^2.24.2",
95
+ "eslint-plugin-import": "^2.25.2",
92
96
  "eslint-plugin-only-warn": "^1.0.3",
93
97
  "eslint-plugin-prettier": "^4.0.0",
94
98
  "eslint-plugin-promise": "^5.1.0",
95
- "eslint-plugin-regexp": "^1.1.0",
99
+ "eslint-plugin-regexp": "^1.4.1",
96
100
  "eslint-plugin-simple-import-sort": "^7.0.0",
97
101
  "eslint-plugin-sonarjs": "^0.10.0",
98
102
  "eslint-plugin-sort-class-members": "^1.11.0",
99
103
  "eslint-plugin-total-functions": "^4.10.1",
100
- "eslint-plugin-unicorn": "^36.0.0",
104
+ "eslint-plugin-unicorn": "^37.0.1",
101
105
  "eslint-plugin-wix-editor": "^3.3.0",
102
- "expect": "^27.2.1",
106
+ "expect": "^27.2.5",
107
+ "ghooks": "^2.0.4",
103
108
  "git-branch-is": "^4.0.0",
104
- "graphql": "^15.6.0",
105
- "graphql-scalars": "^1.10.1",
109
+ "graphql": "^15.6.1",
110
+ "graphql-scalars": "^1.12.0",
106
111
  "graphql-type-json": "^0.3.2",
107
- "mocha": "^9.1.1",
112
+ "mocha": "^9.1.3",
108
113
  "ololog": "^1.1.175",
109
114
  "precise-commits": "^1.0.2",
110
115
  "prettier": "^2.4.1",
111
- "prisma": "^3.1.1",
116
+ "prisma": "^3.2.1",
112
117
  "prisma-graphql-type-decimal": "^1.0.0",
113
118
  "reflect-metadata": "^0.1.13",
114
- "rxjs": "^7.3.0",
119
+ "rxjs": "^7.4.0",
115
120
  "semantic-release": "^18.0.0",
116
121
  "simplytyped": "^3.3.0",
117
122
  "temp-dir": "^2.0.0",
118
- "ts-node": "^10.2.1",
123
+ "ts-node": "^10.3.0",
119
124
  "ts-node-dev": "^1.1.8",
120
125
  "tslib": "^2.3.1",
121
- "typescript": "^4.4.3",
126
+ "typescript": "^4.4.4",
122
127
  "watchexec-bin": "^1.0.0"
123
128
  }
124
129
  }