Skip to content

Commit

Permalink
fix: disallow extending from multiple delegate models (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Mar 13, 2024
1 parent b63589a commit a662107
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { validateDuplicatedDeclarations } from './utils';
export default class DataModelValidator implements AstValidator<DataModel> {
validate(dm: DataModel, accept: ValidationAcceptor): void {
this.validateBaseAbstractModel(dm, accept);
this.validateBaseDelegateModel(dm, accept);
validateDuplicatedDeclarations(dm, getModelFieldsWithBases(dm), accept);
this.validateAttributes(dm, accept);
this.validateFields(dm, accept);
Expand Down Expand Up @@ -396,6 +397,15 @@ export default class DataModelValidator implements AstValidator<DataModel> {
);
});
}

private validateBaseDelegateModel(model: DataModel, accept: ValidationAcceptor) {
if (model.superTypes.filter((base) => base.ref && isDelegateModel(base.ref)).length > 1) {
accept('error', 'Extending from multiple delegate models is not supported', {
node: model,
property: 'superTypes',
});
}
}
}

export interface MissingOppositeRelationData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,4 +714,28 @@ describe('Data Model Validation Tests', () => {
errorLike(`The relation field "user" on model "A" is missing an opposite relation field on model "User"`)
);
});

it('delegate base type', async () => {
const errors = await safelyLoadModel(`
${prelude}
model Base1 {
id String @id
type String
@@delegate(type)
}
model Base2 {
id String @id
type String
@@delegate(type)
}
model A extends Base1,Base2 {
a String
}
`);

expect(errors).toMatchObject(errorLike(`Extending from multiple delegate models is not supported`));
});
});

0 comments on commit a662107

Please sign in to comment.