prisma-nestjs-graphql 21.0.0 → 21.0.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 +2 -2
- package/generate.cjs +73 -64
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,8 +78,6 @@ Default: `@prisma/client`
|
|
|
78
78
|
|
|
79
79
|
#### `combineScalarFilters`
|
|
80
80
|
|
|
81
|
-
DOESNT WORK IN v21+
|
|
82
|
-
|
|
83
81
|
Combine nested/nullable scalar filters to single
|
|
84
82
|
Type: `boolean`
|
|
85
83
|
Default: `false`
|
|
@@ -764,3 +762,5 @@ import { generate } from 'prisma-nestjs-graphql/generate';
|
|
|
764
762
|
|
|
765
763
|
- keyof typeof SortOrder -> `SortOrder`
|
|
766
764
|
- dummy-createfriends.input.ts -> `create-friends`
|
|
765
|
+
- check 'TODO FIXME'
|
|
766
|
+
- 22.12 node require esm (update all deps to latest)
|
package/generate.cjs
CHANGED
|
@@ -184,7 +184,14 @@ function postBegin(args) {
|
|
|
184
184
|
`${modelName}NullableRelationFilter`
|
|
185
185
|
]);
|
|
186
186
|
}
|
|
187
|
-
|
|
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) {
|
|
@@ -274,7 +281,7 @@ class ImportDeclarationMap extends Map {
|
|
|
274
281
|
}
|
|
275
282
|
|
|
276
283
|
async function generateFiles(args) {
|
|
277
|
-
const {
|
|
284
|
+
const { config, eventEmitter, output, project } = args;
|
|
278
285
|
if (config.emitSingle) {
|
|
279
286
|
const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
|
|
280
287
|
const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", undefined, { overwrite: true });
|
|
@@ -325,9 +332,9 @@ async function generateFiles(args) {
|
|
|
325
332
|
}
|
|
326
333
|
if (statement.defaultImport) {
|
|
327
334
|
imports.create({
|
|
335
|
+
defaultImport: statement.defaultImport,
|
|
328
336
|
from: statement.moduleSpecifier,
|
|
329
|
-
name: statement.defaultImport
|
|
330
|
-
defaultImport: statement.defaultImport
|
|
337
|
+
name: statement.defaultImport
|
|
331
338
|
});
|
|
332
339
|
}
|
|
333
340
|
if (statement.namespaceImport) {
|
|
@@ -358,9 +365,9 @@ async function generateFiles(args) {
|
|
|
358
365
|
project.compilerOptions.set({
|
|
359
366
|
declaration: true,
|
|
360
367
|
declarationDir: output,
|
|
361
|
-
rootDir: output,
|
|
362
|
-
outDir: output,
|
|
363
368
|
emitDecoratorMetadata: false,
|
|
369
|
+
outDir: output,
|
|
370
|
+
rootDir: output,
|
|
364
371
|
skipLibCheck: true
|
|
365
372
|
});
|
|
366
373
|
const emitResult = await project.emit();
|
|
@@ -409,12 +416,12 @@ function getGraphqlImport(args) {
|
|
|
409
416
|
const {
|
|
410
417
|
config,
|
|
411
418
|
fileType,
|
|
412
|
-
|
|
413
|
-
typeName,
|
|
419
|
+
getSourceFile,
|
|
414
420
|
isId,
|
|
421
|
+
location,
|
|
415
422
|
noTypeId,
|
|
416
423
|
sourceFile,
|
|
417
|
-
|
|
424
|
+
typeName
|
|
418
425
|
} = args;
|
|
419
426
|
if (location === "scalar") {
|
|
420
427
|
if (isId && !noTypeId) {
|
|
@@ -455,8 +462,8 @@ function getGraphqlImport(args) {
|
|
|
455
462
|
const specifier = relativePath(
|
|
456
463
|
sourceFile.getFilePath(),
|
|
457
464
|
getSourceFile({
|
|
458
|
-
|
|
459
|
-
|
|
465
|
+
name: typeName,
|
|
466
|
+
type: sourceFileType
|
|
460
467
|
}).getFilePath()
|
|
461
468
|
);
|
|
462
469
|
return { name: typeName, specifier };
|
|
@@ -557,7 +564,8 @@ function getPropertyType(args) {
|
|
|
557
564
|
return [type];
|
|
558
565
|
}
|
|
559
566
|
if (location === "enumTypes") {
|
|
560
|
-
|
|
567
|
+
const enumType = "`${" + type + "}`";
|
|
568
|
+
return [enumType];
|
|
561
569
|
}
|
|
562
570
|
if (location === "scalar") {
|
|
563
571
|
return [type];
|
|
@@ -1353,9 +1361,13 @@ function isListInput(typeName, model, field) {
|
|
|
1353
1361
|
return typeName === `${model}Create${field}Input` || typeName === `${model}Update${field}Input`;
|
|
1354
1362
|
}
|
|
1355
1363
|
|
|
1364
|
+
function getEnumName(referenceName) {
|
|
1365
|
+
return referenceName.slice(3, -2);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1356
1368
|
const nestjsGraphql = "@nestjs/graphql";
|
|
1357
1369
|
function outputType(outputType2, args) {
|
|
1358
|
-
const {
|
|
1370
|
+
const { config, eventEmitter, fieldSettings, getModelName, getSourceFile, models } = args;
|
|
1359
1371
|
const importDeclarations = new ImportDeclarationMap();
|
|
1360
1372
|
const fileType = "output";
|
|
1361
1373
|
const modelName = getModelName(outputType2.name) || "";
|
|
@@ -1372,21 +1384,21 @@ function outputType(outputType2, args) {
|
|
|
1372
1384
|
type: fileType
|
|
1373
1385
|
});
|
|
1374
1386
|
const classStructure = {
|
|
1375
|
-
kind: tsMorph.StructureKind.Class,
|
|
1376
|
-
isExported: true,
|
|
1377
|
-
name: outputType2.name,
|
|
1378
1387
|
decorators: [
|
|
1379
1388
|
{
|
|
1380
|
-
|
|
1381
|
-
|
|
1389
|
+
arguments: [],
|
|
1390
|
+
name: "ObjectType"
|
|
1382
1391
|
}
|
|
1383
1392
|
],
|
|
1393
|
+
isExported: true,
|
|
1394
|
+
kind: tsMorph.StructureKind.Class,
|
|
1395
|
+
name: outputType2.name,
|
|
1384
1396
|
properties: []
|
|
1385
1397
|
};
|
|
1386
1398
|
importDeclarations.add("Field", nestjsGraphql);
|
|
1387
1399
|
importDeclarations.add("ObjectType", nestjsGraphql);
|
|
1388
1400
|
for (const field of outputType2.fields) {
|
|
1389
|
-
const {
|
|
1401
|
+
const { isList, location, type } = field.outputType;
|
|
1390
1402
|
const outputTypeName = getOutputTypeName(String(type));
|
|
1391
1403
|
const settings = isCountOutput ? undefined : model && fieldSettings.get(model.name)?.get(field.name);
|
|
1392
1404
|
const propertySettings = settings?.getPropertyType({
|
|
@@ -1402,11 +1414,11 @@ function outputType(outputType2, args) {
|
|
|
1402
1414
|
})
|
|
1403
1415
|
);
|
|
1404
1416
|
const property = propertyStructure({
|
|
1405
|
-
name: field.name,
|
|
1406
|
-
isNullable: field.isNullable,
|
|
1407
1417
|
hasQuestionToken: isCountOutput ? true : undefined,
|
|
1408
|
-
|
|
1409
|
-
|
|
1418
|
+
isList,
|
|
1419
|
+
isNullable: field.isNullable,
|
|
1420
|
+
name: field.name,
|
|
1421
|
+
propertyType
|
|
1410
1422
|
});
|
|
1411
1423
|
classStructure.properties?.push(property);
|
|
1412
1424
|
if (propertySettings) {
|
|
@@ -1431,46 +1443,43 @@ function outputType(outputType2, args) {
|
|
|
1431
1443
|
} else {
|
|
1432
1444
|
const graphqlImport = getGraphqlImport({
|
|
1433
1445
|
config,
|
|
1434
|
-
sourceFile,
|
|
1435
1446
|
fileType,
|
|
1436
|
-
|
|
1447
|
+
getSourceFile,
|
|
1437
1448
|
isId: false,
|
|
1438
|
-
|
|
1439
|
-
|
|
1449
|
+
location,
|
|
1450
|
+
sourceFile,
|
|
1451
|
+
typeName: outputTypeName
|
|
1440
1452
|
});
|
|
1453
|
+
const referenceName = location === "enumTypes" ? getEnumName(propertyType[0]) : propertyType[0];
|
|
1441
1454
|
graphqlType = graphqlImport.name;
|
|
1442
|
-
let referenceName = propertyType[0];
|
|
1443
|
-
if (location === "enumTypes") {
|
|
1444
|
-
referenceName = lodash.last(referenceName.split(" "));
|
|
1445
|
-
}
|
|
1446
1455
|
if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType2.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
|
|
1447
1456
|
importDeclarations.set(graphqlImport.name, {
|
|
1448
|
-
|
|
1449
|
-
|
|
1457
|
+
moduleSpecifier: graphqlImport.specifier,
|
|
1458
|
+
namedImports: [{ name: graphqlImport.name }]
|
|
1450
1459
|
});
|
|
1451
1460
|
}
|
|
1452
1461
|
}
|
|
1453
1462
|
assert.ok(property.decorators, "property.decorators is undefined");
|
|
1454
1463
|
if (shouldHideField) {
|
|
1455
1464
|
importDeclarations.add("HideField", nestjsGraphql);
|
|
1456
|
-
property.decorators.push({ name: "HideField"
|
|
1465
|
+
property.decorators.push({ arguments: [], name: "HideField" });
|
|
1457
1466
|
} else {
|
|
1458
1467
|
property.decorators.push({
|
|
1459
|
-
name: "Field",
|
|
1460
1468
|
arguments: [
|
|
1461
1469
|
isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
|
|
1462
1470
|
JSON5.stringify({
|
|
1463
1471
|
...settings?.fieldArguments(),
|
|
1464
1472
|
nullable: Boolean(field.isNullable)
|
|
1465
1473
|
})
|
|
1466
|
-
]
|
|
1474
|
+
],
|
|
1475
|
+
name: "Field"
|
|
1467
1476
|
});
|
|
1468
1477
|
if (isCustomsApplicable) {
|
|
1469
1478
|
for (const options of settings || []) {
|
|
1470
1479
|
if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
|
|
1471
1480
|
property.decorators.push({
|
|
1472
|
-
|
|
1473
|
-
|
|
1481
|
+
arguments: options.arguments,
|
|
1482
|
+
name: options.name
|
|
1474
1483
|
});
|
|
1475
1484
|
assert.ok(options.from, "Missed 'from' part in configuration or field setting");
|
|
1476
1485
|
importDeclarations.create(options);
|
|
@@ -1479,8 +1488,8 @@ function outputType(outputType2, args) {
|
|
|
1479
1488
|
}
|
|
1480
1489
|
}
|
|
1481
1490
|
eventEmitter.emitSync("ClassProperty", property, {
|
|
1482
|
-
location,
|
|
1483
1491
|
isList,
|
|
1492
|
+
location,
|
|
1484
1493
|
propertyType
|
|
1485
1494
|
});
|
|
1486
1495
|
}
|
|
@@ -1812,9 +1821,8 @@ function toBoolean(value) {
|
|
|
1812
1821
|
}
|
|
1813
1822
|
|
|
1814
1823
|
function generateFileName(args) {
|
|
1815
|
-
const {
|
|
1824
|
+
const { getModelName, name, template, type } = args;
|
|
1816
1825
|
return pupa(template, {
|
|
1817
|
-
type,
|
|
1818
1826
|
get model() {
|
|
1819
1827
|
const result = getModelName(name) || "prisma";
|
|
1820
1828
|
return lodash.kebabCase(result);
|
|
@@ -1833,7 +1841,8 @@ function generateFileName(args) {
|
|
|
1833
1841
|
get type() {
|
|
1834
1842
|
return pluralize(type);
|
|
1835
1843
|
}
|
|
1836
|
-
}
|
|
1844
|
+
},
|
|
1845
|
+
type
|
|
1837
1846
|
});
|
|
1838
1847
|
}
|
|
1839
1848
|
|
|
@@ -1976,7 +1985,7 @@ const middleKeywords = [
|
|
|
1976
1985
|
|
|
1977
1986
|
const AwaitEventEmitter = require$1("await-event-emitter").default;
|
|
1978
1987
|
async function generate(args) {
|
|
1979
|
-
const { connectCallback, generator, skipAddOutputSourceFiles
|
|
1988
|
+
const { connectCallback, dmmf, generator, skipAddOutputSourceFiles } = args;
|
|
1980
1989
|
const generatorOutputValue = generator.output?.value;
|
|
1981
1990
|
assert.ok(generatorOutputValue, "Missing generator configuration: output");
|
|
1982
1991
|
const config = createConfig(generator.config);
|
|
@@ -1998,12 +2007,12 @@ async function generate(args) {
|
|
|
1998
2007
|
eventEmitter.emitSync("Warning", message);
|
|
1999
2008
|
}
|
|
2000
2009
|
const project = new tsMorph.Project({
|
|
2001
|
-
tsConfigFilePath: config.tsConfigFilePath,
|
|
2002
|
-
skipAddingFilesFromTsConfig: true,
|
|
2003
|
-
skipLoadingLibFiles: !config.emitCompiled,
|
|
2004
2010
|
manipulationSettings: {
|
|
2005
2011
|
quoteKind: tsMorph.QuoteKind.Single
|
|
2006
|
-
}
|
|
2012
|
+
},
|
|
2013
|
+
skipAddingFilesFromTsConfig: true,
|
|
2014
|
+
skipLoadingLibFiles: !config.emitCompiled,
|
|
2015
|
+
tsConfigFilePath: config.tsConfigFilePath
|
|
2007
2016
|
});
|
|
2008
2017
|
if (!skipAddOutputSourceFiles) {
|
|
2009
2018
|
project.addSourceFilesAtPaths([
|
|
@@ -2023,30 +2032,30 @@ async function generate(args) {
|
|
|
2023
2032
|
const fieldSettings = /* @__PURE__ */ new Map();
|
|
2024
2033
|
const getModelName = createGetModelName(modelNames);
|
|
2025
2034
|
const getSourceFile = factoryGetSourceFile({
|
|
2026
|
-
|
|
2027
|
-
project,
|
|
2035
|
+
eventEmitter,
|
|
2028
2036
|
getModelName,
|
|
2037
|
+
output: generatorOutputValue,
|
|
2029
2038
|
outputFilePattern: config.outputFilePattern,
|
|
2030
|
-
|
|
2039
|
+
project
|
|
2031
2040
|
});
|
|
2032
2041
|
const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf));
|
|
2033
2042
|
const removeTypes = /* @__PURE__ */ new Set();
|
|
2034
2043
|
const eventArguments = {
|
|
2035
|
-
|
|
2036
|
-
models,
|
|
2044
|
+
classTransformerTypeModels: /* @__PURE__ */ new Set(),
|
|
2037
2045
|
config,
|
|
2038
|
-
modelNames,
|
|
2039
|
-
modelFields,
|
|
2040
|
-
fieldSettings,
|
|
2041
|
-
project,
|
|
2042
|
-
output: generatorOutputValue,
|
|
2043
|
-
getSourceFile,
|
|
2044
|
-
eventEmitter,
|
|
2045
|
-
typeNames: /* @__PURE__ */ new Set(),
|
|
2046
2046
|
enums: lodash.mapKeys(datamodel.enums, (x) => x.name),
|
|
2047
|
+
eventEmitter,
|
|
2048
|
+
fieldSettings,
|
|
2047
2049
|
getModelName,
|
|
2050
|
+
getSourceFile,
|
|
2051
|
+
modelFields,
|
|
2052
|
+
modelNames,
|
|
2053
|
+
models,
|
|
2054
|
+
output: generatorOutputValue,
|
|
2055
|
+
project,
|
|
2048
2056
|
removeTypes,
|
|
2049
|
-
|
|
2057
|
+
schema,
|
|
2058
|
+
typeNames: /* @__PURE__ */ new Set()
|
|
2050
2059
|
};
|
|
2051
2060
|
if (connectCallback) {
|
|
2052
2061
|
await connectCallback(eventEmitter, eventArguments);
|
|
@@ -2058,7 +2067,7 @@ async function generate(args) {
|
|
|
2058
2067
|
for (const model of datamodel.types || []) {
|
|
2059
2068
|
await eventEmitter.emit("Model", model, eventArguments);
|
|
2060
2069
|
}
|
|
2061
|
-
const { inputObjectTypes, outputObjectTypes
|
|
2070
|
+
const { enumTypes, inputObjectTypes, outputObjectTypes } = schema;
|
|
2062
2071
|
await eventEmitter.emit("PostBegin", eventArguments);
|
|
2063
2072
|
for (const enumType of enumTypes.prisma.concat(enumTypes.model || [])) {
|
|
2064
2073
|
await eventEmitter.emit("EnumType", enumType, eventArguments);
|
|
@@ -2078,9 +2087,9 @@ async function generate(args) {
|
|
|
2078
2087
|
for (const inputType2 of inputTypes) {
|
|
2079
2088
|
const event = {
|
|
2080
2089
|
...eventArguments,
|
|
2081
|
-
|
|
2090
|
+
classDecoratorName: "InputType",
|
|
2082
2091
|
fileType: "input",
|
|
2083
|
-
|
|
2092
|
+
inputType: inputType2
|
|
2084
2093
|
};
|
|
2085
2094
|
if (inputType2.fields.length === 0) {
|
|
2086
2095
|
removeTypes.add(inputType2.name);
|
package/package.json
CHANGED