prisma-nestjs-graphql 18.1.0 → 18.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/generate.cjs +37 -15
- package/generate.d.ts +1 -1
- package/package.json +34 -32
package/README.md
CHANGED
|
@@ -701,6 +701,12 @@ model User {
|
|
|
701
701
|
export class User {}
|
|
702
702
|
```
|
|
703
703
|
|
|
704
|
+
### Using lirary in other generators
|
|
705
|
+
|
|
706
|
+
```ts
|
|
707
|
+
import { generate } from 'prisma-nestjs-graphql/generate';
|
|
708
|
+
```
|
|
709
|
+
|
|
704
710
|
## Similar Projects
|
|
705
711
|
|
|
706
712
|
- https://github.com/jasonraimondi/prisma-generator-nestjs-graphql
|
package/generate.cjs
CHANGED
|
@@ -26,7 +26,7 @@ var filenamify__default = /*#__PURE__*/_interopDefaultLegacy(filenamify);
|
|
|
26
26
|
var pluralize__default = /*#__PURE__*/_interopDefaultLegacy(pluralize);
|
|
27
27
|
|
|
28
28
|
function pascalCase(string) {
|
|
29
|
-
return lodash.startCase(lodash.camelCase(string)).
|
|
29
|
+
return lodash.startCase(lodash.camelCase(string)).replaceAll(" ", "");
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function argsType(field, args) {
|
|
@@ -110,7 +110,7 @@ function beforeGenerateField(field) {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
function replaceBogus(name) {
|
|
113
|
-
return name.
|
|
113
|
+
return name.replaceAll(/Nullable|Nested/g, "");
|
|
114
114
|
}
|
|
115
115
|
function isContainBogus(name) {
|
|
116
116
|
return name.startsWith("Nested") || name.includes("Nullable") && name.endsWith("Filter") || name.endsWith("NullableFilter");
|
|
@@ -129,7 +129,7 @@ function isScalarFilter(inputType) {
|
|
|
129
129
|
return result;
|
|
130
130
|
}
|
|
131
131
|
function postBegin(args) {
|
|
132
|
-
const { schema } = args;
|
|
132
|
+
const { schema, modelNames } = args;
|
|
133
133
|
const inputTypes = schema.inputObjectTypes.prisma;
|
|
134
134
|
const enumTypes = schema.enumTypes.model || [];
|
|
135
135
|
const types = [
|
|
@@ -173,6 +173,11 @@ function postBegin(args) {
|
|
|
173
173
|
`Nested${type}NullableListFilter`
|
|
174
174
|
]);
|
|
175
175
|
}
|
|
176
|
+
for (const modelName of modelNames) {
|
|
177
|
+
replaceBogusFilters(`${modelName}RelationFilter`, [
|
|
178
|
+
`${modelName}NullableRelationFilter`
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
176
181
|
lodash.remove(inputTypes, (inputType) => isContainBogus(inputType.name));
|
|
177
182
|
}
|
|
178
183
|
|
|
@@ -213,11 +218,12 @@ function emitSingle(emitter) {
|
|
|
213
218
|
function classProperty(property, eventArguments) {
|
|
214
219
|
const { location, isList, propertyType } = eventArguments;
|
|
215
220
|
if (["inputObjectTypes", "outputObjectTypes"].includes(location) && !isList) {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
+
const [safeTypes, instanceofTypes] = lodash.partition(
|
|
222
|
+
propertyType,
|
|
223
|
+
(t) => t === "null" || t.startsWith("Prisma.")
|
|
224
|
+
);
|
|
225
|
+
const mappedInstanceofTypes = instanceofTypes.map((t) => `InstanceType<typeof ${t}>`);
|
|
226
|
+
property.type = [...mappedInstanceofTypes, ...safeTypes].join(" | ");
|
|
221
227
|
}
|
|
222
228
|
}
|
|
223
229
|
|
|
@@ -557,6 +563,19 @@ function getPropertyType(args) {
|
|
|
557
563
|
return ["unknown"];
|
|
558
564
|
}
|
|
559
565
|
|
|
566
|
+
function getWhereUniqueAtLeastKeys(model) {
|
|
567
|
+
const names = model.fields.filter((field) => field.isUnique || field.isId).map((field) => field.name);
|
|
568
|
+
for (const uniqueIndex of model.uniqueIndexes) {
|
|
569
|
+
const name = uniqueIndex.name || uniqueIndex.fields.join("_");
|
|
570
|
+
names.push(name);
|
|
571
|
+
}
|
|
572
|
+
return names.map((name) => `'${name}'`).join(" | ");
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function isWhereUniqueInputType(name) {
|
|
576
|
+
return name.endsWith("WhereUniqueInput");
|
|
577
|
+
}
|
|
578
|
+
|
|
560
579
|
function propertyStructure(args) {
|
|
561
580
|
const {
|
|
562
581
|
isNullable,
|
|
@@ -644,8 +663,9 @@ function inputType(args) {
|
|
|
644
663
|
});
|
|
645
664
|
const modelField = model == null ? void 0 : model.fields.find((f) => f.name === name);
|
|
646
665
|
const isCustomsApplicable = typeName === (modelField == null ? void 0 : modelField.type);
|
|
666
|
+
const whereUniqueInputType = isWhereUniqueInputType(typeName) && model && `Prisma.AtLeast<${typeName}, ${getWhereUniqueAtLeastKeys(model)}>`;
|
|
647
667
|
const propertyType = lodash.castArray(
|
|
648
|
-
(propertySettings == null ? void 0 : propertySettings.name) || getPropertyType({
|
|
668
|
+
(propertySettings == null ? void 0 : propertySettings.name) || whereUniqueInputType || getPropertyType({
|
|
649
669
|
location,
|
|
650
670
|
type: typeName
|
|
651
671
|
})
|
|
@@ -661,6 +681,8 @@ function inputType(args) {
|
|
|
661
681
|
importDeclarations.create({ ...propertySettings });
|
|
662
682
|
} else if (propertyType.includes("Decimal")) {
|
|
663
683
|
importDeclarations.add("Decimal", "@prisma/client/runtime/library");
|
|
684
|
+
} else if (propertyType.some((p) => p.startsWith("Prisma."))) {
|
|
685
|
+
importDeclarations.add("Prisma", "@prisma/client");
|
|
664
686
|
}
|
|
665
687
|
let graphqlType;
|
|
666
688
|
const shouldHideField = (settings == null ? void 0 : settings.shouldHideField({
|
|
@@ -1611,9 +1633,6 @@ function beforeInputType(args) {
|
|
|
1611
1633
|
field.isNullable = false;
|
|
1612
1634
|
}
|
|
1613
1635
|
}
|
|
1614
|
-
function isWhereUniqueInputType(name) {
|
|
1615
|
-
return name.endsWith("WhereUniqueInput");
|
|
1616
|
-
}
|
|
1617
1636
|
|
|
1618
1637
|
function warning(message) {
|
|
1619
1638
|
if (Array.isArray(message)) {
|
|
@@ -1633,7 +1652,7 @@ function createConfig(data) {
|
|
|
1633
1652
|
);
|
|
1634
1653
|
let outputFilePattern = filenamify__default["default"](configOutputFilePattern, {
|
|
1635
1654
|
replacement: "/"
|
|
1636
|
-
}).
|
|
1655
|
+
}).replaceAll("..", "/").replaceAll(/\/+/g, "/");
|
|
1637
1656
|
outputFilePattern = lodash.trim(outputFilePattern, "/");
|
|
1638
1657
|
if (outputFilePattern !== configOutputFilePattern) {
|
|
1639
1658
|
$warnings.push(
|
|
@@ -1801,11 +1820,11 @@ function getModelName(args) {
|
|
|
1801
1820
|
}
|
|
1802
1821
|
for (const [start, end] of middleKeywords) {
|
|
1803
1822
|
let test = name.slice(start.length).slice(0, -end.length);
|
|
1804
|
-
if (modelNames.includes(test)) {
|
|
1823
|
+
if (modelNames.includes(test) && name.startsWith(start) && name.endsWith(end)) {
|
|
1805
1824
|
return test;
|
|
1806
1825
|
}
|
|
1807
1826
|
test = name.slice(0, -(start + end).length);
|
|
1808
|
-
if (modelNames.includes(test)) {
|
|
1827
|
+
if (modelNames.includes(test) && name.endsWith(start + end)) {
|
|
1809
1828
|
return test;
|
|
1810
1829
|
}
|
|
1811
1830
|
}
|
|
@@ -1834,6 +1853,7 @@ const splitKeywords = [
|
|
|
1834
1853
|
"ManyWithout",
|
|
1835
1854
|
"OrderByInput",
|
|
1836
1855
|
"RelationFilter",
|
|
1856
|
+
"NullableRelationFilter",
|
|
1837
1857
|
"ListRelationFilter",
|
|
1838
1858
|
"ScalarWhereInput",
|
|
1839
1859
|
"UpdateInput",
|
|
@@ -1869,6 +1889,7 @@ const endsWithKeywords = [
|
|
|
1869
1889
|
"Aggregate",
|
|
1870
1890
|
"GroupBy",
|
|
1871
1891
|
"CreateOne",
|
|
1892
|
+
"CreateMany",
|
|
1872
1893
|
"DeleteMany",
|
|
1873
1894
|
"DeleteOne",
|
|
1874
1895
|
"FindMany",
|
|
@@ -1883,6 +1904,7 @@ const middleKeywords = [
|
|
|
1883
1904
|
["FindUnique", "OrThrowArgs"],
|
|
1884
1905
|
["Aggregate", "Args"],
|
|
1885
1906
|
["CreateOne", "Args"],
|
|
1907
|
+
["CreateMany", "Args"],
|
|
1886
1908
|
["DeleteMany", "Args"],
|
|
1887
1909
|
["DeleteOne", "Args"],
|
|
1888
1910
|
["FindMany", "Args"],
|
package/generate.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ declare namespace DMMF {
|
|
|
70
70
|
isGenerated?: boolean;
|
|
71
71
|
isUpdatedAt?: boolean;
|
|
72
72
|
/**
|
|
73
|
-
* Describes the data type in the same the way
|
|
73
|
+
* Describes the data type in the same the way it is defined in the Prisma schema:
|
|
74
74
|
* BigInt, Boolean, Bytes, DateTime, Decimal, Float, Int, JSON, String, $ModelName
|
|
75
75
|
*/
|
|
76
76
|
type: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-nestjs-graphql",
|
|
3
|
-
"version": "18.1.
|
|
3
|
+
"version": "18.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module",
|
|
6
6
|
"bin": "bin.js",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@prisma/generator-helper": "^
|
|
73
|
+
"@prisma/generator-helper": "^5.0.0",
|
|
74
74
|
"await-event-emitter": "^2.0.2",
|
|
75
75
|
"filenamify": "4.X",
|
|
76
76
|
"flat": "^5.0.2",
|
|
@@ -84,67 +84,69 @@
|
|
|
84
84
|
"ts-morph": ">=11 <=16"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@commitlint/cli": "^17.6.
|
|
88
|
-
"@commitlint/config-conventional": "^17.6.
|
|
89
|
-
"@nestjs/apollo": "^
|
|
90
|
-
"@nestjs/common": "^
|
|
91
|
-
"@nestjs/core": "^
|
|
92
|
-
"@nestjs/graphql": "^
|
|
93
|
-
"@nestjs/platform-express": "^
|
|
94
|
-
"@paljs/plugins": "^5.3.
|
|
95
|
-
"@prisma/client": "^
|
|
87
|
+
"@commitlint/cli": "^17.6.7",
|
|
88
|
+
"@commitlint/config-conventional": "^17.6.7",
|
|
89
|
+
"@nestjs/apollo": "^12.0.7",
|
|
90
|
+
"@nestjs/common": "^10.1.0",
|
|
91
|
+
"@nestjs/core": "^10.1.0",
|
|
92
|
+
"@nestjs/graphql": "^12.0.8",
|
|
93
|
+
"@nestjs/platform-express": "^10.1.0",
|
|
94
|
+
"@paljs/plugins": "^5.3.3",
|
|
95
|
+
"@prisma/client": "^5.0.0",
|
|
96
96
|
"@semantic-release/changelog": "^6.0.3",
|
|
97
97
|
"@semantic-release/git": "^10.0.1",
|
|
98
|
-
"@swc/core": "^1.3.
|
|
98
|
+
"@swc/core": "^1.3.70",
|
|
99
99
|
"@swc/helpers": "^0.5.1",
|
|
100
100
|
"@swc/register": "^0.1.10",
|
|
101
101
|
"@types/flat": "^5.0.2",
|
|
102
102
|
"@types/graceful-fs": "^4.1.6",
|
|
103
|
-
"@types/lodash": "^4.14.
|
|
103
|
+
"@types/lodash": "^4.14.195",
|
|
104
104
|
"@types/mocha": "^10.0.1",
|
|
105
|
-
"@types/node": "^20.
|
|
106
|
-
"@types/pluralize": "^0.0.
|
|
107
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
108
|
-
"@typescript-eslint/parser": "^
|
|
105
|
+
"@types/node": "^20.4.4",
|
|
106
|
+
"@types/pluralize": "^0.0.30",
|
|
107
|
+
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
|
108
|
+
"@typescript-eslint/parser": "^6.1.0",
|
|
109
109
|
"apollo-server-express": "^3.10.0",
|
|
110
|
-
"c8": "^
|
|
110
|
+
"c8": "^8.0.0",
|
|
111
111
|
"class-transformer": "^0.5.1",
|
|
112
112
|
"class-validator": "^0.14.0",
|
|
113
113
|
"commitizen": "^4.3.0",
|
|
114
114
|
"cz-customizable": "^7.0.0",
|
|
115
115
|
"decimal.js": "^10.4.3",
|
|
116
|
-
"eslint": "^8.
|
|
116
|
+
"eslint": "^8.45.0",
|
|
117
117
|
"eslint-import-resolver-node": "^0.3.7",
|
|
118
|
-
"eslint-plugin-etc": "^2.0.
|
|
118
|
+
"eslint-plugin-etc": "^2.0.3",
|
|
119
119
|
"eslint-plugin-import": "^2.27.5",
|
|
120
120
|
"eslint-plugin-only-warn": "^1.1.0",
|
|
121
|
-
"eslint-plugin-prettier": "^
|
|
121
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
122
122
|
"eslint-plugin-regexp": "^1.15.0",
|
|
123
123
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
124
|
-
"eslint-plugin-sort-class-members": "^1.
|
|
125
|
-
"eslint-plugin-unicorn": "^
|
|
124
|
+
"eslint-plugin-sort-class-members": "^1.18.0",
|
|
125
|
+
"eslint-plugin-unicorn": "^48.0.0",
|
|
126
126
|
"eslint-plugin-wix-editor": "^3.3.0",
|
|
127
|
-
"expect": "^29.
|
|
128
|
-
"ghooks": "^2.0.4",
|
|
127
|
+
"expect": "^29.6.1",
|
|
129
128
|
"git-branch-is": "^4.0.0",
|
|
130
|
-
"graphql": "^16.
|
|
131
|
-
"graphql-scalars": "^1.
|
|
129
|
+
"graphql": "^16.7.1",
|
|
130
|
+
"graphql-scalars": "^1.22.2",
|
|
132
131
|
"graphql-type-json": "^0.3.2",
|
|
133
132
|
"mocha": "^10.2.0",
|
|
134
133
|
"ololog": "^1.1.175",
|
|
135
134
|
"precise-commits": "^1.0.2",
|
|
136
|
-
"prettier": "^
|
|
137
|
-
"prisma": "^
|
|
135
|
+
"prettier": "^3.0.0",
|
|
136
|
+
"prisma": "^5.0.0",
|
|
138
137
|
"prisma-graphql-type-decimal": "^3.0.0",
|
|
139
138
|
"reflect-metadata": "^0.1.13",
|
|
140
139
|
"request": "^2.88.2",
|
|
141
140
|
"rxjs": "^7.8.1",
|
|
142
|
-
"semantic-release": "^21.0.
|
|
141
|
+
"semantic-release": "^21.0.7",
|
|
143
142
|
"simplytyped": "^3.3.0",
|
|
144
143
|
"temp-dir": "2.X",
|
|
145
144
|
"ts-node": "^10.9.1",
|
|
146
|
-
"tslib": "^2.
|
|
147
|
-
"typescript": "^5.
|
|
145
|
+
"tslib": "^2.6.0",
|
|
146
|
+
"typescript": "^5.1.6",
|
|
148
147
|
"watchexec-bin": "^1.0.0"
|
|
148
|
+
},
|
|
149
|
+
"overrides": {
|
|
150
|
+
"prisma": "^5.0.0"
|
|
149
151
|
}
|
|
150
152
|
}
|