I have a AppSync API that is linked to a lambda function as data source, the lambda function is calling another API to retrieve data from Database.
However after I setup the schema and resolver as well as the lambda function, it kept return me null result despite I have the actual result in my lambda function. (I printed it in logs so I can see it)
Here is my schema:
scalar AWSDateTime
type Event implements Node {
appId: String!
description: String
eventName: String!
id: String!
nodeId: ID!
ts: AWSDateTime!
}
input EventCondition {
appId: String
description: String
eventName: String
id: String
ts: AWSDateTime
}
type EventsConnection {
nodes: [Event!]!
totalCount: Int!
}
enum EventsOrderBy {
APP_ID_ASC
APP_ID_DESC
DESCRIPTION_ASC
DESCRIPTION_DESC
EVENT_NAME_ASC
EVENT_NAME_DESC
ID_ASC
ID_DESC
NATURAL
PRIMARY_KEY_ASC
PRIMARY_KEY_DESC
}
interface Node {
nodeId: ID!
}
type Query implements Node {
event(id: String!): Event
eventByNodeId(nodeId: ID!): Event
events(
condition: EventCondition,
first: Int,
last: Int,
offset: Int,
orderBy: [EventsOrderBy!]
): EventsConnection
node(nodeId: ID!): Node
nodeId: ID!
query: Query!
}
Here is my resolver request mapping for events, I hardcoded it so I can test:
{
"version" : "2017-02-28",
"operation": "Invoke",
"payload": {
"fieldName": "events",
"parentTypeName": "query",
"selectionSetGraphQL": "{\n nodes\n {\n id\n appId\n eventName\n }\n}"
}
}
Here is my response mapping template:
$util.toJson($context.result)
I expect it directly returns what Lambda Function return which is an object, but it is not. Here is what my lambda function have:
const client = new GraphQLClient(eventsGraphQLURI, { headers: {} })
client.request(request).then(
(data) => {
response = data;
console.log(`Result: ${JSON.stringify(response)}`)
})
.catch((error) => {
console.log(`Error Occurred: ${error}`)
})
return response;
When I check the logs, this is what the API return to my Lambda Function:
{
"events": {
"nodes": [
{
"id": "1e8601cf-a740-4146-a9b7-a38201a89eab",
"appId": "2fa39c1e-5b40-4a77-bab3-d22a79f051a7",
"eventName": "TemperatureDetection"
},
{
"id": "2645538",
"appId": "cc472578-2389-40ea-8525-a2b86fea23c4",
"eventName": "xxx"
}
]
}
}
However when I run query on AppSync console, this is what it returns:
{
"data": {
"events": null
}
}
Is there anything that I have done wrong so it will not recognized? When I go and check the logs of the AppSync, there is not any response.context log. All I have for response after the request in the log is as below image:
Deeply appreciates if anyone could help with this, I struggled for like two days on this. Thank you!
