prisma-nestjs-graphql 21.0.1 → 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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/generate.cjs +65 -63
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -763,3 +763,4 @@ import { generate } from 'prisma-nestjs-graphql/generate';
763
763
  - keyof typeof SortOrder -> `SortOrder`
764
764
  - dummy-createfriends.input.ts -> `create-friends`
765
765
  - check 'TODO FIXME'
766
+ - 22.12 node require esm (update all deps to latest)
package/generate.cjs CHANGED
@@ -281,7 +281,7 @@ class ImportDeclarationMap extends Map {
281
281
  }
282
282
 
283
283
  async function generateFiles(args) {
284
- const { project, config, output, eventEmitter } = args;
284
+ const { config, eventEmitter, output, project } = args;
285
285
  if (config.emitSingle) {
286
286
  const rootDirectory = project.getDirectory(output) || project.createDirectory(output);
287
287
  const sourceFile = rootDirectory.getSourceFile("index.ts") || rootDirectory.createSourceFile("index.ts", undefined, { overwrite: true });
@@ -332,9 +332,9 @@ async function generateFiles(args) {
332
332
  }
333
333
  if (statement.defaultImport) {
334
334
  imports.create({
335
+ defaultImport: statement.defaultImport,
335
336
  from: statement.moduleSpecifier,
336
- name: statement.defaultImport,
337
- defaultImport: statement.defaultImport
337
+ name: statement.defaultImport
338
338
  });
339
339
  }
340
340
  if (statement.namespaceImport) {
@@ -365,9 +365,9 @@ async function generateFiles(args) {
365
365
  project.compilerOptions.set({
366
366
  declaration: true,
367
367
  declarationDir: output,
368
- rootDir: output,
369
- outDir: output,
370
368
  emitDecoratorMetadata: false,
369
+ outDir: output,
370
+ rootDir: output,
371
371
  skipLibCheck: true
372
372
  });
373
373
  const emitResult = await project.emit();
@@ -416,12 +416,12 @@ function getGraphqlImport(args) {
416
416
  const {
417
417
  config,
418
418
  fileType,
419
- location,
420
- typeName,
419
+ getSourceFile,
421
420
  isId,
421
+ location,
422
422
  noTypeId,
423
423
  sourceFile,
424
- getSourceFile
424
+ typeName
425
425
  } = args;
426
426
  if (location === "scalar") {
427
427
  if (isId && !noTypeId) {
@@ -462,8 +462,8 @@ function getGraphqlImport(args) {
462
462
  const specifier = relativePath(
463
463
  sourceFile.getFilePath(),
464
464
  getSourceFile({
465
- type: sourceFileType,
466
- name: typeName
465
+ name: typeName,
466
+ type: sourceFileType
467
467
  }).getFilePath()
468
468
  );
469
469
  return { name: typeName, specifier };
@@ -564,7 +564,8 @@ function getPropertyType(args) {
564
564
  return [type];
565
565
  }
566
566
  if (location === "enumTypes") {
567
- return [`keyof typeof ${type}`];
567
+ const enumType = "`${" + type + "}`";
568
+ return [enumType];
568
569
  }
569
570
  if (location === "scalar") {
570
571
  return [type];
@@ -1360,9 +1361,13 @@ function isListInput(typeName, model, field) {
1360
1361
  return typeName === `${model}Create${field}Input` || typeName === `${model}Update${field}Input`;
1361
1362
  }
1362
1363
 
1364
+ function getEnumName(referenceName) {
1365
+ return referenceName.slice(3, -2);
1366
+ }
1367
+
1363
1368
  const nestjsGraphql = "@nestjs/graphql";
1364
1369
  function outputType(outputType2, args) {
1365
- const { getSourceFile, models, eventEmitter, fieldSettings, getModelName, config } = args;
1370
+ const { config, eventEmitter, fieldSettings, getModelName, getSourceFile, models } = args;
1366
1371
  const importDeclarations = new ImportDeclarationMap();
1367
1372
  const fileType = "output";
1368
1373
  const modelName = getModelName(outputType2.name) || "";
@@ -1379,21 +1384,21 @@ function outputType(outputType2, args) {
1379
1384
  type: fileType
1380
1385
  });
1381
1386
  const classStructure = {
1382
- kind: tsMorph.StructureKind.Class,
1383
- isExported: true,
1384
- name: outputType2.name,
1385
1387
  decorators: [
1386
1388
  {
1387
- name: "ObjectType",
1388
- arguments: []
1389
+ arguments: [],
1390
+ name: "ObjectType"
1389
1391
  }
1390
1392
  ],
1393
+ isExported: true,
1394
+ kind: tsMorph.StructureKind.Class,
1395
+ name: outputType2.name,
1391
1396
  properties: []
1392
1397
  };
1393
1398
  importDeclarations.add("Field", nestjsGraphql);
1394
1399
  importDeclarations.add("ObjectType", nestjsGraphql);
1395
1400
  for (const field of outputType2.fields) {
1396
- const { location, isList, type } = field.outputType;
1401
+ const { isList, location, type } = field.outputType;
1397
1402
  const outputTypeName = getOutputTypeName(String(type));
1398
1403
  const settings = isCountOutput ? undefined : model && fieldSettings.get(model.name)?.get(field.name);
1399
1404
  const propertySettings = settings?.getPropertyType({
@@ -1409,11 +1414,11 @@ function outputType(outputType2, args) {
1409
1414
  })
1410
1415
  );
1411
1416
  const property = propertyStructure({
1412
- name: field.name,
1413
- isNullable: field.isNullable,
1414
1417
  hasQuestionToken: isCountOutput ? true : undefined,
1415
- propertyType,
1416
- isList
1418
+ isList,
1419
+ isNullable: field.isNullable,
1420
+ name: field.name,
1421
+ propertyType
1417
1422
  });
1418
1423
  classStructure.properties?.push(property);
1419
1424
  if (propertySettings) {
@@ -1438,46 +1443,43 @@ function outputType(outputType2, args) {
1438
1443
  } else {
1439
1444
  const graphqlImport = getGraphqlImport({
1440
1445
  config,
1441
- sourceFile,
1442
1446
  fileType,
1443
- location,
1447
+ getSourceFile,
1444
1448
  isId: false,
1445
- typeName: outputTypeName,
1446
- getSourceFile
1449
+ location,
1450
+ sourceFile,
1451
+ typeName: outputTypeName
1447
1452
  });
1453
+ const referenceName = location === "enumTypes" ? getEnumName(propertyType[0]) : propertyType[0];
1448
1454
  graphqlType = graphqlImport.name;
1449
- let referenceName = propertyType[0];
1450
- if (location === "enumTypes") {
1451
- referenceName = lodash.last(referenceName.split(" "));
1452
- }
1453
1455
  if (graphqlImport.specifier && !importDeclarations.has(graphqlImport.name) && (graphqlImport.name !== outputType2.name && !shouldHideField || shouldHideField && referenceName === graphqlImport.name)) {
1454
1456
  importDeclarations.set(graphqlImport.name, {
1455
- namedImports: [{ name: graphqlImport.name }],
1456
- moduleSpecifier: graphqlImport.specifier
1457
+ moduleSpecifier: graphqlImport.specifier,
1458
+ namedImports: [{ name: graphqlImport.name }]
1457
1459
  });
1458
1460
  }
1459
1461
  }
1460
1462
  assert.ok(property.decorators, "property.decorators is undefined");
1461
1463
  if (shouldHideField) {
1462
1464
  importDeclarations.add("HideField", nestjsGraphql);
1463
- property.decorators.push({ name: "HideField", arguments: [] });
1465
+ property.decorators.push({ arguments: [], name: "HideField" });
1464
1466
  } else {
1465
1467
  property.decorators.push({
1466
- name: "Field",
1467
1468
  arguments: [
1468
1469
  isList ? `() => [${graphqlType}]` : `() => ${graphqlType}`,
1469
1470
  JSON5.stringify({
1470
1471
  ...settings?.fieldArguments(),
1471
1472
  nullable: Boolean(field.isNullable)
1472
1473
  })
1473
- ]
1474
+ ],
1475
+ name: "Field"
1474
1476
  });
1475
1477
  if (isCustomsApplicable) {
1476
1478
  for (const options of settings || []) {
1477
1479
  if ((options.kind === "Decorator" && options.output && options.match?.(field.name)) ?? true) {
1478
1480
  property.decorators.push({
1479
- name: options.name,
1480
- arguments: options.arguments
1481
+ arguments: options.arguments,
1482
+ name: options.name
1481
1483
  });
1482
1484
  assert.ok(options.from, "Missed 'from' part in configuration or field setting");
1483
1485
  importDeclarations.create(options);
@@ -1486,8 +1488,8 @@ function outputType(outputType2, args) {
1486
1488
  }
1487
1489
  }
1488
1490
  eventEmitter.emitSync("ClassProperty", property, {
1489
- location,
1490
1491
  isList,
1492
+ location,
1491
1493
  propertyType
1492
1494
  });
1493
1495
  }
@@ -1819,9 +1821,8 @@ function toBoolean(value) {
1819
1821
  }
1820
1822
 
1821
1823
  function generateFileName(args) {
1822
- const { template, type, name, getModelName } = args;
1824
+ const { getModelName, name, template, type } = args;
1823
1825
  return pupa(template, {
1824
- type,
1825
1826
  get model() {
1826
1827
  const result = getModelName(name) || "prisma";
1827
1828
  return lodash.kebabCase(result);
@@ -1840,7 +1841,8 @@ function generateFileName(args) {
1840
1841
  get type() {
1841
1842
  return pluralize(type);
1842
1843
  }
1843
- }
1844
+ },
1845
+ type
1844
1846
  });
1845
1847
  }
1846
1848
 
@@ -1983,7 +1985,7 @@ const middleKeywords = [
1983
1985
 
1984
1986
  const AwaitEventEmitter = require$1("await-event-emitter").default;
1985
1987
  async function generate(args) {
1986
- const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
1988
+ const { connectCallback, dmmf, generator, skipAddOutputSourceFiles } = args;
1987
1989
  const generatorOutputValue = generator.output?.value;
1988
1990
  assert.ok(generatorOutputValue, "Missing generator configuration: output");
1989
1991
  const config = createConfig(generator.config);
@@ -2005,12 +2007,12 @@ async function generate(args) {
2005
2007
  eventEmitter.emitSync("Warning", message);
2006
2008
  }
2007
2009
  const project = new tsMorph.Project({
2008
- tsConfigFilePath: config.tsConfigFilePath,
2009
- skipAddingFilesFromTsConfig: true,
2010
- skipLoadingLibFiles: !config.emitCompiled,
2011
2010
  manipulationSettings: {
2012
2011
  quoteKind: tsMorph.QuoteKind.Single
2013
- }
2012
+ },
2013
+ skipAddingFilesFromTsConfig: true,
2014
+ skipLoadingLibFiles: !config.emitCompiled,
2015
+ tsConfigFilePath: config.tsConfigFilePath
2014
2016
  });
2015
2017
  if (!skipAddOutputSourceFiles) {
2016
2018
  project.addSourceFilesAtPaths([
@@ -2030,30 +2032,30 @@ async function generate(args) {
2030
2032
  const fieldSettings = /* @__PURE__ */ new Map();
2031
2033
  const getModelName = createGetModelName(modelNames);
2032
2034
  const getSourceFile = factoryGetSourceFile({
2033
- output: generatorOutputValue,
2034
- project,
2035
+ eventEmitter,
2035
2036
  getModelName,
2037
+ output: generatorOutputValue,
2036
2038
  outputFilePattern: config.outputFilePattern,
2037
- eventEmitter
2039
+ project
2038
2040
  });
2039
2041
  const { datamodel, schema } = JSON.parse(JSON.stringify(dmmf));
2040
2042
  const removeTypes = /* @__PURE__ */ new Set();
2041
2043
  const eventArguments = {
2042
- schema,
2043
- models,
2044
+ classTransformerTypeModels: /* @__PURE__ */ new Set(),
2044
2045
  config,
2045
- modelNames,
2046
- modelFields,
2047
- fieldSettings,
2048
- project,
2049
- output: generatorOutputValue,
2050
- getSourceFile,
2051
- eventEmitter,
2052
- typeNames: /* @__PURE__ */ new Set(),
2053
2046
  enums: lodash.mapKeys(datamodel.enums, (x) => x.name),
2047
+ eventEmitter,
2048
+ fieldSettings,
2054
2049
  getModelName,
2050
+ getSourceFile,
2051
+ modelFields,
2052
+ modelNames,
2053
+ models,
2054
+ output: generatorOutputValue,
2055
+ project,
2055
2056
  removeTypes,
2056
- classTransformerTypeModels: /* @__PURE__ */ new Set()
2057
+ schema,
2058
+ typeNames: /* @__PURE__ */ new Set()
2057
2059
  };
2058
2060
  if (connectCallback) {
2059
2061
  await connectCallback(eventEmitter, eventArguments);
@@ -2065,7 +2067,7 @@ async function generate(args) {
2065
2067
  for (const model of datamodel.types || []) {
2066
2068
  await eventEmitter.emit("Model", model, eventArguments);
2067
2069
  }
2068
- const { inputObjectTypes, outputObjectTypes, enumTypes } = schema;
2070
+ const { enumTypes, inputObjectTypes, outputObjectTypes } = schema;
2069
2071
  await eventEmitter.emit("PostBegin", eventArguments);
2070
2072
  for (const enumType of enumTypes.prisma.concat(enumTypes.model || [])) {
2071
2073
  await eventEmitter.emit("EnumType", enumType, eventArguments);
@@ -2085,9 +2087,9 @@ async function generate(args) {
2085
2087
  for (const inputType2 of inputTypes) {
2086
2088
  const event = {
2087
2089
  ...eventArguments,
2088
- inputType: inputType2,
2090
+ classDecoratorName: "InputType",
2089
2091
  fileType: "input",
2090
- classDecoratorName: "InputType"
2092
+ inputType: inputType2
2091
2093
  };
2092
2094
  if (inputType2.fields.length === 0) {
2093
2095
  removeTypes.add(inputType2.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "21.0.1",
3
+ "version": "21.0.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",