question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data live in DynamoDB however AppSync list query doesn't show some of the data

See original GitHub issue

Describe 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:closed
  • Created 5 years ago
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
artista7commented, Jul 28, 2019

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)

3reactions
YikSanChancommented, Dec 5, 2018

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS AppSync not returning all the records from DynamoDB
When I am running a listAll query, however, I see very random data on the screen limited to 20 records. When I investigated...
Read more >
AWS AppSync query returns wrong item number with ...
My list queries are returning the wrong number of items when I use Amazon DynamoDB with AWS AppSync. How do I resolve this?...
Read more >
DynamoDB design patterns with GraphQL APIs and AppSync
Organizations building modern applications are increasingly turning to serverless API architectures powered by GraphQL and NoSQL databases ...
Read more >
GraphQL API ft. AWS AppSync and Amazon DynamoDB
This video covers how to leverage AWS AppSync to expose Amazon DynamoDb data via GraphQL API Links======= AWS AppSync...
Read more >
AWS AppSync - The Ultimate Guide - Serverless Framework
The supported request types are queries (for getting data from the API), mutations (for changing data via the API), and subscriptions (long-lived ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found