multimeric / AmplifyCountDirective

Count the number of items in your DynamoDB tables using Amplify
12 stars 1 forks source link

Support Query calls to Dynamo #1

Open multimeric opened 2 years ago

multimeric commented 2 years ago

This would speed up the count function for users who have GSIs.

Implementers should look into how Amplify performs the conditional logic using VTL: https://github.com/aws-amplify/amplify-cli/blob/fcf9100c778e98e16f0ed695112f2a7251aca06a/packages/amplify-graphql-model-transformer/src/resolvers/query.ts#L141-L155.

#if( !$util.isNull($ctx.stash.modelQueryExpression) && !$util.isNullOrEmpty($ctx.stash.modelQueryExpression.expression) )
  $util.qr($ListRequest.put("operation", "Query"))
  $util.qr($ListRequest.put("query", $ctx.stash.modelQueryExpression))
  #if( !$util.isNull($args.sortDirection) && $args.sortDirection == "DESC" )
    #set( $ListRequest.scanIndexForward = false )
  #else
    #set( $ListRequest.scanIndexForward = true )
  #end
#else
  $util.qr($ListRequest.put("operation", "Scan"))
#end
multimeric commented 2 years ago

This would also require generating a few new Query subtypes like countByRepresentative.

multimeric commented 2 years ago

Ideally this would be implemented as a @count directive on the individual index fields. It should check if they also have the @index directive and fail if they do not.

Tedsterh commented 2 years ago

I believe I have added a way to use @count on Fields as well, its in a fork at the moment as I'm not what the next steps are, I am unable to install it in my area as I get an npm error. If you could take a look and let me know what I need to do to test this and or get it in here.

I have also added a variable to the Directive called CountType as there is a DISTINCT query on DynamoDB that might be quite useful

multimeric commented 2 years ago

Can you open a pull request please?