prisma-nestjs-graphql 20.1.0 → 21.0.1

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
@@ -389,7 +389,7 @@ export class Product {
389
389
  @Field(() => String, {
390
390
  description: 'Old description',
391
391
  deprecationReason: 'Use new name instead',
392
- complexity: 1
392
+ complexity: 1,
393
393
  })
394
394
  oldName: string;
395
395
  }
@@ -757,3 +757,9 @@ import { generate } from 'prisma-nestjs-graphql/generate';
757
757
  - JSON type for the code first approach - https://github.com/nestjs/graphql/issues/111#issuecomment-631452899
758
758
  - https://github.com/paljs/prisma-tools/tree/master/packages/plugins
759
759
  - https://github.com/wasp-lang/wasp
760
+
761
+ ## TODO
762
+
763
+ - keyof typeof SortOrder -> `SortOrder`
764
+ - dummy-createfriends.input.ts -> `create-friends`
765
+ - check 'TODO FIXME'
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 = [
@@ -184,7 +184,14 @@ function postBegin(args) {
184
184
  `${modelName}NullableRelationFilter`
185
185
  ]);
186
186
  }
187
- lodash.remove(inputTypes, (inputType) => isContainBogus(inputType.name));
187
+ for (const modelName of modelNames) {
188
+ replaceBogusFilters(`${modelName}ScalarRelationFilter`, [
189
+ `${modelName}NullableScalarRelationFilter`
190
+ ]);
191
+ }
192
+ lodash.remove(inputTypes, (inputType) => {
193
+ return isContainBogus(inputType.name);
194
+ });
188
195
  }
189
196
 
190
197
  function createAggregateInput(args) {
@@ -194,21 +201,18 @@ function createAggregateInput(args) {
194
201
  // eslint-disable-next-line unicorn/no-null
195
202
  constraints: { maxNumFields: null, minNumFields: null },
196
203
  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
- })
204
+ fields: outputType.fields.map((x) => ({
205
+ name: x.name,
206
+ isNullable: x.isNullable ?? true,
207
+ isRequired: false,
208
+ inputTypes: [
209
+ {
210
+ isList: false,
211
+ type: "true",
212
+ location: "scalar"
213
+ }
214
+ ]
215
+ }))
212
216
  };
