prisma-nestjs-graphql 19.1.0 → 19.2.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
@@ -145,6 +145,13 @@ Type: `boolean`
145
145
  Default: `false`
146
146
  **Note**: It will break compatiblity between Prisma types and generated classes.
147
147
 
148
+ #### `unsafeCompatibleWhereUniqueInput`
149
+
150
+ This trick TypeScript and set property as non optional for all fields in `*WhereUniqueInput` classes.
151
+ See [#177](https://github.com/unlight/prisma-nestjs-graphql/issues/177) for more details.
152
+ Type: `boolean`
153
+ Default: `false`
154
+
148
155
  #### `useInputType`
149
156
 
150
157
  Since GraphQL does not support input union type, this setting map
package/generate.cjs CHANGED
@@ -86,9 +86,11 @@ function argsType(field, args) {
86
86
  });
87
87
  }
88
88
 
89
+ const BeforeGenerateField = "BeforeGenerateField";
90
+
89
91
  function combineScalarFilters(eventEmitter) {
90
92
  eventEmitter.on("BeforeInputType", beforeInputType$2);
91
- eventEmitter.on("BeforeGenerateField", beforeGenerateField);
93
+ eventEmitter.on(BeforeGenerateField, beforeGenerateField);
92
94
  eventEmitter.on("PostBegin", postBegin);
93
95
  }
