I am new to AWS AppSync and am trying to use an HTTP endpoint to fetch data from an external API. Here is an example of what that API returns.
{
"status": 1,
"size": 3,
"result": [
{
"number": "123",
"program": "program name",
"team_name": "team name",
"robot_name": "robot name",
"organisation": "team organization",
"city": "team city",
"region": "team state",
"country": "team country",
"grade": "team grade",
"is_registered": 0
},
{
"number": "456",
"program": "program name",
"team_name": "team name",
"robot_name": "robot name",
"organisation": "team organization",
"city": "team city",
"region": "team state",
"country": "team country",
"grade": "team grade",
"is_registered": 0
},
{
"number": "789",
"program": "program name",
"team_name": "team name",
"robot_name": "robot name",
"organisation": "team organization",
"city": "team city",
"region": "team state",
"country": "team country",
"grade": "team grade",
"is_registered": 0
}
]
}
Here is my GraphQL Schema
type Query {
getTeams(number: String!): Team
}
type Team {
number: String
program: String
teamName: String
robotName: String
organization: String
city: String
region: String
country: String
grade: String
isRegistered: Int
}
schema {
query: Query
}
Here is my request mapping template
{
"version": "2018-05-29",
"method": "GET",
"resourcePath": "/v1/get_teams",
"params":{
"query": {
"APIKEY": "API_KEY_GOES_HERE"
},
"headers": {
"Content-Type": "application/json"
}
}
}
And here is my response mapping template
#if($context.result.statusCode == 200)
## Success - decode the body and reconstruct the response with the schema in mind
#set($response = $util.parseJson($context.result.body))
#set($result = {
"number": $response.result[0].number,
"program": $response.result[0].program,
"teamName": $response.result[0].team_name,
"robotName": $response.result[0].robot_name,
"organization": $response.result[0].organisation,
"city": $response.result[0].city,
"region": $response.result[0].region,
"country": $response.result[0].country,
"grade": $response.result[0].grade,
"isRegistered": $response.result[0].is_registered
})
$util.toJson($result)
#else
## Error - send the proper error message
$utils.appendError($ctx.result.body, $ctx.result.statusCode)
#end
What I have currently worked but only returns one team. My question is how can I get the GraphQL query to return an array of teams by getting all of the items from the result array in the JSON file?