prisma-nestjs-graphql 20.1.0 → 21.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,6 +78,8 @@ Default: `@prisma/client`
78
78
 
79
79
  #### `combineScalarFilters`
80
80
 
81
+ DOESNT WORK IN v21+
82
+
81
83
  Combine nested/nullable scalar filters to single
82
84
  Type: `boolean`
83
85
  Default: `false`
@@ -389,7 +391,7 @@ export class Product {
389
391
  @Field(() => String, {
390
392
  description: 'Old description',
391
393
  deprecationReason: 'Use new name instead',
392
- complexity: 1
394
+ complexity: 1,
393
395
  })
394
396
  oldName: string;
395
397
  }
@@ -757,3 +759,8 @@ import { generate } from 'prisma-nestjs-graphql/generate';
757
759
  - JSON type for the code first approach - https://github.com/nestjs/graphql/issues/111#issuecomment-631452899
758
760
  - https://github.com/paljs/prisma-tools/tree/master/packages/plugins
759
761
  - https://github.com/wasp-lang/wasp
762
+
763
+ ## TODO
764
+
765
+ - keyof typeof SortOrder -> `SortOrder`
766
+ - dummy-createfriends.input.ts -> `create-friends`
package/generate.cjs CHANGED
@@ -20,9 +20,9 @@ var require$1 = (
20
20
  : require
21
21
  );
22
22
 
