Data live in DynamoDB however AppSync list query doesn't show some of the data
See original GitHub issueDescribe the bug I have an AWS Amplify app in which I add a GraghQL backend and create the model like this:
type Item @model @auth(rules: [{allow: owner}]) {
id: ID!
inventoryType: String!
itemName: String!
imgKey: String
}
Inside my app I allow users to create an item via submitting a form, by calling API.graphqlOperation(createItemMutation, newItem)
. This works well, because after users submit the form, I can find new items be created in DynamoDB.
After this, I go to AppSync console, I login via Cognito user pool as user A, the following query doesn’t show some of created items:
query {
listItems {
items {
id
inventoryType
itemName
}
}
}
What I get:
{
"data": {
"listItems": {
"items": [
{
"itemName": "2015 book"
},
{
"itemName": "Sundaya 0845"
},
...
]
}
}
}
Some newly created item will be shown, while some not (e.g., one with item name “Sunday 0845 2”) - and I guarantee they are from the same user so that auth is not the root cause. I cannot figure out the show/not show pattern. However, I can always show the created item by get with id:
query {
getItem(id: "72eee5e9-c1f5-4860-8a52-d846ec7d7a54") {
id
inventoryType
itemName
}
}
What I get:
{
"data": {
"getItem": {
"id": "72eee5e9-c1f5-4860-8a52-d846ec7d7a54",
"inventoryType": "apparels",
"itemName": "Sunday 0845 2"
}
}
}
To Reproduce I am not sure how can one reproduce. The result is somewhat un-deterministic.
You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = ‘DEBUG’; in your app.
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (3 by maintainers)
This has to be a joke. Working with dynamoDb along with appsync in amplify always seem to be doing un-intuitive things. If i’m passing filter expression along with limit, i would want to limit the filtered result instead of filtering the limited result. Can anyone provide an alternate resolver mappings? @YikSanChan
Current default mapping templates in amplify are : - query.listRounds.req.vtl:-
#set( $limit = $util.defaultIfNull($context.args.limit, 10) ) #set( $ListRequest = { “version”: “2017-02-28”, “limit”: $limit } ) #if( $context.args.nextToken ) #set( $ListRequest.nextToken = “$context.args.nextToken” ) #end #if( $context.args.filter ) #set( $ListRequest.filter = $util.parseJson(“$util.transform.toDynamoDBFilterExpression($ctx.args.filter)”) ) #end #if( !$util.isNull($modelQueryExpression) && !$util.isNullOrEmpty($modelQueryExpression.expression) ) $util.qr($ListRequest.put(“operation”, “Query”)) $util.qr($ListRequest.put(“query”, $modelQueryExpression)) #else $util.qr($ListRequest.put(“operation”, “Scan”)) #end $util.toJson($ListRequest)
and query.listRounds.res.vtl:- $util.toJson($ctx.result)
Hey, @manueliglesias I believe I figured out the reason.
I list items filtered by inventory type and I expect to apply the limit after I get all items fit the criteria (
{inventoryType: {eq: "books"}}
). However, dynamodb apply the limit before I get all items. Same issue as described here.Any walkaround other than setting a very large limit and pray it works? Thanks!