multimeric / amplifycountdirective Goto Github PK
View Code? Open in Web Editor NEWCount the number of items in your DynamoDB tables using Amplify
Count the number of items in your DynamoDB tables using Amplify
I get this error after adding the directive to more than one model, I am able to push successfully when it is just the one.
An error occurred during the push operation: There is already a Construct with name '[object Object]CountResolver' in TransformerNestedStack [countResolverStack]
I am not doing anything other than running amplify push
A query like this:
{
countFoo(filter: {})
}
Will result in:
{
"data": {
"countFoo": null
},
"errors": [
{
"path": [
"countFoo"
],
"data": null,
"errorType": "Lambda:Unhandled",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "ExpressionAttributeNames must not be empty"
}
]
}
We can obtain a rough item count using the describeTable
API call on Dynamo. This can be used to very quickly return the number of items in the table when no filters are needed. This could possibly be made even faster by doing this using VTL and not using Lambda at all.
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
Hi, sorry its me again,
So I am able to call searchTraits
and listTraits
from inside the function but I cannot call countTraits
, I am also unable to use the an apiKey to call the count even though my model has the correct auth on it.
I have tried to remove permissions and add them again, but no luck.
This would then allow countFoo
to work like listFoo
with the auth filter. This basically just involves applying this logic:
#if( !$util.isNullOrEmpty($ctx.stash.authFilter) )
#set( $filter = $ctx.stash.authFilter )
#if( !$util.isNullOrEmpty($args.filter) )
#set( $filter = {
"and": [$filter, $args.filter]
} )
#end
e.g. if your model is called Hit
, it will generate listHits
but only countHit
.
Might have to look into how this is done by Amplify: https://github.com/aws-amplify/amplify-cli/blob/fcf9100c778e98e16f0ed695112f2a7251aca06a/packages/amplify-graphql-model-transformer/src/graphql-model-transformer.ts
Hi,
I am trying to filter based on wether an attribute exists or not, if I use an and statement alongside the attributeExists
I am able to get a count but on its own it throws and error
"errors": [
{
"path": [
"fuseable"
],
"data": null,
"errorType": "Lambda:Unhandled",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "ExpressionAttributeValues must not be empty"
}
]
How can I controll iam auth for @count? I want to get count over IAM. It is not working.
My schema:
@count
@model
@auth(rules: [
{allow: public, provider: iam},
{allow: groups, groups: ["admin"], operations: [create,delete,read,update]}
])
{
id: ID!
caption: String
video: Video! @hasOne
userId: Ticket! @hasOne
LikeSuggestions: [LikeSuggestion] @hasMany(indexName: "bySignSuggestion", fields: ["id"])
approvalStatus: ApprovalStatusEnum!
reasonForRejection: String,
updatedAt: AWSDateTime!
}```
Hi,
I updated my Amplify CLI from 7.6.4 to v. 9.2.1 and got this:
Unable to import custom transformer module(amplify-count-directive).
๐ You may fix this error by editing transformers at amplify-count-directive/transform.conf.json
here my transform.conf.json
{
"Version": 5,
"ElasticsearchWarning": true,
"transformers": [
"amplify-count-directive"
]
}
With previous version I had no problem.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.