amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Support Set Types in GraphQL Schema backed by DynamoDB

Open iyz91 opened this issue 4 years ago • 8 comments

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).

iyz91 avatar Feb 02 '21 00:02 iyz91

any updates on this feature ?

nathanagez avatar Jun 10 '21 04:06 nathanagez

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"] } image 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) image Inside the template, set conversion must remove any duplicates present in the array. Thanks.

hackrx avatar Jun 17 '21 19:06 hackrx

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).

alextriaca avatar Jun 18 '21 08:06 alextriaca

Please, this would be really helpful 🙏

wvidana avatar May 25 '22 14:05 wvidana

Vote +1

rideddy84 avatar Oct 31 '22 08:10 rideddy84

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?

charlieforward9 avatar Feb 07 '24 16:02 charlieforward9

+1

izner32 avatar May 25 '24 13:05 izner32

+1

codenimble avatar Nov 08 '24 07:11 codenimble