aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

Support Set Types in GraphQL Schema backed by DynamoDB #212

Open iyz91 opened 3 years ago

iyz91 commented 3 years ago

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

nathanagez commented 3 years ago

any updates on this feature ?

hackrx commented 3 years ago

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.

alextriaca commented 3 years ago

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

wvidana commented 2 years ago

Please, this would be really helpful 🙏

rideddy84 commented 2 years ago

Vote +1

charlieforward9 commented 9 months ago

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?

izner32 commented 5 months ago

+1

codenimble commented 6 days ago

+1