prisma-nestjs-graphql 15.1.0 → 15.2.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.
Files changed (4) hide show
  1. package/README.md +5 -25
  2. package/bin.js +2 -0
  3. package/index.js +32 -4
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -21,6 +21,8 @@ npm install --save-dev prisma-nestjs-graphql
21
21
  ```prisma
22
22
  generator nestgraphql {
23
23
  provider = "node node_modules/prisma-nestjs-graphql"
24
+ // for yarn monorepos
25
+ // provider = "prisma-nestjs-graphql"
24
26
  output = "../src/@generated/prisma-nestjs-graphql"
25
27
  }
26
28
  ```
@@ -64,9 +66,9 @@ Possible tokens:
64
66
 
65
67
  #### `tsConfigFilePath`
66
68
 
67
- Path to `tsconfig.json`
69
+ Path to `tsconfig.json` (absolute path or relative to current working directory)
68
70
  Type: `string | undefined`
69
- Default: `undefined`
71
+ Default: `tsconfig.json` if exists, `undefined` otherwise
70
72
 
71
73
  #### `combineScalarFilters`
72
74
 
@@ -556,29 +558,7 @@ Similar to `@FieldType()` but refer to TypeScript property (actually field too).
556
558
  To override TypeScript type in specific classes, you can use glob pattern `match: string | string[]`
557
559
  see [outmatch](https://github.com/axtgr/outmatch#usage) for details.
558
560
 
559
- Named import example:
560
-
561
- ```prisma
562
- model Transfer {
563
- id String @id
564
- /// @PropertyType({ name: 'Prisma.Decimal', from: '@prisma/client', namedImport: true, input: true })
565
- money Decimal
566
- }
567
- ```
568
-
569
- May generate following:
570
-
571
- ```ts
572
- import { Prisma } from '@prisma/client';
573
-
574
- @ObjectType()
575
- export class TransferCreateInput {
576
- @Field(() => GraphQLDecimal)
577
- money!: Prisma.Decimal;
578
- }
579
- ```
580
-
581
- Another example:
561
+ Example:
582
562
 
583
563
  ```
584
564
  generator nestgraphql {
package/bin.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('./index.js');
package/index.js CHANGED
@@ -1451,12 +1451,24 @@ function beforeGenerateFiles2(args) {
1451
1451
  ReExport.Directories,
1452
1452
  ReExport.All
1453
1453
  ].includes(config.reExport)) {
1454
- for (const directory of rootDirectory.getDirectories()) {
1454
+ for (const directory of rootDirectory.getDescendantDirectories()) {
1455
+ let indexSourceFile;
1455
1456
  const exportDeclarations = directory.getSourceFiles().filter((sourceFile) => {
1456
1457
  return sourceFile.getBaseName() !== "index.ts";
1457
1458
  }).map((sourcesFile) => getExportDeclaration2(directory, sourcesFile));
1458
- directory.createSourceFile("index.ts", {
1459
- statements: exportDeclarations
1459
+ if (exportDeclarations.length > 0) {
1460
+ indexSourceFile = directory.createSourceFile("index.ts", {
1461
+ statements: exportDeclarations
1462
+ }, {
1463
+ overwrite: true
1464
+ });
1465
+ }
1466
+ if (indexSourceFile) {
1467
+ continue;
1468
+ }
1469
+ const namespaceExportDeclarations = directory.getDirectories().map((sourceDirectory) => getNamespaceExportDeclaration(directory, sourceDirectory));
1470
+ project.createSourceFile(`${directory.getPath()}/index.ts`, {
1471
+ statements: namespaceExportDeclarations
1460
1472
  }, {
1461
1473
  overwrite: true
1462
1474
  });
@@ -1496,6 +1508,12 @@ function getExportDeclaration2(directory, sourceFile) {
1496
1508
  };
1497
1509
  }
1498
1510
  __name(getExportDeclaration2, "getExportDeclaration");
1511
+ function getNamespaceExportDeclaration(directory, sourceDirectory) {
1512
+ return {
1513
+ kind: import_ts_morph7.StructureKind.ExportDeclaration,
1514
+ moduleSpecifier: directory.getRelativePathAsModuleSpecifierTo(sourceDirectory)
1515
+ };
1516
+ }
1499
1517
 
1500
1518
  // src/handlers/register-enum.ts
1501
1519
  var import_ts_morph8 = require("ts-morph");
@@ -1567,6 +1585,7 @@ function warning(message) {
1567
1585
  var import_assert5 = require("assert");
1568
1586
  var import_filenamify = __toESM(require("filenamify"));
1569
1587
  var import_flat = require("flat");
1588
+ var import_fs2 = require("fs");
1570
1589
  var import_json55 = __toESM(require("json5"));
1571
1590
  var import_lodash7 = require("lodash");
1572
1591
  var import_outmatch3 = __toESM(require("outmatch"));
@@ -1628,7 +1647,7 @@ function createConfig(data) {
1628
1647
  }
1629
1648
  return {
1630
1649
  outputFilePattern,
1631
- tsConfigFilePath: void 0,
1650
+ tsConfigFilePath: createTsConfigFilePathValue(config.tsConfigFilePath),
1632
1651
  combineScalarFilters: toBoolean(config.combineScalarFilters),
1633
1652
  noAtomicOperations: toBoolean(config.noAtomicOperations),
1634
1653
  reExport: ReExport[String(config.reExport)] || ReExport.None,
@@ -1644,6 +1663,15 @@ function createConfig(data) {
1644
1663
  decorate
1645
1664
  };
1646
1665
  }
1666
+ var tsConfigFileExists = (0, import_lodash7.memoize)((filePath) => {
1667
+ return (0, import_fs2.existsSync)(filePath);
1668
+ });
1669
+ function createTsConfigFilePathValue(value) {
1670
+ if (typeof value === "string")
1671
+ return value;
1672
+ if (tsConfigFileExists("tsconfig.json"))
1673
+ return "tsconfig.json";
1674
+ }
1647
1675
  function createUseInputType(data) {
1648
1676
  if (!data) {
1649
1677
  return [];
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "prisma-nestjs-graphql",
3
- "version": "15.1.0",
3
+ "version": "15.2.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
  "main": "index.js",
7
- "bin": "index.js",
7
+ "bin": "bin.js",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/unlight/nestjs-graphql-prisma.git"