amplify-category-api
amplify-category-api copied to clipboard
Support Set Types in GraphQL Schema backed by DynamoDB
Is your feature request related to a problem? Please describe. For AppSync GraphQL API backed by DynamoDB, it can be useful and potentially more performant to allow sets (e.g. string set) for fields that fit.
Describe the solution you'd like
An ideal implementation would be some sort of directive like @set that would apply the correct DynamoDB helper inferred from the field type. For example, members: [String!] @set would implement $util.dynamodb.toStringSetJson() in the mutation's request template and elsewhere. Alternatively, @stringset would also work to skip the inferring step.
Additional context By default, Amplify's GQL transformer utilizes $util.dynamodb.toMapValuesJson(Map) which is "opinionated about how it represents some of the nested objects: e.g., it will use lists (“L”) rather than sets (“SS”, “NS”, “BS”)." (here).
any updates on this feature ?
Hi @iyz91, did you found any workaround for this, I want to store blogHashtags as string set in DynamoDB, but it is not allowing me to do so.
In amplify I have blogHashtags as [String] and in Schema we can't use @set directive.
For now I am passing blogHashtags as a list of string and using $util.qr($ctx.args.input.put("blogHashtags",$util.dynamodb.toStringSet($ctx.args.input.blogHashtags))) but it is storing the values in table like this:
input: {blogHashtags: ["car","bike","cycle","bike","car"] }
Actually I don't want to keep duplicate hashtag in blogHashtags, and I want to perform this set conversion on the backend.
I want to store it like this (stored manually)
Inside the template, set conversion must remove any duplicates present in the array.
Thanks.
I recently had to solve a similar problem to dedup error codes from the backend. Don't think this is the optimal solution but it seems to work OK:
#set($results = [])
#set($previous = "")
#foreach($error in $util.list.sortList($ctx.result.items,false, ""))
#if($error != $previous)
$util.qr($results.add($error))
#set($previous = $error)
#end
#end
The $util.list.sortList function is documented here (https://docs.aws.amazon.com/appsync/latest/devguide/resolver-util-reference.html).
Please, this would be really helpful 🙏
Vote +1
Subscribing to this to promote its demand.
Seems like the graphql-transformer-v1 label is no longer relevant and potentially lessening the visibility of this feature request. Should the label be updated?
+1
+1