Да, можно фильтровать данные из вашего источника данных HTTP. Один из способов, который я могу придумать, - это использовать условие if / else в шаблоне ответа для фильтрации необходимых вам данных. что-то вроде этого;
{
"data" :
[
{"item" : "ItemA", "price" : 20},
{"item" : "ItemB", "price" : 10},
{"item" : "ItemC", "price" : 9},
{"item" : "ItemD", "price" : 8}
]
}
Затем в своем шаблоне ответа вы можете сделать что-то вроде:
#set($resultList = [])
#set($resMap = {})
## Raise a GraphQL field error in case of a datasource invocation error
#if($ctx.error)
$util.error($ctx.error.message, $ctx.error.type)
#end
## If the response is not 200 then return an error. Else return the filtered data **
#if($ctx.result.statusCode == 200)
#foreach($item in $ctx.result.body.data)
#if($item.price < $ctx.args.price)
$util.qr($resultList.add($item))
#end
#end
$util.qr($resMap.put("result", $resultList))
#return($resMap)
#else
$utils.appendError($ctx.result.body, "$ctx.result.statusCode")
#end
Ожидаемый результат:
{
"result" :
[
{"item" : "ItemC", "price" : 9},
{"item" : "ItemD", "price" : 8}
]
}
Надеюсь, это поможет.