0

Below is the autogenerated resolver of appsync with DynamoDB. I am unable to understand what object I have to pass to use the Query operation.

#set( $limit = $util.defaultIfNull($context.args.limit, 100) )
#set( $ListRequest = {
  "version": "2018-05-29",
  "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))
  #if( !$util.isNull($ctx.args.sortDirection) && $ctx.args.sortDirection == "DESC" )
    #set( $ListRequest.scanIndexForward = false )
  #else
    #set( $ListRequest.scanIndexForward = true )
  #end
#else
  $util.qr($ListRequest.put("operation", "Scan"))
#end
$util.toJson($ListRequest)

I have tried to pass the below query but got the all data of table. I have also tried with simple filter scan it's working and returning the data but I want to use index.

            let modelQueryExpression = {
                "expression": "#bookingtype = :bookingtype AND #bookinguserid = :bookinguserid",
                "expressionNames": {
                    "#bookinguserid": "bookinguserid",
                    "#bookingtype": "bookingtype",
                },
                "expressionValues": {
                    ":bookingtype": {
                        "S": JSON.parse(user).id,
                    },
                    ":parent": {
                        "S": 'Trip',
                    },
                }
            }
            const bookingdata = await API.graphql({ query: listBookings, variables: { modelQueryExpression } });
Aryan
  • 3,338
  • 4
  • 18
  • 43

0 Answers0