aws / aws/aws-appsync-community

Feature Request: new RDS util for converting ctx.args to comma separated list of SQL update values

Open
#60 12 comments 0 reactions 0 assignees View on GitHub
feature-request
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

I have an update mutation resolver with the following as its request template:

```
#set ($updates = "")

#if ($ctx.args.name)
#set ($updates = "$updates, name = '$ctx.args.name'")
#end

#if ($ctx.args.duration)
#set ($updates = "$updates, duration = $ctx.args.duration")
#end

{
"version": "2018-05-29",
"statements": [
"UPDATE tracks SET $updates.substring(1) WHERE id = $ctx.args.id AND owner_id = '$ctx.identity.username' RETURNING *"
]
}
```

This works fine, but is a little clunky, and could really get out of hand if I were updating 10+ columns. It would be nice to have a built-in util to convert specific args into a list of column/value pairs for using with SQL's `UPDATE`, e.g.:

```
#set ($updates = $util.rds.argsToValuePairs($ctx.args, ["name", "duration"]))

{
"version": "2018-05-29",
"statements": [
"UPDATE tracks SET $updates WHERE id = $ctx.args.id AND owner_id = '$ctx.identity.username' RETURNING *"
]
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the requested $util.rds.argsToValuePairs helper and the example request template in the issue. Review the existing RDS utility surface and related project conventions before defining the argument-selection and SQL value-pair behavior. Done means the helper supports the shown update use case and its behavior is covered by appropriate project tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, sql
Domain
api, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.