schema/mixin: add support for mixed-in annotations

This commit is contained in:
Ariel Mashraki
2020-10-11 21:06:10 +03:00
committed by Ariel Mashraki
parent 85c4999472
commit c8a6527612
5 changed files with 38 additions and 8 deletions

View File

@@ -158,12 +158,13 @@ func MarshalSchema(schema ent.Interface) (b []byte, err error) {
Name: indirect(reflect.TypeOf(schema)).Name(),
Annotations: make(map[string]interface{}),
}
for _, at := range schema.Annotations() {
s.Annotations[at.Name()] = at
}
if err := s.loadMixin(schema); err != nil {
return nil, fmt.Errorf("schema %q: %v", s.Name, err)
}
// Schema annotations override mixed-in annotations.
for _, at := range schema.Annotations() {
s.Annotations[at.Name()] = at
}
if err := s.loadFields(schema); err != nil {
return nil, fmt.Errorf("schema %q: %v", s.Name, err)
}
@@ -263,6 +264,9 @@ func (s *Schema) loadMixin(schema ent.Interface) error {
MixinIndex: i,
})
}
for _, at := range mx.Annotations() {
s.Annotations[at.Name()] = at
}
}
return nil
}