Skip to content

Commit

Permalink
fix(delegate): remove createMany from delegate input types (#1619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Jul 28, 2024
1 parent d0fd350 commit e01751d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/schema/src/plugins/enhancer/enhance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,12 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara
const typeName = typeAlias.getName();
const delegateModelNames = delegateModels.map(([delegate]) => delegate.name);
const delegateCreateUpdateInputRegex = new RegExp(
`\\${delegateModelNames.join('|')}(Unchecked)?(Create|Update).*Input`
`^(${delegateModelNames.join('|')})(Unchecked)?(Create|Update).*Input$`
);
if (delegateCreateUpdateInputRegex.test(typeName)) {
const toRemove = typeAlias
.getDescendantsOfKind(SyntaxKind.PropertySignature)
.filter((p) => ['create', 'connectOrCreate', 'upsert'].includes(p.getName()));
.filter((p) => ['create', 'createMany', 'connectOrCreate', 'upsert'].includes(p.getName()));
toRemove.forEach((r) => {
source = source.replace(r.getText(), '');
});
Expand Down Expand Up @@ -543,6 +543,10 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara
return source;
}

private readonly CreateUpdateWithoutDelegateRelationRegex = new RegExp(
`(.+)(Create|Update)Without${upperCaseFirst(DELEGATE_AUX_RELATION_PREFIX)}_(.+)Input`
);

private removeDelegateFieldsFromNestedMutationInput(
typeAlias: TypeAliasDeclaration,
_delegateInfo: DelegateInfo,
Expand All @@ -553,8 +557,7 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara
// remove delegate model fields (and corresponding fk fields) from
// create/update input types nested inside concrete models

const regex = new RegExp(`(.+)(Create|Update)Without${upperCaseFirst(DELEGATE_AUX_RELATION_PREFIX)}_(.+)Input`);
const match = name.match(regex);
const match = name.match(this.CreateUpdateWithoutDelegateRelationRegex);
if (!match) {
return source;
}
Expand Down

0 comments on commit e01751d

Please sign in to comment.