entc/gen: propagate nodes post-save mutations (#2525)

* Failing test

* Fix propagating entirely models from OpCreate hook

* Apply suggestions from code review

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* whitespace

* Failing test for updateone

* fix for updateone

* Regnerate

* regen from root

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
Justin Johnson
2022-05-05 01:19:21 -07:00
committed by GitHub
parent 240a43e7a2
commit 38d4d5fb5c
215 changed files with 1557 additions and 214 deletions

View File

@@ -79,9 +79,15 @@ func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
}
mut = uc.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, uc.mutation); err != nil {
v, err := mut.Mutate(ctx, uc.mutation)
if err != nil {
return nil, err
}
nv, ok := v.(*User)
if !ok {
return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v)
}
node = nv
}
return node, err
}

View File

@@ -199,9 +199,15 @@ func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
}
mut = uuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
v, err := mut.Mutate(ctx, uuo.mutation)
if err != nil {
return nil, err
}
nv, ok := v.(*User)
if !ok {
return nil, fmt.Errorf("unexpected node type %T returned from UserMutation", v)
}
node = nv
}
return node, err
}