Skip to content

Commit

Permalink
fix: Combine scalars option with nullable relation filter
Browse files Browse the repository at this point in the history
  • Loading branch information
unlight committed Jul 24, 2023
1 parent 6a9cb7f commit 471c405
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
12 changes: 6 additions & 6 deletions Taskfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ compatibilty_check() {
set -x
rm -rf ./@generated && npm run prisma:g && npm run tscheck

echo Check noAtomicOperations
echo === Check noAtomicOperations ===
sed -i 's/noAtomicOperations *= false/noAtomicOperations = true/g' prisma/schema.prisma
rm -rf ./@generated && npm run prisma:g && npm run tscheck
sed -i 's/noAtomicOperations *= true/noAtomicOperations = false/g' prisma/schema.prisma

echo Check combineScalarFilters
echo === Check combineScalarFilters ===
sed -i 's/combineScalarFilters *= false/combineScalarFilters = true/g' prisma/schema.prisma
rm -rf ./@generated && npm run prisma:g && npm run tscheck
sed -i 's/combineScalarFilters *= true/combineScalarFilters = false/g' prisma/schema.prisma

echo Check Switching reExport
echo === Switching reExport ===
sed -i 's/reExport *= None/reExport = All/g' prisma/schema.prisma
rm -rf ./@generated && npm run prisma:g && npm run tscheck
sed -i 's/reExport *= All/reExport = None/g' prisma/schema.prisma

echo Check emitSingle
echo === Check emitSingle ===
sed -i 's/emitSingle *= false/emitSingle = true/g' prisma/schema.prisma
rm -rf ./@generated && npm run prisma:g
npx tsc --noEmit --skipLibCheck --experimentalDecorators ./@generated/index.ts
npx ts-node ./@generated/index.ts

echo Check emitCompiled
echo === Check emitCompiled ===
sed -i 's/emitCompiled *= false/emitCompiled = true/g' prisma/schema.prisma
rm -rf ./@generated && npm run prisma:g
node ./@generated/index.js

sed -i 's/emitCompiled *= true/emitCompiled = false/g' prisma/schema.prisma
sed -i 's/emitSingle *= true/emitSingle = false/g' prisma/schema.prisma

echo Check requireSingleFieldsInWhereUniqueInput
echo === Check requireSingleFieldsInWhereUniqueInput ===
sed -i 's/requireSingleFieldsInWhereUniqueInput *= false/requireSingleFieldsInWhereUniqueInput = true/g' prisma/schema.prisma
rm -rf ./@generated && npm run prisma:g && npm run tscheck
sed -i 's/requireSingleFieldsInWhereUniqueInput *= true/requireSingleFieldsInWhereUniqueInput = false/g' prisma/schema.prisma
Expand Down
10 changes: 8 additions & 2 deletions src/handlers/combine-scalar-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function beforeGenerateField(field: DMMF.SchemaArg): void {
}

function replaceBogus(name: string) {
return name.replaceAll(/(Nullable|Nested)/g, '');
return name.replaceAll(/Nullable|Nested/g, '');
}

function isContainBogus(name: string) {
Expand All @@ -66,7 +66,7 @@ function isScalarFilter(inputType: InputType) {
}

function postBegin(args: EventArguments) {
const { schema } = args;
const { schema, modelNames } = args;
const inputTypes = schema.inputObjectTypes.prisma;
const enumTypes = schema.enumTypes.model || [];
const types = [
Expand Down Expand Up @@ -117,5 +117,11 @@ function postBegin(args: EventArguments) {
]);
}

for (const modelName of modelNames) {
replaceBogusFilters(`${modelName}RelationFilter`, [
`${modelName}NullableRelationFilter`,
]);
}

remove(inputTypes, inputType => isContainBogus(inputType.name));
}
23 changes: 23 additions & 0 deletions src/test/combine-scalar-filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,26 @@ describe('combine scalar filters on array', () => {
'no errors';
});
});

describe('empty relation filter input', () => {
before(async () => {
({ project, sourceFiles } = await testGenerate({
schema: `
model Article {
id String @id @default(cuid())
comments Comment[]
}
model Comment {
id String @id @default(cuid())
article Article? @relation(fields: [articleId], references: [id])
articleId String?
}
`,
options: [`combineScalarFilters = true`],
}));
});

it('smoke', () => {
'no errors';
});
});

0 comments on commit 471c405

Please sign in to comment.