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.

Auto-generated list resolver templates limits before filtering

See original GitHub issue

It was kinda weird discovering that auto-generated appsync list query resolvers limit the scanned result before it filters. Part of this weirdness could be attributed to ignorance on dynamo usage on my part but part of this is also due to un-intuitive behavior which was not expected.

I ran this particular query :-

query ListRounds{
  listRounds(
    limit:10,
    filter:{
    	jobOpeningId:{
    		eq:"jobOpening-Company1College1drive1"
      }
  	})
  {
    items{
      id
    }
    nextToken
  }
}

It did not return rounds, even though they exist as the filter was applied on the limited result.

The default request resolver is:-

#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)

Q1 - What is $modelQueryExpression in this template?

Q2 - How can this template be modified to use query expression with indexName i.e query instead of scan?

What AWS Services are you utilizing? aws-amplify version 1.7.8

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
RossWilliamscommented, Jul 28, 2019

Regarding Q1, that is an object that holds data only if you are doing a query operation in dynamodb. Its properties are populated here, it is set as the parameter ‘queryExprReference’ Because you are doing a scan operation, this value should not be set. If you expect your tables to be large, or be accessed frequently you will almost always want to be doing a query rather than a scan.

0reactions
github-actions[bot]commented, May 27, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API (GraphQL) - Overwrite & customize resolvers - Amplify Docs
GraphQL resolvers connect the fields in a type's schema to a data source. Resolvers are the mechanism by which requests are fulfilled.
Read more >
Practical use cases for AWS AppSync Pipeline Resolvers
Our request template uses a scan operation with a filter expression to narrow down the results for a given userId and list of...
Read more >
Appsync & GraphQL: how to filter a list by nested value
I have an Appsync API generated by Amplify from a basic schema. On the Article model, a category field is nested within a...
Read more >
With the Console - Appsync Immersion Day
The schema includes autogenerated queries, mutations, and subscriptions ... When used with DynamoDB resolvers, the limit is applied before any filtering is ...
Read more >
Implementing Search in GraphQL - Medium
The method we'll use in this tutorial is DynamoDB filters that are autogenerated for us when creating an AppSync API. For more advanced...
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