94
96
  function beforeInputType$2(args) {
@@ -571,7 +573,7 @@ function getWhereUniqueAtLeastKeys(model) {
571
573
  for (const uniqueIndex of model.uniqueIndexes) {
572
574
  names.push(createFieldName(uniqueIndex));
573
575
  }
574
- return names.map((name) => `'${name}'`).join(" | ");
576
+ return names;
575
577
  }
576
578
  function createFieldName(args) {
577
579
  const { name, fields } = args;
@@ -651,9 +653,10 @@ function inputType(args) {
651
653
  const useInputType = config.useInputType.find(
652
654
  (x) => inputType2.name.includes(x.typeName)
653
655
  );
656
+ const isWhereUnique = isWhereUniqueInputType(inputType2.name);
654
657
  for (const field of inputType2.fields) {
655
658
  field.inputTypes = field.inputTypes.filter((t) => !removeTypes.has(String(t.type)));
656
- eventEmitter.emitSync("BeforeGenerateField", field, args);
659
+ eventEmitter.emitSync(BeforeGenerateField, field, args);
657
660
  const { inputTypes, isRequired, name } = field;
658
661
  if (inputTypes.length === 0) {
659
662
  continue;
@@ -669,16 +672,22 @@ function inputType(args) {
669
672
  });
670
673
  const modelField = model == null ? void 0 : model.fields.find((f) => f.name === name);
671
674
  const isCustomsApplicable = typeName === (modelField == null ? void 0 : modelField.type);
672
- const whereUniqueInputType = isWhereUniqueInputType(typeName) && model && `Prisma.AtLeast<${typeName}, ${getWhereUniqueAtLeastKeys(model)}>`;
675
+ const atLeastKeys = model && getWhereUniqueAtLeastKeys(model);
676
+ const whereUniqueInputType = isWhereUniqueInputType(typeName) && atLeastKeys && `Prisma.AtLeast<${typeName}, ${atLeastKeys.map((name2) => `'${name2}'`).join(" | ")}>`;
673
677
  const propertyType = lodash.castArray(
674
678
  (propertySettings == null ? void 0 : propertySettings.name) || whereUniqueInputType || getPropertyType({
675
679
  location,
676
680
  type: typeName
677
681
  })
678
682
  );
683
+ const hasExclamationToken = Boolean(
684
+ isWhereUnique && config.unsafeCompatibleWhereUniqueInput && (atLeastKeys == null ? void 0 : atLeastKeys.includes(name))
685
+ );
679
686
  const property = propertyStructure({
680
687
  name,
681
688
  isNullable: !isRequired,
689
+ hasExclamationToken: hasExclamationToken || void 0,
690
+ hasQuestionToken: hasExclamationToken ? false : void 0,
682
691
  propertyType,
683
692
  isList
684
693
  });
@@ -695,7 +704,7 @@ function inputType(args) {
695
704
  name: inputType2.name,
696
705
  input: true
697
706
  })) || config.decorate.some(
698
- (d) => d.name === "HideField" && d.from === "@nestjs/graphql" && d.isMatchField(name) && d.isMatchType(inputType2.name)
707
+ (d) => d.name === "HideField" && d.from === moduleSpecifier && d.isMatchField(name) && d.isMatchType(inputType2.name)
699
708
  );
700
709
  const fieldType = settings == null ? void 0 : settings.getFieldType({
701
710
  name: inputType2.name,
@@ -726,7 +735,7 @@ function inputType(args) {
726
735
  }
727
736
  assert.ok(property.decorators, "property.decorators is undefined");
728
737
  if (shouldHideField) {
729
- importDeclarations.add("HideField", "@nestjs/graphql");
738
+ importDeclarations.add("HideField", moduleSpecifier);
730
739
  property.decorators.push({ name: "HideField", arguments: [] });
731
740
  } else {
732
741
  property.decorators.push({
@@ -1757,6 +1766,9 @@ function createConfig(data) {
1757
1766
  requireSingleFieldsInWhereUniqueInput: toBoolean(
1758
1767
  config.requireSingleFieldsInWhereUniqueInput
1759
1768
  ),
1769
+ unsafeCompatibleWhereUniqueInput: toBoolean(
1770
+ config.unsafeCompatibleWhereUniqueInput
1771
+ ),
1760
1772
  graphqlScalars: config.graphqlScalars || {},
1761
1773
  decorate
1762
1774
  };
package/generate.d.ts CHANGED
@@ -243,6 +243,7 @@ declare function createConfig(data: Record<string, unknown>): {
243
243
  useInputType: ConfigInputItem[];
244
244
  noTypeId: boolean;
245
245
  requireSingleFieldsInWhereUniqueInput: boolean;
246
+ unsafeCompatibleWhereUniqueInput: boolean;
246
247
  graphqlScalars: Record<string, ImportNameSpec | undefined>;
247
248
  decorate: DecorateElement[];
248
249
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "19.1.0",
3
+ "version": "19.2.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",
@@ -70,10 +70,10 @@
70
70
  }
71
71
  },
72
72
  "dependencies": {
73
- "@prisma/generator-helper": "^5.1.1",
73
+ "@prisma/generator-helper": "^5.3.1",
74
74
  "await-event-emitter": "^2.0.2",
75
75
  "filenamify": "4.X",
76
- "flat": "^5.0.2",
76
+ "flat": "5.X",
77
77
  "get-relative-path": "^1.0.2",
78
78
  "graceful-fs": "^4.2.11",
79
79
  "json5": "^2.2.3",
@@ -84,28 +84,28 @@
84
84
  "ts-morph": ">=11 <=16"
85
85
  },
86
86
  "devDependencies": {
87
- "@commitlint/cli": "^17.6.7",
88
- "@commitlint/config-conventional": "^17.6.7",
89
- "@nestjs/apollo": "^12.0.7",
90
- "@nestjs/common": "^10.1.3",
91
- "@nestjs/core": "^10.1.3",
92
- "@nestjs/graphql": "^12.0.8",
93
- "@nestjs/platform-express": "^10.1.3",
94
- "@paljs/plugins": "^5.3.3",
95
- "@prisma/client": "^5.1.1",
87
+ "@commitlint/cli": "^17.7.1",
88
+ "@commitlint/config-conventional": "^17.7.0",
89
+ "@nestjs/apollo": "^12.0.9",
90
+ "@nestjs/common": "^10.2.6",
91
+ "@nestjs/core": "^10.2.6",
92
+ "@nestjs/graphql": "^12.0.9",
93
+ "@nestjs/platform-express": "^10.2.6",
94
+ "@paljs/plugins": "^6.0.7",
95
+ "@prisma/client": "^5.3.1",
96
96
  "@semantic-release/changelog": "^6.0.3",
97
97
  "@semantic-release/git": "^10.0.1",
98
- "@swc/core": "^1.3.74",
99
- "@swc/helpers": "^0.5.1",
98
+ "@swc/core": "^1.3.87",
99
+ "@swc/helpers": "^0.5.2",
100
100
  "@swc/register": "^0.1.10",
101
- "@types/flat": "^5.0.2",
102
- "@types/graceful-fs": "^4.1.6",
103
- "@types/lodash": "^4.14.196",
101
+ "@types/flat": "^5.0.3",
102
+ "@types/graceful-fs": "^4.1.7",
103
+ "@types/lodash": "^4.14.199",
104
104
  "@types/mocha": "^10.0.1",
105
- "@types/node": "^20.4.7",
105
+ "@types/node": "^20.6.3",
106
106
  "@types/pluralize": "^0.0.30",
107
- "@typescript-eslint/eslint-plugin": "^6.2.1",
108
- "@typescript-eslint/parser": "^6.2.1",
107
+ "@typescript-eslint/eslint-plugin": "^6.7.2",
108
+ "@typescript-eslint/parser": "^6.7.2",
109
109
  "apollo-server-express": "^3.10.0",
110
110
  "c8": "^8.0.1",
111
111
  "class-transformer": "^0.5.1",
@@ -113,10 +113,10 @@
113
113
  "commitizen": "^4.3.0",
114
114
  "cz-customizable": "^7.0.0",
115
115
  "decimal.js": "^10.4.3",
116
- "eslint": "^8.46.0",
117
- "eslint-import-resolver-node": "^0.3.7",
116
+ "eslint": "^8.50.0",
117
+ "eslint-import-resolver-node": "^0.3.9",
118
118
  "eslint-plugin-etc": "^2.0.3",
119
- "eslint-plugin-import": "^2.28.0",
119
+ "eslint-plugin-import": "^2.28.1",
120
120
  "eslint-plugin-only-warn": "^1.1.0",
121
121
  "eslint-plugin-prettier": "^5.0.0",
122
122
  "eslint-plugin-regexp": "^1.15.0",
@@ -124,29 +124,26 @@
124
124
  "eslint-plugin-sort-class-members": "^1.18.0",
125
125
  "eslint-plugin-unicorn": "^48.0.1",
126
126
  "eslint-plugin-wix-editor": "^3.3.0",
127
- "expect": "^29.6.2",
127
+ "expect": "^29.7.0",
128
128
  "git-branch-is": "^4.0.0",
129
- "graphql": "^16.7.1",
129
+ "graphql": "^16.8.1",
130
130
  "graphql-scalars": "^1.22.2",
131
131
  "graphql-type-json": "^0.3.2",
132
132
  "mocha": "^10.2.0",
133
133
  "ololog": "^1.1.175",
134
134
  "precise-commits": "^1.0.2",
135
- "prettier": "^3.0.1",
136
- "prisma": "^5.1.1",
135
+ "prettier": "^3.0.3",
136
+ "prisma": "^5.3.1",
137
137
  "prisma-graphql-type-decimal": "^3.0.0",
138
138
  "reflect-metadata": "^0.1.13",
139
139
  "request": "^2.88.2",
140
140
  "rxjs": "^7.8.1",
141
- "semantic-release": "^21.0.7",
141
+ "semantic-release": "^22.0.4",
142
142
  "simplytyped": "^3.3.0",
143
143
  "temp-dir": "2.X",
144
144
  "ts-node": "^10.9.1",
145
- "tslib": "^2.6.1",
146
- "typescript": "^5.1.6",
145
+ "tslib": "^2.6.2",
146
+ "typescript": "^5.2.2",
147
147
  "watchexec-bin": "^1.0.0"
148
- },
149
- "overrides": {
150
- "prisma": "^5.1.1"
151
148
  }
152
149
  }