23
- function isCreateManyReturn(name) {
23
+ function isManyAndReturnOutputType(name) {
24
24
  const lowerName = name.toLowerCase();
25
- if (lowerName.startsWith("createmany") && (lowerName.endsWith("andreturnoutputtype") || lowerName.endsWith("andreturn"))) {
25
+ if ((lowerName.startsWith("createmany") || lowerName.startsWith("updatemany")) && (lowerName.endsWith("andreturnoutputtype") || lowerName.endsWith("andreturn"))) {
26
26
  return true;
27
27
  }
28
28
  return false;
@@ -36,7 +36,7 @@ function argsType(field, args) {
36
36
  if (["queryRaw", "executeRaw"].includes(field.name)) {
37
37
  return;
38
38
  }
39
- if (isCreateManyReturn(field.name)) return;
39
+ if (isManyAndReturnOutputType(field.name)) return;
40
40
  const { eventEmitter, typeNames, getModelName } = args;
41
41
  let className = pascalCase(`${field.name}Args`);
42
42
  const modelName = getModelName(className) || "";
@@ -60,7 +60,7 @@ function argsType(field, args) {
60
60
  const names = ["Count", "Avg", "Sum", "Min", "Max"];
61
61
  if (`${modelName}GroupByArgs` === inputType.name) {
62
62
  const byField = inputType.fields.find((f) => f.name === "by");
63
- if (byField == null ? undefined : byField.inputTypes) {
63
+ if (byField?.inputTypes) {
64
64
  byField.inputTypes = byField.inputTypes.filter((inputType2) => inputType2.isList);
65
65
  }
66
66
  }
@@ -135,7 +135,7 @@ function isScalarFilter(inputType) {
135
135
  return result;
136
136
  }
137
137
  function postBegin(args) {
138
- const { schema, modelNames } = args;
138
+ const { modelNames, schema } = args;
139
139
  const inputTypes = schema.inputObjectTypes.prisma;
140
140
  const enumTypes = schema.enumTypes.model || [];
141
141
  const types = [
@@ -194,21 +194,18 @@ function createAggregateInput(args) {
194
194
  // eslint-disable-next-line unicorn/no-null
195
195
  constraints: { maxNumFields: null, minNumFields: null },
196
196
  name: className,
197
- fields: outputType.fields.map((x) => {
198
- var _a;
199
- return {
200
- name: x.name,
201
- isNullable: (_a = x.isNullable) != null ? _a : true,
202
- isRequired: false,
203
- inputTypes: [
204
- {
205
- isList: false,
206
- type: "true",
207
- location: "scalar"
208
- }
209
- ]
210
- };
211
- })
197
+ fields: outputType.fields.map((x) => ({
198
+ name: x.name,
199
+ isNullable: x.isNullable ?? true,
200
+ isRequired: false,
201
+ inputTypes: [
202
+ {
203
+ isList: false,
204
+ type: "true",
205
+ location: "scalar"
206
+ }
207
+ ]
208
+ }))
212
209
  };
213
210
  eventEmitter.emitSync("InputType", {
214
211
  ...args,
@@ -282,7 +279,6 @@ async function generateFiles(args) {
282
279
  const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
283
280
  const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", undefined, { overwrite: true });
284
281
  const statements = project.getSourceFiles().flatMap((s) => {
285
- var _a, _b;
286
282
  if (s === sourceFile) {
287
283
  return [];
288
284
  }
@@ -295,7 +291,7 @@ async function generateFiles(args) {
295
291
  }
296
292
  for (const property of statement.properties || []) {
297
293
  for (const decorator of property.decorators || []) {
298
- const fullName = (_b = (_a = classDeclaration == null ? undefined : classDeclaration.getProperty(property.name)) == null ? undefined : _a.getDecorator(decorator.name)) == null ? undefined : _b.getFullName();
294
+ const fullName = classDeclaration?.getProperty(property.name)?.getDecorator(decorator.name)?.getFullName();
299
295
  assert.ok(
300
296
  fullName,
301
297
  `Cannot get full name of decorator of class ${statement.name}`
@@ -526,7 +522,7 @@ function getGraphqlInputType(inputTypes, pattern) {
526
522
  }
527
523
 
528
524
  function getPropertyType(args) {
529
- const { type, location } = args;
525
+ const { location, type } = args;
530
526
  switch (type) {
531
527
  case "Float":
532
528
  case "Int": {
@@ -551,7 +547,7 @@ function getPropertyType(args) {
551
547
  return ["null"];
552
548
  }
553
549
  case "Bytes": {
554
- return ["Buffer"];
550
+ return ["Uint8Array"];
555
551
  }
556
552
  case "BigInt": {
557
553
  return ["bigint", "number"];
@@ -602,15 +598,14 @@ function propertyStructure(args) {
602
598
  kind: tsMorph.StructureKind.Property,
603
599
  name,
604
600
  type,
605
- hasQuestionToken: hasQuestionToken != null ? hasQuestionToken : isNullable,
606
- hasExclamationToken: hasExclamationToken != null ? hasExclamationToken : !isNullable,
601
+ hasQuestionToken: hasQuestionToken ?? isNullable,
602
+ hasExclamationToken: hasExclamationToken ?? !isNullable,
607
603
  decorators: [],
608
604
  leadingTrivia: "\n"
609
605
  };
610
606
  }
611
607
 
612
608
  function inputType(args) {
613
- var _a, _b, _c, _d;
614
609
  const {
615
610
  classDecoratorName,
616
611
  classTransformerTypeModels,
@@ -665,27 +660,27 @@ function inputType(args) {
665
660
  if (inputTypes.length === 0) {
666
661
  continue;
667
662
  }
668
- const usePattern = (useInputType == null ? undefined : useInputType.ALL) || (useInputType == null ? undefined : useInputType[name]);
663
+ const usePattern = useInputType?.ALL || useInputType?.[name];
669
664
  const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
670
665
  const { isList, location, type } = graphqlInputType;
671
666
  const typeName = String(type);
672
- const settings = modelFieldSettings == null ? undefined : modelFieldSettings.get(name);
673
- const propertySettings = settings == null ? undefined : settings.getPropertyType({
667
+ const settings = modelFieldSettings?.get(name);
668
+ const propertySettings = settings?.getPropertyType({
674
669
  name: inputType2.name,
675
670
  input: true
676
671
  });
677
- const modelField = model == null ? undefined : model.fields.find((f) => f.name === name);
678
- const isCustomsApplicable = typeName === (modelField == null ? undefined : modelField.type);
672
+ const modelField = model?.fields.find((f) => f.name === name);
673
+ const isCustomsApplicable = typeName === modelField?.type;
679
674
  const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
680
675
  const whereUniqueInputType = isWhereUniqueInputType(typeName) && atLeastKeys && `Prisma.AtLeast<${typeName}, ${atLeastKeys.map((name2) => `'${name2}'`).join(" | ")}>`;
681
676
  const propertyType = lodash.castArray(
682
- (propertySettings == null ? undefined : propertySettings.name) || whereUniqueInputType || getPropertyType({
677
+ propertySettings?.name || whereUniqueInputType || getPropertyType({
683
678
  location,
684
679
  type: typeName
685
680
  })
686
681
  );
687
682
  const hasExclamationToken = Boolean(
688
- isWhereUnique && config.unsafeCompatibleWhereUniqueInput && (atLeastKeys == null ? undefined : atLeastKeys.includes(name))
683
+ isWhereUnique && config.unsafeCompatibleWhereUniqueInput && atLeastKeys?.includes(name)
689
684
  );
690
685
  const property = propertyStructure({
691
686
  name,
@@ -704,13 +699,13 @@ function inputType(args) {
704
699
  importDeclarations.add("Prisma", config.prismaClientImport);
705
700
  }
706
701
  let graphqlType;
707
- const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
702
+ const shouldHideField = settings?.shouldHideField({
708
703
  name: inputType2.name,
709
704
  input: true
710
- })) || config.decorate.some(
705
+ }) || config.decorate.some(
711
706
  (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputType2.name)
712
707
  );
713
- const fieldType = settings == null ? undefined : settings.getFieldType({
708
+ const fieldType = settings?.getFieldType({
714
709
  name: inputType2.name,
715
710
  input: true
716
711
  });
@@ -747,7 +742,7 @@ function inputType(args) {
747
742
  arguments: [
748
743
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
749
744
  JSON5.stringify({
750
- ...settings == null ? undefined : settings.fieldArguments(),
745
+ ...settings?.fieldArguments(),
751
746
  nullable: !isRequired
752
747
  })
753
748
  ]
@@ -766,7 +761,7 @@ function inputType(args) {
766
761
  arguments: ["transformToDecimal"]
767
762
  }
768
763
  );
769
- } else if (location === "inputObjectTypes" && ((modelField == null ? undefined : modelField.type) === "Decimal" || [
764
+ } else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
770
765
  "connect",
771
766
  "connectOrCreate",
772
767
  "create",
@@ -780,15 +775,15 @@ function inputType(args) {
780
775
  "updateMany",
781
776
  "upsert",
782
777
  "where"
783
- ].includes(name) || classTransformerTypeModels.has(getModelName(graphqlType) || "") || (modelField == null ? undefined : modelField.kind) === "object" && models.get(modelField.type) && ((_a = models.get(modelField.type)) == null ? undefined : _a.fields.some(
778
+ ].includes(name) || classTransformerTypeModels.has(getModelName(graphqlType) || "") || modelField?.kind === "object" && models.get(modelField.type) && models.get(modelField.type)?.fields.some(
784
779
  (field2) => field2.kind === "object" && classTransformerTypeModels.has(field2.type)
785
- )))) {
780
+ ))) {
786
781
  importDeclarations.add("Type", "class-transformer");
787
782
  property.decorators.push({ name: "Type", arguments: [`() => ${graphqlType}`] });
788
783
  }
789
784
  if (isCustomsApplicable) {
790
785
  for (const options of settings || []) {
791
- if ((_c = options.kind === "Decorator" && options.input && ((_b = options.match) == null ? undefined : _b.call(options, name))) != null ? _c : true) {
786
+ if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
792
787
  property.decorators.push({
793
788
  name: options.name,
794
789
  arguments: options.arguments
@@ -802,7 +797,7 @@ function inputType(args) {
802
797
  if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
803
798
  property.decorators.push({
804
799
  name: decorate.name,
805
- arguments: (_d = decorate.arguments) == null ? undefined : _d.map((x) => pupa(x, { propertyType }))
800
+ arguments: decorate.arguments?.map((x) => pupa(x, { propertyType }))
806
801
  });
807
802
  importDeclarations.create(decorate);
808
803
  }
@@ -825,10 +820,9 @@ class ObjectSettings extends Array {
825
820
  input = false,
826
821
  output = false
827
822
  }) {
828
- var _a;
829
823
  const hideField = this.find((s) => s.name === "HideField");
830
824
  return Boolean(
831
- (hideField == null ? undefined : hideField.input) && input || (hideField == null ? undefined : hideField.output) && output || ((_a = hideField == null ? undefined : hideField.match) == null ? undefined : _a.call(hideField, name))
825
+ hideField?.input && input || hideField?.output && output || hideField?.match?.(name)
832
826
  );
833
827
  }
834
828
  getFieldType({
@@ -930,7 +924,6 @@ function createSettingElement({
930
924
  fieldElement,
931
925
  match
932
926
  }) {
933
- var _a, _b, _c, _d, _e;
934
927
  const result = {
935
928
  documentLine: "",
936
929
  element: undefined
@@ -947,7 +940,7 @@ function createSettingElement({
947
940
  result.element = fieldElement;
948
941
  return result;
949
942
  }
950
- const name = (_a = match == null ? undefined : match.groups) == null ? undefined : _a.name;
943
+ const name = match?.groups?.name;
951
944
  if (!(match && name)) {
952
945
  result.documentLine = line;
953
946
  return result;
@@ -966,14 +959,14 @@ function createSettingElement({
966
959
  Object.assign(element, hideFieldDecorator(match));
967
960
  return result;
968
961
  }
969
- if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? undefined : _b.args)) {
962
+ if (["FieldType", "PropertyType"].includes(name) && match.groups?.args) {
970
963
  const options2 = customType(match.groups.args);
971
964
  lodash.merge(element, options2.namespace && config.fields[options2.namespace], options2, {
972
965
  kind: name
973
966
  });
974
967
  return result;
975
968
  }
976
- if (name === "ObjectType" && ((_c = match.groups) == null ? undefined : _c.args)) {
969
+ if (name === "ObjectType" && match.groups?.args) {
977
970
  element.kind = "ObjectType";
978
971
  const options2 = customType(match.groups.args);
979
972
  if (typeof options2[0] === "string" && options2[0]) {
@@ -988,7 +981,7 @@ function createSettingElement({
988
981
  };
989
982
  return result;
990
983
  }
991
- if (name === "Directive" && ((_d = match.groups) == null ? undefined : _d.args)) {
984
+ if (name === "Directive" && match.groups?.args) {
992
985
  const options2 = customType(match.groups.args);
993
986
  lodash.merge(element, { model: true, from: "@nestjs/graphql" }, options2, {
994
987
  name,
@@ -1002,13 +995,12 @@ function createSettingElement({
1002
995
  element.namespaceImport = namespace;
1003
996
  const options = {
1004
997
  name,
1005
- arguments: (((_e = match.groups) == null ? undefined : _e.args) || "").split(",").map((s) => lodash.trim(s)).filter(Boolean)
998
+ arguments: (match.groups?.args || "").split(",").map((s) => lodash.trim(s)).filter(Boolean)
1006
999
  };
1007
1000
  lodash.merge(element, namespace && config.fields[namespace], options);
1008
1001
  return result;
1009
1002
  }
1010
1003
  function customType(args) {
1011
- var _a;
1012
1004
  const result = {};
1013
1005
  let options = parseArgs(args);
1014
1006
  if (typeof options === "string") {
@@ -1017,7 +1009,7 @@ function customType(args) {
1017
1009
  Object.assign(result, options);
1018
1010
  const namespace = getNamespace(options.name);
1019
1011
  result.namespace = namespace;
1020
- if ((_a = options.name) == null ? undefined : _a.includes(".")) {
1012
+ if (options.name?.includes(".")) {
1021
1013
  result.namespaceImport = namespace;
1022
1014
  }
1023
1015
  if (typeof options.match === "string" || Array.isArray(options.match)) {
@@ -1026,7 +1018,6 @@ function customType(args) {
1026
1018
  return result;
1027
1019
  }
1028
1020
  function hideFieldDecorator(match) {
1029
- var _a;
1030
1021
  const result = {
1031
1022
  name: "HideField",
1032
1023
  arguments: [],
@@ -1035,7 +1026,7 @@ function hideFieldDecorator(match) {
1035
1026
  namespaceImport: undefined,
1036
1027
  match: undefined
1037
1028
  };
1038
- if (!((_a = match.groups) == null ? undefined : _a.args)) {
1029
+ if (!match.groups?.args) {
1039
1030
  result.output = true;
1040
1031
  return result;
1041
1032
  }
@@ -1110,13 +1101,12 @@ function modelData(model, args) {
1110
1101
  }
1111
1102
 
1112
1103
  function createComment(documentation, settings) {
1113
- var _a;
1114
1104
  const documentationLines = documentation.split("\n");
1115
1105
  const commentLines = ["/**"];
1116
1106
  for (const line of documentationLines) {
1117
1107
  commentLines.push(` * ${line}`);
1118
1108
  }
1119
- const deprecationReason = (_a = settings == null ? undefined : settings.fieldArguments()) == null ? undefined : _a.deprecationReason;
1109
+ const deprecationReason = settings?.fieldArguments()?.deprecationReason;
1120
1110
  if (deprecationReason) {
1121
1111
  commentLines.push(` * @deprecated ${deprecationReason}`);
1122
1112
  }
@@ -1130,9 +1120,8 @@ function getOutputTypeName(name) {
1130
1120
 
1131
1121
  const nestjsGraphql$1 = "@nestjs/graphql";
1132
1122
  function modelOutputType(outputType, args) {
1133
- var _a, _b, _c, _d, _e, _f;
1134
- const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } = args;
1135
- if (isCreateManyReturn(outputType.name)) return;
1123
+ const { config, eventEmitter, fieldSettings, getSourceFile, modelFields, models } = args;
1124
+ if (isManyAndReturnOutputType(outputType.name)) return;
1136
1125
  const model = models.get(outputType.name);
1137
1126
  assert.ok(model, `Cannot find model by name ${outputType.name}`);
1138
1127
  const sourceFile = getSourceFile({
@@ -1146,15 +1135,15 @@ function modelOutputType(outputType, args) {
1146
1135
  );
1147
1136
  const importDeclarations = new ImportDeclarationMap();
1148
1137
  const classStructure = {
1149
- kind: tsMorph.StructureKind.Class,
1150
- isExported: true,
1151
- name: outputType.name,
1152
1138
  decorators: [
1153
1139
  {
1154
- name: "ObjectType",
1155
- arguments: []
1140
+ arguments: [],
1141
+ name: "ObjectType"
1156
1142
  }
1157
1143
  ],
1144
+ isExported: true,
1145
+ kind: tsMorph.StructureKind.Class,
1146
+ name: outputType.name,
1158
1147
  properties: []
1159
1148
  };
1160
1149
  sourceFileStructure.statements.push(classStructure);
@@ -1165,8 +1154,8 @@ function modelOutputType(outputType, args) {
1165
1154
  if (model.documentation) {
1166
1155
  const objectTypeOptions = {};
1167
1156
  const { documentation, settings } = createObjectSettings({
1168
- text: model.documentation,
1169
- config
1157
+ config,
1158
+ text: model.documentation
1170
1159
  });
1171
1160
  if (documentation) {
1172
1161
  if (!classStructure.leadingTrivia) {
@@ -1182,24 +1171,24 @@ function modelOutputType(outputType, args) {
1182
1171
  for (const field of outputType.fields) {
1183
1172
  if (config.omitModelsCount && field.name === "_count") continue;
1184
1173
  let fileType = "model";
1185
- const { location, isList, type, namespace } = field.outputType;
1174
+ const { isList, location, namespace, type } = field.outputType;
1186
1175
  let outputTypeName = String(type);
1187
1176
  if (namespace !== "model") {
1188
1177
  fileType = "output";
1189
1178
  outputTypeName = getOutputTypeName(outputTypeName);
1190
1179
  }
1191
- const modelField = (_a = modelFields.get(model.name)) == null ? undefined : _a.get(field.name);
1192
- const settings = (_b = fieldSettings.get(model.name)) == null ? undefined : _b.get(field.name);
1193
- const fieldType = settings == null ? undefined : settings.getFieldType({
1180
+ const modelField = modelFields.get(model.name)?.get(field.name);
1181
+ const settings = fieldSettings.get(model.name)?.get(field.name);
1182
+ const fieldType = settings?.getFieldType({
1194
1183
  name: outputType.name,
1195
1184
  output: true
1196
1185
  });
1197
- const propertySettings = settings == null ? undefined : settings.getPropertyType({
1186
+ const propertySettings = settings?.getPropertyType({
1198
1187
  name: outputType.name,
1199
1188
  output: true
1200
1189
  });
1201
1190
  const propertyType = lodash.castArray(
1202
- (propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
1191
+ propertySettings?.name || getPropertyType({
1203
1192
  location,
1204
1193
  type: outputTypeName
1205
1194
  })
@@ -1215,13 +1204,13 @@ function modelOutputType(outputType, args) {
1215
1204
  } else {
1216
1205
  const graphqlImport = getGraphqlImport({
1217
1206
  config,
1218
- sourceFile,
1219
1207
  fileType,
1208
+ getSourceFile,
1209
+ isId: modelField?.isId,
1220
1210
  location,
1221
- isId: modelField == null ? undefined : modelField.isId,
1222
1211
  noTypeId: config.noTypeId,
1223
- typeName: outputTypeName,
1224
- getSourceFile
1212
+ sourceFile,
1213
+ typeName: outputTypeName
1225
1214
  });
1226
1215
  graphqlType = graphqlImport.name;
1227
1216
  if (graphqlImport.name !== outputType.name && graphqlImport.specifier) {
@@ -1229,49 +1218,49 @@ function modelOutputType(outputType, args) {
1229
1218
  }
1230
1219
  }
1231
1220
  const property = propertyStructure({
1232
- name: field.name,
1233
- isNullable: field.isNullable,
1234
1221
  hasExclamationToken: true,
1235
1222
  hasQuestionToken: location === "outputObjectTypes",
1236
- propertyType,
1237
- isList
1223
+ isList,
1224
+ isNullable: field.isNullable,
1225
+ name: field.name,
1226
+ propertyType
1238
1227
  });
1239
- if (typeof property.leadingTrivia === "string" && (modelField == null ? undefined : modelField.documentation)) {
1228
+ if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1240
1229
  property.leadingTrivia += createComment(modelField.documentation, settings);
1241
1230
  }
1242
- (_c = classStructure.properties) == null ? undefined : _c.push(property);
1231
+ classStructure.properties?.push(property);
1243
1232
  if (propertySettings) {
1244
1233
  importDeclarations.create({ ...propertySettings });
1245
1234
  } else if (propertyType.includes("Decimal")) {
1246
1235
  importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
1247
1236
  }
1248
1237
  assert.ok(property.decorators, "property.decorators is undefined");
1249
- const shouldHideField = (settings == null ? undefined : settings.shouldHideField({ name: outputType.name, output: true })) || config.decorate.some(
1238
+ const shouldHideField = settings?.shouldHideField({ name: outputType.name, output: true }) || config.decorate.some(
1250
1239
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1251
1240
  );
1252
1241
  if (shouldHideField) {
1253
1242
  importDeclarations.add("HideField", nestjsGraphql$1);
1254
- property.decorators.push({ name: "HideField", arguments: [] });
1243
+ property.decorators.push({ arguments: [], name: "HideField" });
1255
1244
  } else {
1256
1245
  property.decorators.push({
1257
- name: "Field",
1258
1246
  arguments: [
1259
1247
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1260
1248
  JSON5.stringify({
1261
- ...settings == null ? undefined : settings.fieldArguments(),
1262
- nullable: Boolean(field.isNullable),
1249
+ ...settings?.fieldArguments(),
1263
1250
  defaultValue: ["number", "string", "boolean"].includes(
1264
- typeof (modelField == null ? undefined : modelField.default)
1265
- ) ? modelField == null ? undefined : modelField.default : undefined,
1266
- description: modelField == null ? undefined : modelField.documentation
1251
+ typeof modelField?.default
1252
+ ) ? modelField?.default : undefined,
1253
+ description: modelField?.documentation,
1254
+ nullable: Boolean(field.isNullable)
1267
1255
  })
1268
- ]
1256
+ ],
1257
+ name: "Field"
1269
1258
  });
1270
1259
  for (const setting of settings || []) {
1271
- if (shouldBeDecorated(setting) && ((_e = (_d = setting.match) == null ? undefined : _d.call(setting, field.name)) != null ? _e : true)) {
1260
+ if (shouldBeDecorated(setting) && (setting.match?.(field.name) ?? true)) {
1272
1261
  property.decorators.push({
1273
- name: setting.name,
1274
- arguments: setting.arguments
1262
+ arguments: setting.arguments,
1263
+ name: setting.name
1275
1264
  });
1276
1265
  assert.ok(setting.from, "Missed 'from' part in configuration or field setting");
1277
1266
  importDeclarations.create(setting);
@@ -1280,24 +1269,24 @@ function modelOutputType(outputType, args) {
1280
1269
  for (const decorate of config.decorate) {
1281
1270
  if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
1282
1271
  property.decorators.push({
1283
- name: decorate.name,
1284
- arguments: (_f = decorate.arguments) == null ? undefined : _f.map((x) => pupa(x, { propertyType }))
1272
+ arguments: decorate.arguments?.map((x) => pupa(x, { propertyType })),
1273
+ name: decorate.name
1285
1274
  });
1286
1275
  importDeclarations.create(decorate);
1287
1276
  }
1288
1277
  }
1289
1278
  }
1290
1279
  eventEmitter.emitSync("ClassProperty", property, {
1291
- location,
1292
1280
  isList,
1281
+ location,
1293
1282
  propertyType
1294
1283
  });
1295
1284
  }
1296
1285
  for (const setting of modelSettings || []) {
1297
1286
  if (shouldBeDecorated(setting)) {
1298
1287
  classStructure.decorators.push({
1299
- name: setting.name,
1300
- arguments: setting.arguments
1288
+ arguments: setting.arguments,
1289
+ name: setting.name
1301
1290
  });
1302
1291
  importDeclarations.create(setting);
1303
1292
  }
@@ -1346,10 +1335,9 @@ function beforeInputType$1(args) {
1346
1335
  }
1347
1336
  }
1348
1337
  function beforeGenerateFiles$1(args) {
1349
- var _a;
1350
1338
  const { project } = args;
1351
1339
  for (const sourceFile of project.getSourceFiles()) {
1352
- const className = (_a = sourceFile.getClass(() => true)) == null ? undefined : _a.getName();
1340
+ const className = sourceFile.getClass(() => true)?.getName();
1353
1341
  if (className && isAtomicOperation(className)) {
1354
1342
  project.removeSourceFile(sourceFile);
1355
1343
  }
@@ -1367,14 +1355,13 @@ function isListInput(typeName, model, field) {
1367
1355
 
1368
1356
  const nestjsGraphql = "@nestjs/graphql";
1369
1357
  function outputType(outputType2, args) {
1370
- var _a, _b, _c, _d, _e;
1371
1358
  const { getSourceFile, models, eventEmitter, fieldSettings, getModelName, config } = args;
1372
1359
  const importDeclarations = new ImportDeclarationMap();
1373
1360
  const fileType = "output";
1374
1361
  const modelName = getModelName(outputType2.name) || "";
1375
1362
  const model = models.get(modelName);
1376
1363
  const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
1377
- const isCountOutput = (model == null ? undefined : model.name) && outputType2.name === `${model.name}CountOutputType`;
1364
+ const isCountOutput = model?.name && outputType2.name === `${model.name}CountOutputType`;
1378
1365
  if (!config.emitBlocks.outputs && !isCountOutput) return;
1379
1366
  outputType2.name = getOutputTypeName(outputType2.name);
1380
1367
  if (isAggregateOutput) {
@@ -1401,15 +1388,15 @@ function outputType(outputType2, args) {
1401
1388
  for (const field of outputType2.fields) {
1402
1389
  const { location, isList, type } = field.outputType;
1403
1390
  const outputTypeName = getOutputTypeName(String(type));
1404
- const settings = isCountOutput ? undefined : model && ((_a = fieldSettings.get(model.name)) == null ? undefined : _a.get(field.name));
1405
- const propertySettings = settings == null ? undefined : settings.getPropertyType({
1391
+ const settings = isCountOutput ? undefined : model && fieldSettings.get(model.name)?.get(field.name);
1392
+ const propertySettings = settings?.getPropertyType({
1406
1393
  name: outputType2.name,
1407
1394
  output: true
1408
1395
  });
1409
- const isCustomsApplicable = outputTypeName === ((_b = model == null ? undefined : model.fields.find((f) => f.name === field.name)) == null ? undefined : _b.type);
1396
+ const isCustomsApplicable = outputTypeName === model?.fields.find((f) => f.name === field.name)?.type;
1410
1397
  field.outputType.type = outputTypeName;
1411
1398
  const propertyType = lodash.castArray(
1412
- (propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
1399
+ propertySettings?.name || getPropertyType({
1413
1400
  location,
1414
1401
  type: outputTypeName
1415
1402
  })
@@ -1421,20 +1408,20 @@ function outputType(outputType2, args) {
1421
1408
  propertyType,
1422
1409
  isList
1423
1410
  });
1424
- (_c = classStructure.properties) == null ? undefined : _c.push(property);
1411
+ classStructure.properties?.push(property);
1425
1412
  if (propertySettings) {
1426
1413
  importDeclarations.create({ ...propertySettings });
1427
1414
  } else if (propertyType.includes("Decimal")) {
1428
1415
  importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
1429
1416
  }
1430
1417
  let graphqlType;
1431
- const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
1418
+ const shouldHideField = settings?.shouldHideField({
1432
1419
  name: outputType2.name,
1433
1420
  output: true
1434
- })) || config.decorate.some(
1421
+ }) || config.decorate.some(
1435
1422
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1436
1423
  );
1437
- const fieldType = settings == null ? undefined : settings.getFieldType({
1424
+ const fieldType = settings?.getFieldType({
1438
1425
  name: outputType2.name,
1439
1426
  output: true
1440
1427
  });
@@ -1473,14 +1460,14 @@ function outputType(outputType2, args) {
1473
1460
  arguments: [
1474
1461
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1475
1462
  JSON5.stringify({
1476
- ...settings == null ? undefined : settings.fieldArguments(),
1463
+ ...settings?.fieldArguments(),
1477
1464
  nullable: Boolean(field.isNullable)
1478
1465
  })
1479
1466
  ]
1480
1467
  });
1481
1468
  if (isCustomsApplicable) {
1482
1469
  for (const options of settings || []) {
1483
- if ((_e = options.kind === "Decorator" && options.output && ((_d = options.match) == null ? undefined : _d.call(options, field.name))) != null ? _e : true) {
1470
+ if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
1484
1471
  property.decorators.push({
1485
1472
  name: options.name,
1486
1473
  arguments: options.arguments
@@ -1507,8 +1494,7 @@ function purgeOutput(emitter) {
1507
1494
  emitter.on("End", end);
1508
1495
  }
1509
1496
  function begin({ project, output }) {
1510
- var _a;
1511
- const sourceFiles = (_a = project.getDirectory(output)) == null ? undefined : _a.getDescendantSourceFiles();
1497
+ const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
1512
1498
  if (sourceFiles) {
1513
1499
  for (const sourceFile of sourceFiles) {
1514
1500
  sourceFile.delete();
@@ -1516,8 +1502,7 @@ function begin({ project, output }) {
1516
1502
  }
1517
1503
  }
1518
1504
  function end({ project, output }) {
1519
- var _a;
1520
- const directories = (_a = project.getDirectory(output)) == null ? undefined : _a.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1505
+ const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1521
1506
  for (const directory of directories || []) {
1522
1507
  try {
1523
1508
  gracefulFs.rmdirSync(directory);
@@ -1646,7 +1631,7 @@ function registerEnum(enumType, args) {
1646
1631
  ...importDeclarations.toStatements(),
1647
1632
  enumStructure,
1648
1633
  "\n",
1649
- `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum == null ? undefined : dataModelEnum.documentation)} })`
1634
+ `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum?.documentation)} })`
1650
1635
  ]
1651
1636
  });
1652
1637
  }
@@ -1674,7 +1659,14 @@ function warning(message) {
1674
1659
  }
1675
1660
  }
1676
1661
 
1677
- const allEmmittedBlocks = ["prismaEnums", "schemaEnums", "models", "inputs", "args", "outputs"];
1662
+ const allEmmittedBlocks = [
1663
+ "prismaEnums",
1664
+ "schemaEnums",
1665
+ "models",
1666
+ "inputs",
1667
+ "args",
1668
+ "outputs"
1669
+ ];
1678
1670
  const blocksDependencyMap = {
1679
1671
  enums: ["schemaEnums", "prismaEnums"],
1680
1672
  models: ["models", "schemaEnums"],
@@ -1691,14 +1683,15 @@ function createEmitBlocks(data) {
1691
1683
  if (!Object.keys(blocksDependencyMap).includes(block)) continue;
1692
1684
  blocksToEmit = {
1693
1685
  ...blocksToEmit,
1694
- ...Object.fromEntries(blocksDependencyMap[block].map((block2) => [block2, true]))
1686
+ ...Object.fromEntries(
1687
+ blocksDependencyMap[block].map((block2) => [block2, true])
1688
+ )
1695
1689
  };
1696
1690
  }
1697
1691
  return blocksToEmit;
1698
1692
  }
1699
1693
 
1700
1694
  function createConfig(data) {
1701
- var _a;
1702
1695
  const config = lodash.merge({}, flat.unflatten(data, { delimiter: "_" }));
1703
1696
  const $warnings = [];
1704
1697
  const configOutputFilePattern = String(
@@ -1721,7 +1714,7 @@ function createConfig(data) {
1721
1714
  }
1722
1715
  const fields = Object.fromEntries(
1723
1716
  Object.entries(
1724
- (_a = config.fields) != null ? _a : {}
1717
+ config.fields ?? {}
1725
1718
  ).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
1726
1719
  const fieldSetting = {
1727
1720
  arguments: [],
@@ -1866,7 +1859,7 @@ function createGetModelName(modelNames) {
1866
1859
  }
1867
1860
  }
1868
1861
  function getModelName(args) {
1869
- const { name, modelNames } = args;
1862
+ const { modelNames, name } = args;
1870
1863
  for (const keyword of splitKeywords) {
1871
1864
  const [test] = name.split(keyword, 1);
1872
1865
  if (modelNames.includes(test)) {
@@ -1900,7 +1893,6 @@ function getModelName(args) {
1900
1893
  return test;
1901
1894
  }
1902
1895
  }
1903
- return undefined;
1904
1896
  }
1905
1897
  const splitKeywords = [
1906
1898
  "CreateInput",
@@ -1944,7 +1936,9 @@ const splitKeywords = [
1944
1936
  "MaxOrderBy",
1945
1937
  "AvgOrderBy",
1946
1938
  "Create",
1947
- "Update"
1939
+ "Update",
1940
+ "ScalarRelationFilter",
1941
+ "NullableScalarRelationFilter"
1948
1942
  ].sort((a, b) => b.length - a.length);
1949
1943
  const endsWithKeywords = [
1950
1944
  "Aggregate",
@@ -1973,6 +1967,7 @@ const middleKeywords = [
1973
1967
  ["FindOne", "Args"],
1974
1968
  ["FindUnique", "Args"],
1975
1969
  ["UpdateMany", "Args"],
1970
+ ["UpdateMany", "AndReturnOutputType"],
1976
1971
  ["UpdateOne", "Args"],
1977
1972
  ["UpsertOne", "Args"],
1978
1973
  ["GroupBy", "Args"],
@@ -1981,9 +1976,8 @@ const middleKeywords = [
1981
1976
 
1982
1977
  const AwaitEventEmitter = require$1("await-event-emitter").default;
1983
1978
  async function generate(args) {
1984
- var _a;
1985
1979
  const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
1986
- const generatorOutputValue = (_a = generator.output) == null ? undefined : _a.value;
1980
+ const generatorOutputValue = generator.output?.value;
1987
1981
  assert.ok(generatorOutputValue, "Missing generator configuration: output");
1988
1982
  const config = createConfig(generator.config);
1989
1983
  const eventEmitter = new AwaitEventEmitter();
package/generate.d.ts CHANGED
@@ -50,6 +50,7 @@ declare namespace DMMF {
50
50
  export type Model = ReadonlyDeep_2<{
51
51
  name: string;
52
52
  dbName: string | null;
53
+ schema: string | null;
53
54
  fields: Field[];
54
55
  uniqueFields: string[][];
55
56
  uniqueIndexes: uniqueIndex[];
@@ -75,6 +76,12 @@ declare namespace DMMF {
75
76
  * BigInt, Boolean, Bytes, DateTime, Decimal, Float, Int, JSON, String, $ModelName
76
77
  */
77
78
  type: string;
79
+ /**
80
+ * Native database type, if specified.
81
+ * For example, `@db.VarChar(191)` is encoded as `['VarChar', ['191']]`,
82
+ * `@db.Text` is encoded as `['Text', []]`.
83
+ */
84
+ nativeType?: [string, string[]] | null;
78
85
  dbName?: string | null;
79
86
  hasDefaultValue: boolean;
80
87
  default?: FieldDefault | FieldDefaultScalar | FieldDefaultScalar[];
@@ -86,7 +93,7 @@ declare namespace DMMF {
86
93
  }>;
87
94
  export type FieldDefault = ReadonlyDeep_2<{
88
95
  name: string;
89
- args: any[];
96
+ args: Array<string | number>;
90
97
  }>;
91
98
  export type FieldDefaultScalar = string | boolean | number;
92
99
  export type Index = ReadonlyDeep_2<{
@@ -200,6 +207,7 @@ declare namespace DMMF {
200
207
  createManyAndReturn?: string | null;
201
208
  update?: string | null;
202
209
  updateMany?: string | null;
210
+ updateManyAndReturn?: string | null;
203
211
  upsert?: string | null;
204
212
  delete?: string | null;
205
213
  deleteMany?: string | null;
@@ -220,6 +228,7 @@ declare namespace DMMF {
220
228
  createManyAndReturn = "createManyAndReturn",
221
229
  update = "update",
222
230
  updateMany = "updateMany",
231
+ updateManyAndReturn = "updateManyAndReturn",
223
232
  upsert = "upsert",
224
233
  delete = "delete",
225
234
  deleteMany = "deleteMany",
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "20.1.0",
3
+ "version": "21.0.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
  "bin": "bin.js",
7
- "repository": "https://github.com/unlight/nestjs-graphql-prisma.git",
8
- "bugs": {
9
- "url": "https://github.com/unlight/nestjs-graphql-prisma/issues"
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/unlight/prisma-nestjs-graphql.git"
10
10
  },
11
- "homepage": "https://github.com/unlight/nestjs-graphql-prisma#readme",
11
+ "homepage": "https://github.com/unlight/prisma-nestjs-graphql",
12
12
  "keywords": [
13
13
  "nestjs",
14
14
  "graphql",
@@ -62,14 +62,10 @@
62
62
  "config": {
63
63
  "commitizen": {
64
64
  "path": "node_modules/cz-customizable"
65
- },
66
- "ghooks": {
67
- "pre-commit": "precise-commits",
68
- "commit-msg": "sh Taskfile commit_lint"
69
65
  }
70
66
  },
71
67
  "dependencies": {
72
- "@prisma/generator-helper": "^5.14.0",
68
+ "@prisma/generator-helper": "5 - 6",
73
69
  "await-event-emitter": "^2.0.2",
74
70
  "filenamify": "4.X",
75
71
  "flat": "5.X",
@@ -77,75 +73,77 @@
77
73
  "graceful-fs": "^4.2.11",
78
74
  "json5": "^2.2.3",
79
75
  "lodash": "^4.17.21",
80
- "outmatch": "^0.7.0",
76
+ "outmatch": "^1.0.0",
81
77
  "pluralize": "^8.0.0",
82
78
  "pupa": "2.X",
83
- "ts-morph": ">=11 <=16"
79
+ "ts-morph": "11 - 16"
84
80
  },
85
81
  "devDependencies": {
86
- "@commitlint/cli": "^18.4.3",
87
- "@commitlint/config-conventional": "^18.4.3",
88
- "@nestjs/apollo": "^12.1.0",
89
- "@nestjs/common": "^10.3.8",
90
- "@nestjs/core": "^10.3.8",
91
- "@nestjs/graphql": "^12.1.1",
92
- "@nestjs/platform-express": "^10.3.8",
93
- "@paljs/plugins": "^6.0.7",
94
- "@prisma/client": "^5.14.0",
82
+ "@eslint/compat": "^1.2.5",
83
+ "@nestjs/apollo": "^13.0.1",
84
+ "@nestjs/common": "^11.0.1",
85
+ "@nestjs/core": "^11.0.1",
86
+ "@nestjs/graphql": "^13.0.1",
87
+ "@nestjs/platform-express": "^11.0.1",
88
+ "@paljs/plugins": "^8.1.0",
89
+ "@prisma/client": "5 - 6",
95
90
  "@semantic-release/changelog": "^6.0.3",
96
91
  "@semantic-release/git": "^10.0.1",
97
- "@semantic-release/github": "^9.2.5",
98
- "@swc/core": "^1.5.7",
99
- "@swc/helpers": "^0.5.11",
92
+ "@semantic-release/github": "^11.0.1",
93
+ "@swc/core": "^1.10.7",
94
+ "@swc/helpers": "^0.5.15",
100
95
  "@swc/register": "^0.1.10",
101
96
  "@types/flat": "^5.0.5",
102
97
  "@types/graceful-fs": "^4.1.9",
103
- "@types/lodash": "^4.17.4",
104
- "@types/mocha": "^10.0.6",
105
- "@types/node": "^20.12.12",
98
+ "@types/lodash": "^4.17.14",
99
+ "@types/mocha": "^10.0.10",
100
+ "@types/node": "^22.10.7",
106
101
  "@types/pluralize": "^0.0.33",
107
- "@typescript-eslint/eslint-plugin": "^6.14.0",
108
- "@typescript-eslint/parser": "^6.14.0",
102
+ "@typescript-eslint/eslint-plugin": "^8.20.0",
103
+ "@typescript-eslint/parser": "^8.20.0",
109
104
  "apollo-server-express": "^3.13.0",
110
- "c8": "^9.1.0",
105
+ "c8": "^10.1.3",
111
106
  "class-transformer": "^0.5.1",
112
107
  "class-validator": "^0.14.1",
113
- "commitizen": "^4.3.0",
114
- "cz-customizable": "^7.0.0",
108
+ "commitizen": "^4.3.1",
109
+ "conventional-changelog-conventionalcommits": "^8.0.0",
110
+ "cz-customizable": "^7.4.0",
115
111
  "decimal.js": "^10.4.3",
116
- "eslint": "^8.55.0",
112
+ "eslint": "^9.18.0",
113
+ "eslint-config-prettier": "^10.0.1",
117
114
  "eslint-import-resolver-node": "^0.3.9",
118
115
  "eslint-plugin-etc": "^2.0.3",
119
- "eslint-plugin-import": "^2.29.1",
116
+ "eslint-plugin-import": "^2.31.0",
120
117
  "eslint-plugin-only-warn": "^1.1.0",
121
- "eslint-plugin-prettier": "^5.1.3",
122
- "eslint-plugin-regexp": "^2.5.0",
123
- "eslint-plugin-simple-import-sort": "^10.0.0",
124
- "eslint-plugin-sort-class-members": "^1.20.0",
125
- "eslint-plugin-unicorn": "^53.0.0",
118
+ "eslint-plugin-perfectionist": "^4.6.0",
119
+ "eslint-plugin-prettier": "^5.2.2",
120
+ "eslint-plugin-regexp": "^2.7.0",
121
+ "eslint-plugin-simple-import-sort": "^12.1.1",
122
+ "eslint-plugin-sort-class-members": "^1.21.0",
123
+ "eslint-plugin-unicorn": "^56.0.1",
126
124
  "eslint-plugin-wix-editor": "^3.3.0",
127
125
  "expect": "^29.7.0",
128
- "git-branch-is": "^4.0.0",
129
- "graphql": "^16.8.1",
130
- "graphql-scalars": "^1.23.0",
126
+ "graphql": "^16.10.0",
127
+ "graphql-scalars": "^1.24.0",
131
128
  "graphql-type-json": "^0.3.2",
132
- "mocha": "^10.4.0",
129
+ "mocha": "^11.0.1",
133
130
  "ololog": "^1.1.175",
134
- "pkgroll": "^2.1.0",
131
+ "pkgroll": "^2.6.1",
135
132
  "precise-commits": "^1.0.2",
136
- "prettier": "^3.2.5",
137
- "prisma": "^5.14.0",
133
+ "prettier": "^3.4.2",
134
+ "prisma": "5 - 6",
138
135
  "prisma-graphql-type-decimal": "^3.0.0",
139
136
  "reflect-metadata": "^0.2.2",
140
137
  "request": "^2.88.2",
141
138
  "rxjs": "^7.8.1",
142
- "semantic-release": "^22.0.12",
139
+ "semantic-release": "^24.2.1",
143
140
  "simplytyped": "^3.3.0",
144
141
  "temp-dir": "2.X",
145
142
  "ts-node": "^10.9.2",
146
- "tslib": "^2.6.2",
147
- "type-fest": "^4.18.2",
148
- "typescript": "^5.4.5",
143
+ "tslib": "^2.8.1",
144
+ "type-fest": "^4.32.0",
145
+ "typescript": "^5.7.3",
146
+ "typescript-eslint": "^8.20.0",
149
147
  "watchexec-bin": "^1.0.0"
150
148
  }
151
149
  }