Skip to content

Commit

Permalink
fix: Adapted to Prisma 5.14
Browse files Browse the repository at this point in the history
close: #214
  • Loading branch information
unlight committed May 19, 2024
1 parent 5eba79c commit 35da088
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# max-parallel: 1
matrix:
node:
- 20
- 22
os:
- ubuntu-latest
# - windows-latest
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
- name: 'Setup Node'
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 22
- name: 'Install depependencies'
run: yarn install
- name: 'Build'
Expand Down
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
},
"dependencies": {
"@prisma/generator-helper": "^5.7.0",
"@prisma/generator-helper": "^5.14.0",
"await-event-emitter": "^2.0.2",
"filenamify": "4.X",
"flat": "5.X",
Expand All @@ -85,31 +85,31 @@
"devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@nestjs/apollo": "^12.0.11",
"@nestjs/common": "^10.2.10",
"@nestjs/core": "^10.2.10",
"@nestjs/graphql": "^12.0.11",
"@nestjs/platform-express": "^10.2.10",
"@nestjs/apollo": "^12.1.0",
"@nestjs/common": "^10.3.8",
"@nestjs/core": "^10.3.8",
"@nestjs/graphql": "^12.1.1",
"@nestjs/platform-express": "^10.3.8",
"@paljs/plugins": "^6.0.7",
"@prisma/client": "^5.7.0",
"@prisma/client": "^5.14.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.2.5",
"@swc/core": "^1.3.100",
"@swc/helpers": "^0.5.3",
"@swc/core": "^1.5.7",
"@swc/helpers": "^0.5.11",
"@swc/register": "^0.1.10",
"@types/flat": "^5.0.5",
"@types/graceful-fs": "^4.1.9",
"@types/lodash": "^4.14.202",
"@types/lodash": "^4.17.4",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.4",
"@types/node": "^20.12.12",
"@types/pluralize": "^0.0.33",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"apollo-server-express": "^3.13.0",
"c8": "^8.0.1",
"c8": "^9.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"class-validator": "^0.14.1",
"commitizen": "^4.3.0",
"cz-customizable": "^7.0.0",
"decimal.js": "^10.4.3",
Expand All @@ -118,33 +118,33 @@
"eslint-plugin-etc": "^2.0.3",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-regexp": "^2.1.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-regexp": "^2.5.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-sort-class-members": "^1.19.0",
"eslint-plugin-unicorn": "^49.0.0",
"eslint-plugin-sort-class-members": "^1.20.0",
"eslint-plugin-unicorn": "^53.0.0",
"eslint-plugin-wix-editor": "^3.3.0",
"expect": "^29.7.0",
"git-branch-is": "^4.0.0",
"graphql": "^16.8.1",
"graphql-scalars": "^1.22.4",
"graphql-scalars": "^1.23.0",
"graphql-type-json": "^0.3.2",
"mocha": "^10.2.0",
"mocha": "^10.4.0",
"ololog": "^1.1.175",
"pkgroll": "^2.0.1",
"pkgroll": "^2.1.0",
"precise-commits": "^1.0.2",
"prettier": "^3.1.1",
"prisma": "^5.7.0",
"prettier": "^3.2.5",
"prisma": "^5.14.0",
"prisma-graphql-type-decimal": "^3.0.0",
"reflect-metadata": "^0.1.12",
"reflect-metadata": "^0.2.2",
"request": "^2.88.2",
"rxjs": "^7.8.1",
"semantic-release": "^22.0.12",
"simplytyped": "^3.3.0",
"temp-dir": "2.X",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"typescript": "^5.4.5",
"watchexec-bin": "^1.0.0"
}
}
3 changes: 3 additions & 0 deletions src/handlers/args-type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isCreateManyReturn } from '../helpers/create-many-return';
import { pascalCase } from '../helpers/pascal-case';
import { EventArguments, InputType, SchemaField } from '../types';

Expand All @@ -9,6 +10,8 @@ export function argsType(field: SchemaField, args: EventArguments) {
if (['queryRaw', 'executeRaw'].includes(field.name)) {
return;
}
if (isCreateManyReturn(field.name)) return;

const { eventEmitter, typeNames, getModelName } = args;
let className = pascalCase(`${field.name}Args`);
const modelName = getModelName(className) || '';
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/model-output-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'ts-morph';

import { createComment } from '../helpers/create-comment';
import { isCreateManyReturn } from '../helpers/create-many-return';
import { getGraphqlImport } from '../helpers/get-graphql-import';
import { getOutputTypeName } from '../helpers/get-output-type-name';
import { getPropertyType } from '../helpers/get-property-type';
Expand All @@ -28,6 +29,9 @@ const nestjsGraphql = '@nestjs/graphql';
export function modelOutputType(outputType: OutputType, args: EventArguments) {
const { getSourceFile, models, config, modelFields, fieldSettings, eventEmitter } =
args;

if (isCreateManyReturn(outputType.name)) return;

const model = models.get(outputType.name);
ok(model, `Cannot find model by name ${outputType.name}`);

Expand Down
1 change: 1 addition & 0 deletions src/handlers/re-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function beforeGenerateFiles(args: EventArguments) {
if (config.reExport === ReExport.All) {
const exportDeclarations: ExportDeclarationStructure[] = [];
for (const directory of rootDirectory.getDirectories()) {
if (directory.getBaseName() === 'node_modules') continue;
const sourceFile = directory.getSourceFileOrThrow('index.ts');
exportDeclarations.push(getExportDeclaration(rootDirectory, sourceFile));
}
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/create-many-return.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function isCreateManyReturn(name: string): boolean {
const lowerName = name.toLowerCase();
if (
lowerName.startsWith('createmany') &&
(lowerName.endsWith('andreturnoutputtype') || lowerName.endsWith('andreturn'))
) {
return true;
}

return false;
}
11 changes: 5 additions & 6 deletions src/test/test-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ export async function testGenerate(args: {
.getBaseNameWithoutExtension()
.replaceAll('-', '')
.split('.')[0];
const sources = sourceFiles.filter(
s =>
s
.getClass(() => true)
?.getProperties()
.find(p => String(p.getStructure().type).toLowerCase().includes(fileLower)),
const sources = sourceFiles.filter(s =>
s
.getClass(() => true)
?.getProperties()
.find(p => String(p.getStructure().type).toLowerCase().includes(fileLower)),
);
if (sources.length > 0) {
message += `, reference: ${sources.map(s => s.getBaseName()).join(', ')}`;
Expand Down

0 comments on commit 35da088

Please sign in to comment.