Fix missing RowsAffected checks in cookie update methods
Address PR review comments: capture Exec result and check RowsAffected() == 0 to return ErrResourceNotFound in Cookie.Update, CookieCategory.Update, and CookieCategory.UpdateRank. Also update coredata and relay contributor docs accordingly. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -129,7 +129,13 @@ assets, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Asset])
|
|||||||
*a = assets
|
*a = assets
|
||||||
|
|
||||||
// Update / Delete — no RETURNING
|
// Update / Delete — no RETURNING
|
||||||
_, err := conn.Exec(ctx, q, args)
|
result, err := conn.Exec(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if result.RowsAffected() == 0 {
|
||||||
|
return ErrResourceNotFound
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Sentinel errors
|
## Sentinel errors
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ Relay directives handle connection updates automatically — no manual store man
|
|||||||
|
|
||||||
#### Connection setup
|
#### Connection setup
|
||||||
|
|
||||||
Any connection that a mutation will add to or remove from **must** have a `@connection` directive and expose `__id`:
|
Any connection that a mutation will add to or remove from **must** have a `@connection` directive. If the mutation needs the connection ID in the same fragment, expose `__id`; otherwise derive it with `ConnectionHandler.getConnectionID`:
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
const fragment = graphql`
|
const fragment = graphql`
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ WHERE
|
|||||||
}
|
}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
_, err := tx.Exec(ctx, q, args)
|
result, err := tx.Exec(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok {
|
||||||
if pgErr.Code == "23505" && pgErr.ConstraintName == "idx_cookies_unique_name_per_banner" {
|
if pgErr.Code == "23505" && pgErr.ConstraintName == "idx_cookies_unique_name_per_banner" {
|
||||||
@@ -337,6 +337,10 @@ WHERE
|
|||||||
return fmt.Errorf("cannot update cookie: %w", err)
|
return fmt.Errorf("cannot update cookie: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if result.RowsAffected() == 0 {
|
||||||
|
return ErrResourceNotFound
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -341,11 +341,15 @@ WHERE
|
|||||||
}
|
}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
_, err := tx.Exec(ctx, q, args)
|
result, err := tx.Exec(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot update cookie category: %w", err)
|
return fmt.Errorf("cannot update cookie category: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if result.RowsAffected() == 0 {
|
||||||
|
return ErrResourceNotFound
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,11 +394,15 @@ WHERE %s
|
|||||||
}
|
}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
_, err := tx.Exec(ctx, q, args)
|
result, err := tx.Exec(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot update cookie category rank: %w", err)
|
return fmt.Errorf("cannot update cookie category rank: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if result.RowsAffected() == 0 {
|
||||||
|
return ErrResourceNotFound
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user