amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

graphql list vs sync

Open ErikHochweller opened this issue 1 year ago β€’ 6 comments

Amplify CLI Version

10.7.3

Question

I have a table called surfaces, and when i run a list on it i get less results than when i run sync on it, f.e.

query MyQuery { listSurfaces(filter: {inquiryID: {eq: "48da725a-a7ae-4e91-a6c9-afdb03251138"}}) { items { inquiryID } } } i get no results, but when i run it with sync i get 3 results.

the same would be true tomorrow or next week. Why is the data not synced?

ErikHochweller avatar Apr 08 '24 09:04 ErikHochweller

i found it that when i go to the appsync resolver and change the limit from 100 to say 500 i get "more" results, still not all and nowhere near 500 (i know the table holds 860 at the moment) I also see that the nextToken is always the same?!? even if i use it to try to get the next set of results. Is that maybe the reason?

ErikHochweller avatar Apr 08 '24 09:04 ErikHochweller

and if it is, how can that be changed?

this my current resolver for list:

[Start] List Request. **

#set( $args = $util.defaultIfNull($ctx.stash.transformedArgs, $ctx.args) ) #set( $limit = $util.defaultIfNull($args.limit, 500) ) #set( $ListRequest = { "version": "2018-05-29", "limit": $limit } ) #if( $args.nextToken ) #set( $ListRequest.nextToken = $args.nextToken ) #end #if( !$util.isNullOrEmpty($ctx.stash.authFilter) ) #set( $filter = $ctx.stash.authFilter ) #if( !$util.isNullOrEmpty($args.filter) ) #set( $filter = { "and": [$filter, $args.filter] } ) #end #else #if( !$util.isNullOrEmpty($args.filter) ) #set( $filter = $args.filter ) #end #end #if( !$util.isNullOrEmpty($filter) ) #set( $filterExpression = $util.parseJson($util.transform.toDynamoDBFilterExpression($filter)) ) #if( $util.isNullOrEmpty($filterExpression) ) $util.error("Unable to process the filter expression", "Unrecognized Filter") #end #if( !$util.isNullOrBlank($filterExpression.expression) ) #if( $filterExpression.expressionValues.size() == 0 ) $util.qr($filterExpression.remove("expressionValues")) #end #set( $ListRequest.filter = $filterExpression ) #end #end #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 #if( !$util.isNull($ctx.stash.metadata.index) ) #set( $ListRequest.IndexName = $ctx.stash.metadata.index ) #end $util.toJson($ListRequest)

[End] List Request. **

ErikHochweller avatar Apr 08 '24 09:04 ErikHochweller

interestingly enough the nextToken response is always the same, nomatter the limit or even on a different table.

however on a different table it seems that at least i get more results back

ErikHochweller avatar Apr 08 '24 10:04 ErikHochweller

HeyπŸ‘‹ thanks for raising this! I'm going to transfer this over to our API repository for better assistance πŸ™‚. While the team dives into this, could you try upgrading to the latest version of Amplify CLI, 12.10.3 which should have the latest updates/bug fix and and retry.

ykethan avatar Apr 08 '24 19:04 ykethan

Hey @ErikHochweller, thank you for reaching out. Could you provide us the following information.

  1. Project identifier output when running amplify diagnose --send-report
  2. As @ykethan asked, does this still happen on the latest version of Amplify CLI (12.10.3)?
  3. Does this happen only on clients, or also from the AppSync query console? If only on clients, what client are you using, and what version?

palpatim avatar May 09 '24 17:05 palpatim

(Repasting the resolver above with code formatting)

## [Start] List Request. **
#set( $args = $util.defaultIfNull($ctx.stash.transformedArgs, $ctx.args) )
#set( $limit = $util.defaultIfNull($args.limit, 500) )
#set( $ListRequest = {
  "version": "2018-05-29",
  "limit": $limit
} )
#if( $args.nextToken )
  #set( $ListRequest.nextToken = $args.nextToken )
#end
#if( !$util.isNullOrEmpty($ctx.stash.authFilter) )
  #set( $filter = $ctx.stash.authFilter )
  #if( !$util.isNullOrEmpty($args.filter) )
    #set( $filter = {
  "and":   [$filter, $args.filter]
} )
  #end
#else
  #if( !$util.isNullOrEmpty($args.filter) )
    #set( $filter = $args.filter )
  #end
#end
#if( !$util.isNullOrEmpty($filter) )
  #set( $filterExpression = $util.parseJson($util.transform.toDynamoDBFilterExpression($filter)) )
  #if( $util.isNullOrEmpty($filterExpression) )
    $util.error("Unable to process the filter expression", "Unrecognized Filter")
  #end
  #if( !$util.isNullOrBlank($filterExpression.expression) )
    #if( $filterExpression.expressionValues.size() == 0 )
      $util.qr($filterExpression.remove("expressionValues"))
    #end
    #set( $ListRequest.filter = $filterExpression )
  #end
#end
#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
#if( !$util.isNull($ctx.stash.metadata.index) )
  #set( $ListRequest.IndexName = $ctx.stash.metadata.index )
#end
$util.toJson($ListRequest)
## [End] List Request. **

palpatim avatar May 09 '24 17:05 palpatim

Hey πŸ‘‹ , This issue is being closed due to inactivity. If you are still experiencing the same problem and need further assistance, please feel free to leave a comment. This will enable us to reopen the issue and provide you with the necessary support.

AnilMaktala avatar May 28 '24 13:05 AnilMaktala

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar May 28 '24 13:05 github-actions[bot]