213
217
  eventEmitter.emitSync("InputType", {
214
218
  ...args,
@@ -282,7 +286,6 @@ async function generateFiles(args) {
282
286
  const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
283
287
  const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", undefined, { overwrite: true });
284
288
  const statements = project.getSourceFiles().flatMap((s) => {
285
- var _a, _b;
286
289
  if (s === sourceFile) {
287
290
  return [];
288
291
  }
@@ -295,7 +298,7 @@ async function generateFiles(args) {
295
298
  }
296
299
  for (const property of statement.properties || []) {
297
300
  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();
301
+ const fullName = classDeclaration?.getProperty(property.name)?.getDecorator(decorator.name)?.getFullName();
299
302
  assert.ok(
300
303
  fullName,
301
304
  `Cannot get full name of decorator of class ${statement.name}`
@@ -526,7 +529,7 @@ function getGraphqlInputType(inputTypes, pattern) {
526
529
  }
527
530
 
528
531
  function getPropertyType(args) {
529
- const { type, location } = args;
532
+ const { location, type } = args;
530
533
  switch (type) {
531
534
  case "Float":
532
535
  case "Int": {
@@ -551,7 +554,7 @@ function getPropertyType(args) {
551
554
  return ["null"];
552
555
  }
553
556
  case "Bytes": {
554
- return ["Buffer"];
557
+ return ["Uint8Array"];
555
558
  }
556
559
  case "BigInt": {
557
560
  return ["bigint", "number"];
@@ -602,15 +605,14 @@ function propertyStructure(args) {
602
605
  kind: tsMorph.StructureKind.Property,
603
606
  name,
604
607
  type,
605
- hasQuestionToken: hasQuestionToken != null ? hasQuestionToken : isNullable,
606
- hasExclamationToken: hasExclamationToken != null ? hasExclamationToken : !isNullable,
608
+ hasQuestionToken: hasQuestionToken ?? isNullable,
609
+ hasExclamationToken: hasExclamationToken ?? !isNullable,
607
610
  decorators: [],
608
611
  leadingTrivia: "\n"
609
612
  };
610
613
  }
611
614
 
612
615
  function inputType(args) {
613
- var _a, _b, _c, _d;
614
616
  const {
615
617
  classDecoratorName,
616
618
  classTransformerTypeModels,
@@ -665,27 +667,27 @@ function inputType(args) {
665
667
  if (inputTypes.length === 0) {
666
668
  continue;
667
669
  }
668
- const usePattern = (useInputType == null ? undefined : useInputType.ALL) || (useInputType == null ? undefined : useInputType[name]);
670
+ const usePattern = useInputType?.ALL || useInputType?.[name];
669
671
  const graphqlInputType = getGraphqlInputType(inputTypes, usePattern);
670
672
  const { isList, location, type } = graphqlInputType;
671
673
  const typeName = String(type);
672
- const settings = modelFieldSettings == null ? undefined : modelFieldSettings.get(name);
673
- const propertySettings = settings == null ? undefined : settings.getPropertyType({
674
+ const settings = modelFieldSettings?.get(name);
675
+ const propertySettings = settings?.getPropertyType({
674
676
  name: inputType2.name,
675
677
  input: true
676
678
  });
677
- const modelField = model == null ? undefined : model.fields.find((f) => f.name === name);
678
- const isCustomsApplicable = typeName === (modelField == null ? undefined : modelField.type);
679
+ const modelField = model?.fields.find((f) => f.name === name);
680
+ const isCustomsApplicable = typeName === modelField?.type;
679
681
  const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
680
682
  const whereUniqueInputType = isWhereUniqueInputType(typeName) && atLeastKeys && `Prisma.AtLeast<${typeName}, ${atLeastKeys.map((name2) => `'${name2}'`).join(" | ")}>`;
681
683
  const propertyType = lodash.castArray(
682
- (propertySettings == null ? undefined : propertySettings.name) || whereUniqueInputType || getPropertyType({
684
+ propertySettings?.name || whereUniqueInputType || getPropertyType({
683
685
  location,
684
686
  type: typeName
685
687
  })
686
688
  );
687
689
  const hasExclamationToken = Boolean(
688
- isWhereUnique && config.unsafeCompatibleWhereUniqueInput && (atLeastKeys == null ? undefined : atLeastKeys.includes(name))
690
+ isWhereUnique && config.unsafeCompatibleWhereUniqueInput && atLeastKeys?.includes(name)
689
691
  );
690
692
  const property = propertyStructure({
691
693
  name,
@@ -704,13 +706,13 @@ function inputType(args) {
704
706
  importDeclarations.add("Prisma", config.prismaClientImport);
705
707
  }
706
708
  let graphqlType;
707
- const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
709
+ const shouldHideField = settings?.shouldHideField({
708
710
  name: inputType2.name,
709
711
  input: true
710
- })) || config.decorate.some(
712
+ }) || config.decorate.some(
711
713
  (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputType2.name)
712
714
  );
713
- const fieldType = settings == null ? undefined : settings.getFieldType({
715
+ const fieldType = settings?.getFieldType({
714
716
  name: inputType2.name,
715
717
  input: true
716
718
  });
@@ -747,7 +749,7 @@ function inputType(args) {
747
749
  arguments: [
748
750
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
749
751
  JSON5.stringify({
750
- ...settings == null ? undefined : settings.fieldArguments(),
752
+ ...settings?.fieldArguments(),
751
753
  nullable: !isRequired
752
754
  })
753
755
  ]
@@ -766,7 +768,7 @@ function inputType(args) {
766
768
  arguments: ["transformToDecimal"]
767
769
  }
768
770
  );
769
- } else if (location === "inputObjectTypes" && ((modelField == null ? undefined : modelField.type) === "Decimal" || [
771
+ } else if (location === "inputObjectTypes" && (modelField?.type === "Decimal" || [
770
772
  "connect",
771
773
  "connectOrCreate",
772
774
  "create",
@@ -780,15 +782,15 @@ function inputType(args) {
780
782
  "updateMany",
781
783
  "upsert",
782
784
  "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(
785
+ ].includes(name) || classTransformerTypeModels.has(getModelName(graphqlType) || "") || modelField?.kind === "object" && models.get(modelField.type) && models.get(modelField.type)?.fields.some(
784
786
  (field2) => field2.kind === "object" && classTransformerTypeModels.has(field2.type)
785
- )))) {
787
+ ))) {
786
788
  importDeclarations.add("Type", "class-transformer");
787
789
  property.decorators.push({ name: "Type", arguments: [`() => ${graphqlType}`] });
788
790
  }
789
791
  if (isCustomsApplicable) {
790
792
  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) {
793
+ if ((options.kind === "Decorator" && options.input && options.match?.(name)) ?? true) {
792
794
  property.decorators.push({
793
795
  name: options.name,
794
796
  arguments: options.arguments
@@ -802,7 +804,7 @@ function inputType(args) {
802
804
  if (decorate.isMatchField(name) && decorate.isMatchType(inputType2.name)) {
803
805
  property.decorators.push({
804
806
  name: decorate.name,
805
- arguments: (_d = decorate.arguments) == null ? undefined : _d.map((x) => pupa(x, { propertyType }))
807
+ arguments: decorate.arguments?.map((x) => pupa(x, { propertyType }))
806
808
  });
807
809
  importDeclarations.create(decorate);
808
810
  }
@@ -825,10 +827,9 @@ class ObjectSettings extends Array {
825
827
  input = false,
826
828
  output = false
827
829
  }) {
828
- var _a;
829
830
  const hideField = this.find((s) => s.name === "HideField");
830
831
  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))
832
+ hideField?.input && input || hideField?.output && output || hideField?.match?.(name)
832
833
  );
833
834
  }
834
835
  getFieldType({
@@ -930,7 +931,6 @@ function createSettingElement({
930
931
  fieldElement,
931
932
  match
932
933
  }) {
933
- var _a, _b, _c, _d, _e;
934
934
  const result = {
935
935
  documentLine: "",
936
936
  element: undefined
@@ -947,7 +947,7 @@ function createSettingElement({
947
947
  result.element = fieldElement;
948
948
  return result;
949
949
  }
950
- const name = (_a = match == null ? undefined : match.groups) == null ? undefined : _a.name;
950
+ const name = match?.groups?.name;
951
951
  if (!(match && name)) {
952
952
  result.documentLine = line;
953
953
  return result;
@@ -966,14 +966,14 @@ function createSettingElement({
966
966
  Object.assign(element, hideFieldDecorator(match));
967
967
  return result;
968
968
  }
969
- if (["FieldType", "PropertyType"].includes(name) && ((_b = match.groups) == null ? undefined : _b.args)) {
969
+ if (["FieldType", "PropertyType"].includes(name) && match.groups?.args) {
970
970
  const options2 = customType(match.groups.args);
971
971
  lodash.merge(element, options2.namespace && config.fields[options2.namespace], options2, {
972
972
  kind: name
973
973
  });
974
974
  return result;
975
975
  }
976
- if (name === "ObjectType" && ((_c = match.groups) == null ? undefined : _c.args)) {
976
+ if (name === "ObjectType" && match.groups?.args) {
977
977
  element.kind = "ObjectType";
978
978
  const options2 = customType(match.groups.args);
979
979
  if (typeof options2[0] === "string" && options2[0]) {
@@ -988,7 +988,7 @@ function createSettingElement({
988
988
  };
989
989
  return result;
990
990
  }
991
- if (name === "Directive" && ((_d = match.groups) == null ? undefined : _d.args)) {
991
+ if (name === "Directive" && match.groups?.args) {
992
992
  const options2 = customType(match.groups.args);
993
993
  lodash.merge(element, { model: true, from: "@nestjs/graphql" }, options2, {
994
994
  name,
@@ -1002,13 +1002,12 @@ function createSettingElement({
1002
1002
  element.namespaceImport = namespace;
1003
1003
  const options = {
1004
1004
  name,
1005
- arguments: (((_e = match.groups) == null ? undefined : _e.args) || "").split(",").map((s) => lodash.trim(s)).filter(Boolean)
1005
+ arguments: (match.groups?.args || "").split(",").map((s) => lodash.trim(s)).filter(Boolean)
1006
1006
  };
1007
1007
  lodash.merge(element, namespace && config.fields[namespace], options);
1008
1008
  return result;
1009
1009
  }
1010
1010
  function customType(args) {
1011
- var _a;
1012
1011
  const result = {};
1013
1012
  let options = parseArgs(args);
1014
1013
  if (typeof options === "string") {
@@ -1017,7 +1016,7 @@ function customType(args) {
1017
1016
  Object.assign(result, options);
1018
1017
  const namespace = getNamespace(options.name);
1019
1018
  result.namespace = namespace;
1020
- if ((_a = options.name) == null ? undefined : _a.includes(".")) {
1019
+ if (options.name?.includes(".")) {
1021
1020
  result.namespaceImport = namespace;
1022
1021
  }
1023
1022
  if (typeof options.match === "string" || Array.isArray(options.match)) {
@@ -1026,7 +1025,6 @@ function customType(args) {
1026
1025
  return result;
1027
1026
  }
1028
1027
  function hideFieldDecorator(match) {
1029
- var _a;
1030
1028
  const result = {
1031
1029
  name: "HideField",
1032
1030
  arguments: [],
@@ -1035,7 +1033,7 @@ function hideFieldDecorator(match) {
1035
1033
  namespaceImport: undefined,
1036
1034
  match: undefined
1037
1035
  };
1038
- if (!((_a = match.groups) == null ? undefined : _a.args)) {
1036
+ if (!match.groups?.args) {
1039
1037
  result.output = true;
1040
1038
  return result;
1041
1039
  }
@@ -1110,13 +1108,12 @@ function modelData(model, args) {
1110
1108
  }
1111
1109
 
1112
1110
  function createComment(documentation, settings) {
1113
- var _a;
1114
1111
  const documentationLines = documentation.split("\n");
1115
1112
  const commentLines = ["/**"];
1116
1113
  for (const line of documentationLines) {
1117
1114
  commentLines.push(` * ${line}`);
1118
1115
  }
1119
- const deprecationReason = (_a = settings == null ? undefined : settings.fieldArguments()) == null ? undefined : _a.deprecationReason;
1116
+ const deprecationReason = settings?.fieldArguments()?.deprecationReason;
1120
1117
  if (deprecationReason) {
1121
1118
  commentLines.push(` * @deprecated ${deprecationReason}`);
1122
1119
  }
@@ -1130,9 +1127,8 @@ function getOutputTypeName(name) {
1130
1127
 
1131
1128
  const nestjsGraphql$1 = "@nestjs/graphql";
1132
1129
  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;
1130
+ const { config, eventEmitter, fieldSettings, getSourceFile, modelFields, models } = args;
1131
+ if (isManyAndReturnOutputType(outputType.name)) return;
1136
1132
  const model = models.get(outputType.name);
1137
1133
  assert.ok(model, `Cannot find model by name ${outputType.name}`);
1138
1134
  const sourceFile = getSourceFile({
@@ -1146,15 +1142,15 @@ function modelOutputType(outputType, args) {
1146
1142
  );
1147
1143
  const importDeclarations = new ImportDeclarationMap();
1148
1144
  const classStructure = {
1149
- kind: tsMorph.StructureKind.Class,
1150
- isExported: true,
1151
- name: outputType.name,
1152
1145
  decorators: [
1153
1146
  {
1154
- name: "ObjectType",
1155
- arguments: []
1147
+ arguments: [],
1148
+ name: "ObjectType"
1156
1149
  }
1157
1150
  ],
1151
+ isExported: true,
1152
+ kind: tsMorph.StructureKind.Class,
1153
+ name: outputType.name,
1158
1154
  properties: []
1159
1155
  };
1160
1156
  sourceFileStructure.statements.push(classStructure);
@@ -1165,8 +1161,8 @@ function modelOutputType(outputType, args) {
1165
1161
  if (model.documentation) {
1166
1162
  const objectTypeOptions = {};
1167
1163
  const { documentation, settings } = createObjectSettings({
1168
- text: model.documentation,
1169
- config
1164
+ config,
1165
+ text: model.documentation
1170
1166
  });
1171
1167
  if (documentation) {
1172
1168
  if (!classStructure.leadingTrivia) {
@@ -1182,24 +1178,24 @@ function modelOutputType(outputType, args) {
1182
1178
  for (const field of outputType.fields) {
1183
1179
  if (config.omitModelsCount && field.name === "_count") continue;
1184
1180
  let fileType = "model";
1185
- const { location, isList, type, namespace } = field.outputType;
1181
+ const { isList, location, namespace, type } = field.outputType;
1186
1182
  let outputTypeName = String(type);
1187
1183
  if (namespace !== "model") {
1188
1184
  fileType = "output";
1189
1185
  outputTypeName = getOutputTypeName(outputTypeName);
1190
1186
  }
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({
1187
+ const modelField = modelFields.get(model.name)?.get(field.name);
1188
+ const settings = fieldSettings.get(model.name)?.get(field.name);
1189
+ const fieldType = settings?.getFieldType({
1194
1190
  name: outputType.name,
1195
1191
  output: true
1196
1192
  });
1197
- const propertySettings = settings == null ? undefined : settings.getPropertyType({
1193
+ const propertySettings = settings?.getPropertyType({
1198
1194
  name: outputType.name,
1199
1195
  output: true
1200
1196
  });
1201
1197
  const propertyType = lodash.castArray(
1202
- (propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
1198
+ propertySettings?.name || getPropertyType({
1203
1199
  location,
1204
1200
  type: outputTypeName
1205
1201
  })
@@ -1215,13 +1211,13 @@ function modelOutputType(outputType, args) {
1215
1211
  } else {
1216
1212
  const graphqlImport = getGraphqlImport({
1217
1213
  config,
1218
- sourceFile,
1219
1214
  fileType,
1215
+ getSourceFile,
1216
+ isId: modelField?.isId,
1220
1217
  location,
1221
- isId: modelField == null ? undefined : modelField.isId,
1222
1218
  noTypeId: config.noTypeId,
1223
- typeName: outputTypeName,
1224
- getSourceFile
1219
+ sourceFile,
1220
+ typeName: outputTypeName
1225
1221
  });
1226
1222
  graphqlType = graphqlImport.name;
1227
1223
  if (graphqlImport.name !== outputType.name && graphqlImport.specifier) {
@@ -1229,49 +1225,49 @@ function modelOutputType(outputType, args) {
1229
1225
  }
1230
1226
  }
1231
1227
  const property = propertyStructure({
1232
- name: field.name,
1233
- isNullable: field.isNullable,
1234
1228
  hasExclamationToken: true,
1235
1229
  hasQuestionToken: location === "outputObjectTypes",
1236
- propertyType,
1237
- isList
1230
+ isList,
1231
+ isNullable: field.isNullable,
1232
+ name: field.name,
1233
+ propertyType
1238
1234
  });
1239
- if (typeof property.leadingTrivia === "string" && (modelField == null ? undefined : modelField.documentation)) {
1235
+ if (typeof property.leadingTrivia === "string" && modelField?.documentation) {
1240
1236
  property.leadingTrivia += createComment(modelField.documentation, settings);
1241
1237
  }
1242
- (_c = classStructure.properties) == null ? undefined : _c.push(property);
1238
+ classStructure.properties?.push(property);
1243
1239
  if (propertySettings) {
1244
1240
  importDeclarations.create({ ...propertySettings });
1245
1241
  } else if (propertyType.includes("Decimal")) {
1246
1242
  importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
1247
1243
  }
1248
1244
  assert.ok(property.decorators, "property.decorators is undefined");
1249
- const shouldHideField = (settings == null ? undefined : settings.shouldHideField({ name: outputType.name, output: true })) || config.decorate.some(
1245
+ const shouldHideField = settings?.shouldHideField({ name: outputType.name, output: true }) || config.decorate.some(
1250
1246
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1251
1247
  );
1252
1248
  if (shouldHideField) {
1253
1249
  importDeclarations.add("HideField", nestjsGraphql$1);
1254
- property.decorators.push({ name: "HideField", arguments: [] });
1250
+ property.decorators.push({ arguments: [], name: "HideField" });
1255
1251
  } else {
1256
1252
  property.decorators.push({
1257
- name: "Field",
1258
1253
  arguments: [
1259
1254
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1260
1255
  JSON5.stringify({
1261
- ...settings == null ? undefined : settings.fieldArguments(),
1262
- nullable: Boolean(field.isNullable),
1256
+ ...settings?.fieldArguments(),
1263
1257
  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
1258
+ typeof modelField?.default
1259
+ ) ? modelField?.default : undefined,
1260
+ description: modelField?.documentation,
1261
+ nullable: Boolean(field.isNullable)
1267
1262
  })
1268
- ]
1263
+ ],
1264
+ name: "Field"
1269
1265
  });
1270
1266
  for (const setting of settings || []) {
1271
- if (shouldBeDecorated(setting) && ((_e = (_d = setting.match) == null ? undefined : _d.call(setting, field.name)) != null ? _e : true)) {
1267
+ if (shouldBeDecorated(setting) && (setting.match?.(field.name) ?? true)) {
1272
1268
  property.decorators.push({
1273
- name: setting.name,
1274
- arguments: setting.arguments
1269
+ arguments: setting.arguments,
1270
+ name: setting.name
1275
1271
  });
1276
1272
  assert.ok(setting.from, "Missed 'from' part in configuration or field setting");
1277
1273
  importDeclarations.create(setting);
@@ -1280,24 +1276,24 @@ function modelOutputType(outputType, args) {
1280
1276
  for (const decorate of config.decorate) {
1281
1277
  if (decorate.isMatchField(field.name) && decorate.isMatchType(outputTypeName)) {
1282
1278
  property.decorators.push({
1283
- name: decorate.name,
1284
- arguments: (_f = decorate.arguments) == null ? undefined : _f.map((x) => pupa(x, { propertyType }))
1279
+ arguments: decorate.arguments?.map((x) => pupa(x, { propertyType })),
1280
+ name: decorate.name
1285
1281
  });
1286
1282
  importDeclarations.create(decorate);
1287
1283
  }
1288
1284
  }
1289
1285
  }
1290
1286
  eventEmitter.emitSync("ClassProperty", property, {
1291
- location,
1292
1287
  isList,
1288
+ location,
1293
1289
  propertyType
1294
1290
  });
1295
1291
  }
1296
1292
  for (const setting of modelSettings || []) {
1297
1293
  if (shouldBeDecorated(setting)) {
1298
1294
  classStructure.decorators.push({
1299
- name: setting.name,
1300
- arguments: setting.arguments
1295
+ arguments: setting.arguments,
1296
+ name: setting.name
1301
1297
  });
1302
1298
  importDeclarations.create(setting);
1303
1299
  }
@@ -1346,10 +1342,9 @@ function beforeInputType$1(args) {
1346
1342
  }
1347
1343
  }
1348
1344
  function beforeGenerateFiles$1(args) {
1349
- var _a;
1350
1345
  const { project } = args;
1351
1346
  for (const sourceFile of project.getSourceFiles()) {
1352
- const className = (_a = sourceFile.getClass(() => true)) == null ? undefined : _a.getName();
1347
+ const className = sourceFile.getClass(() => true)?.getName();
1353
1348
  if (className && isAtomicOperation(className)) {
1354
1349
  project.removeSourceFile(sourceFile);
1355
1350
  }
@@ -1367,14 +1362,13 @@ function isListInput(typeName, model, field) {
1367
1362
 
1368
1363
  const nestjsGraphql = "@nestjs/graphql";
1369
1364
  function outputType(outputType2, args) {
1370
- var _a, _b, _c, _d, _e;
1371
1365
  const { getSourceFile, models, eventEmitter, fieldSettings, getModelName, config } = args;
1372
1366
  const importDeclarations = new ImportDeclarationMap();
1373
1367
  const fileType = "output";
1374
1368
  const modelName = getModelName(outputType2.name) || "";
1375
1369
  const model = models.get(modelName);
1376
1370
  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`;
1371
+ const isCountOutput = model?.name && outputType2.name === `${model.name}CountOutputType`;
1378
1372
  if (!config.emitBlocks.outputs && !isCountOutput) return;
1379
1373
  outputType2.name = getOutputTypeName(outputType2.name);
1380
1374
  if (isAggregateOutput) {
@@ -1401,15 +1395,15 @@ function outputType(outputType2, args) {
1401
1395
  for (const field of outputType2.fields) {
1402
1396
  const { location, isList, type } = field.outputType;
1403
1397
  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({
1398
+ const settings = isCountOutput ? undefined : model && fieldSettings.get(model.name)?.get(field.name);
1399
+ const propertySettings = settings?.getPropertyType({
1406
1400
  name: outputType2.name,
1407
1401
  output: true
1408
1402
  });
1409
- const isCustomsApplicable = outputTypeName === ((_b = model == null ? undefined : model.fields.find((f) => f.name === field.name)) == null ? undefined : _b.type);
1403
+ const isCustomsApplicable = outputTypeName === model?.fields.find((f) => f.name === field.name)?.type;
1410
1404
  field.outputType.type = outputTypeName;
1411
1405
  const propertyType = lodash.castArray(
1412
- (propertySettings == null ? undefined : propertySettings.name) || getPropertyType({
1406
+ propertySettings?.name || getPropertyType({
1413
1407
  location,
1414
1408
  type: outputTypeName
1415
1409
  })
@@ -1421,20 +1415,20 @@ function outputType(outputType2, args) {
1421
1415
  propertyType,
1422
1416
  isList
1423
1417
  });
1424
- (_c = classStructure.properties) == null ? undefined : _c.push(property);
1418
+ classStructure.properties?.push(property);
1425
1419
  if (propertySettings) {
1426
1420
  importDeclarations.create({ ...propertySettings });
1427
1421
  } else if (propertyType.includes("Decimal")) {
1428
1422
  importDeclarations.add("Decimal", `${config.prismaClientImport}/runtime/library`);
1429
1423
  }
1430
1424
  let graphqlType;
1431
- const shouldHideField = (settings == null ? undefined : settings.shouldHideField({
1425
+ const shouldHideField = settings?.shouldHideField({
1432
1426
  name: outputType2.name,
1433
1427
  output: true
1434
- })) || config.decorate.some(
1428
+ }) || config.decorate.some(
1435
1429
  (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(field.name) && d.isMatchType(outputTypeName)
1436
1430
  );
1437
- const fieldType = settings == null ? undefined : settings.getFieldType({
1431
+ const fieldType = settings?.getFieldType({
1438
1432
  name: outputType2.name,
1439
1433
  output: true
1440
1434
  });
@@ -1473,14 +1467,14 @@ function outputType(outputType2, args) {
1473
1467
  arguments: [
1474
1468
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1475
1469
  JSON5.stringify({
1476
- ...settings == null ? undefined : settings.fieldArguments(),
1470
+ ...settings?.fieldArguments(),
1477
1471
  nullable: Boolean(field.isNullable)
1478
1472
  })
1479
1473
  ]
1480
1474
  });
1481
1475
  if (isCustomsApplicable) {
1482
1476
  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) {
1477
+ if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
1484
1478
  property.decorators.push({
1485
1479
  name: options.name,
1486
1480
  arguments: options.arguments
@@ -1507,8 +1501,7 @@ function purgeOutput(emitter) {
1507
1501
  emitter.on("End", end);
1508
1502
  }
1509
1503
  function begin({ project, output }) {
1510
- var _a;
1511
- const sourceFiles = (_a = project.getDirectory(output)) == null ? undefined : _a.getDescendantSourceFiles();
1504
+ const sourceFiles = project.getDirectory(output)?.getDescendantSourceFiles();
1512
1505
  if (sourceFiles) {
1513
1506
  for (const sourceFile of sourceFiles) {
1514
1507
  sourceFile.delete();
@@ -1516,8 +1509,7 @@ function begin({ project, output }) {
1516
1509
  }
1517
1510
  }
1518
1511
  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());
1512
+ const directories = project.getDirectory(output)?.getDescendantDirectories().filter((directory) => directory.getSourceFiles().length === 0).map((directory) => directory.getPath());
1521
1513
  for (const directory of directories || []) {
1522
1514
  try {
1523
1515
  gracefulFs.rmdirSync(directory);
@@ -1646,7 +1638,7 @@ function registerEnum(enumType, args) {
1646
1638
  ...importDeclarations.toStatements(),
1647
1639
  enumStructure,
1648
1640
  "\n",
1649
- `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum == null ? undefined : dataModelEnum.documentation)} })`
1641
+ `registerEnumType(${enumType.name}, { name: '${enumType.name}', description: ${JSON.stringify(dataModelEnum?.documentation)} })`
1650
1642
  ]
1651
1643
  });
1652
1644
  }
@@ -1674,7 +1666,14 @@ function warning(message) {
1674
1666
  }
1675
1667
  }
1676
1668
 
1677
- const allEmmittedBlocks = ["prismaEnums", "schemaEnums", "models", "inputs", "args", "outputs"];
1669
+ const allEmmittedBlocks = [
1670
+ "prismaEnums",
1671
+ "schemaEnums",
1672
+ "models",
1673
+ "inputs",
1674
+ "args",
1675
+ "outputs"
1676
+ ];
1678
1677
  const blocksDependencyMap = {
1679
1678
  enums: ["schemaEnums", "prismaEnums"],
1680
1679
  models: ["models", "schemaEnums"],
@@ -1691,14 +1690,15 @@ function createEmitBlocks(data) {
1691
1690
  if (!Object.keys(blocksDependencyMap).includes(block)) continue;
1692
1691
  blocksToEmit = {
1693
1692
  ...blocksToEmit,
1694
- ...Object.fromEntries(blocksDependencyMap[block].map((block2) => [block2, true]))
1693
+ ...Object.fromEntries(
1694
+ blocksDependencyMap[block].map((block2) => [block2, true])
1695
+ )
1695
1696
  };
1696
1697
  }
1697
1698
  return blocksToEmit;
1698
1699
  }
1699
1700
 
1700
1701
  function createConfig(data) {
1701
- var _a;
1702
1702
  const config = lodash.merge({}, flat.unflatten(data, { delimiter: "_" }));
1703
1703
  const $warnings = [];
1704
1704
  const configOutputFilePattern = String(
@@ -1721,7 +1721,7 @@ function createConfig(data) {
1721
1721
  }
1722
1722
  const fields = Object.fromEntries(
1723
1723
  Object.entries(
1724
- (_a = config.fields) != null ? _a : {}
1724
+ config.fields ?? {}
1725
1725
  ).filter(({ 1: value }) => typeof value === "object").map(([name, value]) => {
1726
1726
  const fieldSetting = {
1727
1727
  arguments: [],
@@ -1866,7 +1866,7 @@ function createGetModelName(modelNames) {
1866
1866
  }
1867
1867
  }
1868
1868
  function getModelName(args) {
1869
- const { name, modelNames } = args;
1869
+ const { modelNames, name } = args;
1870
1870
  for (const keyword of splitKeywords) {
1871
1871
  const [test] = name.split(keyword, 1);
1872
1872
  if (modelNames.includes(test)) {
@@ -1900,7 +1900,6 @@ function getModelName(args) {
1900
1900
  return test;
1901
1901
  }
1902
1902
  }
1903
- return undefined;
1904
1903
  }
1905
1904
  const splitKeywords = [
1906
1905
  "CreateInput",
@@ -1944,7 +1943,9 @@ const splitKeywords = [
1944
1943
  "MaxOrderBy",
1945
1944
  "AvgOrderBy",
1946
1945
  "Create",
1947
- "Update"
1946
+ "Update",
1947
+ "ScalarRelationFilter",
1948
+ "NullableScalarRelationFilter"
1948
1949
  ].sort((a, b) => b.length - a.length);
1949
1950
  const endsWithKeywords = [
1950
1951
  "Aggregate",
@@ -1973,6 +1974,7 @@ const middleKeywords = [
1973
1974
  ["FindOne", "Args"],
1974
1975
  ["FindUnique", "Args"],
1975
1976
  ["UpdateMany", "Args"],
1977
+ ["UpdateMany", "AndReturnOutputType"],
1976
1978
  ["UpdateOne", "Args"],
1977
1979
  ["UpsertOne", "Args"],
1978
1980
  ["GroupBy", "Args"],
@@ -1981,9 +1983,8 @@ const middleKeywords = [
1981
1983
 
1982
1984
  const AwaitEventEmitter = require$1("await-event-emitter").default;
1983
1985
  async function generate(args) {
1984
- var _a;
1985
1986
  const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
1986
- const generatorOutputValue = (_a = generator.output) == null ? undefined : _a.value;
1987
+ const generatorOutputValue = generator.output?.value;
1987
1988
  assert.ok(generatorOutputValue, "Missing generator configuration: output");
1988
1989
  const config = createConfig(generator.config);
1989
1990
  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.1",
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
  }