response resolver nesting foreach does not appear to work

0

I have a response resolver that looks like this snip

NOTE: This code runs inside a foreach

#elseif( $entry.get("_source").entity.bundle == "he_transaction" )
#if( $velocityCount > 1 ) , #end

#set( $counties = [])
#if(!$entry.get("_source").field_locations.isEmpty())
#if(!$entry.get("_source").field_locations.counties.isEmpty())
#foreach($county in $entry.get("_source").field_locations.counties)
$util.qr( $counties.add( { "name": $county } ) )
#end
#end
#end

    $util.toJson({  
        "__typename": "Transaction",  
        "id": $entry.get("_source").entity.nid,  
        "title": $entry.get("_source").title\[0].value,  
        "status": $entry.get("_source").entity.status,  
        "uri": { "uri": $entry.get("_source").entity.uri },  
        "changed": $entry.get("_source").entity.changed.value,  
        "closeDate": $entry.get("_source").field_close_date\[0].value,  
        "companies": \[],  
        "buyers": \[],  
        "marketers": \[],  
        "locationBasin": $entry.get("_source").field_location_basin\[0].value,  
        "locationField": $entry.get("_source").field_location_field\[0].value,  
        "locations": \[{  
            "countryCode" : $entry.get("_source").field_locations\[0].country_code,  
            "administrativeArea" : $entry.get("_source").field_locations\[0].administrative_area,  
            "locality": $entry.get("_source").field_locations\[0].locality,  
            "counties": $counties  
        }],  
        "price": {  
            "currency_code": "USD",  
            "number": 0.0  
        },  
        "types": \[],  
        "roomOpening": $entry.get("_source").field_room_opening_date.value,  
        "relatedContents": \[]  
    })  

==============================================
but when I run the query, counties is empty when I can see the result from ES has values in it like this

==============================================
"field_locations": [
{
"country_code": "US",
"administrative_area": "OK",
"counties": [
"Garvin",
"Grady",
"Logan",
"Mayes",
"McClain",
"Oklahoma",
"Texas & Woodward Cos."
]
}
],

Edited by: cjokinen on Jun 7, 2019 6:54 AM

질문됨 5년 전228회 조회
2개 답변
0

To help you better, please enable Logs (with Field Log Level - "ALL") for your API from the Settings page of your AppSync console. Execute the same query and check for the evaluated "Request" and "Response" Mapping Templates in the CloudWatch logs. This should give you some indication on why the counties is resolved to an empty array.

Also, if you still run into issues, please post the obfuscated Request/Response mapping content from your logs so I can help further.

AWS
답변함 5년 전
0

The "field_locations" is the section of the elastic search result that is used. But I just figured out my issue. I forgot to include the array on field_location. starting with the second #if and again in the #foreach I should of had field_locations[0]

답변함 5년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