Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow extending from multiple delegate models #1117

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`));
});
});
Loading