[PATCH meta.sr.ht] api: fix webhooks being called with outdated data
Export this patch
When a user updates their profile, the database gets updated
accordingly, but the webhooks get called with data retrieved before the
update.
Make the update statement return the new values and apply them to the
user object that gets passed to the webhooks.
I believe this will resolve this ticket:
https://todo.sr.ht/~sircmpwn/meta.sr.ht/192
---
api/graph/schema.resolvers.go | 5 +++ --
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go
index d81a4ba..5c2ed91 100644
--- a/api/graph/schema.resolvers.go
+++ b/api/graph/schema.resolvers.go
@@ -121,13 +121,14 @@ func (r *mutationResolver) UpdateUser(ctx context.Context, input map[string]inte
var err error
if len(input) != 0 {
- _, err = query.
+ err = query.
Where(database.WithAlias(user.Alias(), `id`)+"= ?",
auth.ForContext(ctx).UserID).
Set(database.WithAlias(user.Alias(), `updated`),
sq.Expr(`now() at time zone 'utc'`)).
+ Suffix(`RETURNING url, location, bio`).
RunWith(tx).
- ExecContext(ctx)
+ ScanContext(ctx, &user.URL, &user.Location, &user.Bio)
if err != nil {
return err
}
--
2.37.1
Thanks!
To git@git.sr.ht:~sircmpwn/meta.sr.ht
085a966..9d9fed0 master -> master