I have the following schema:
type Task @model
@aws_cognito_user_pools
@aws_api_key {
id: ID!
taskType: TaskType
taskTypeId: ID
}
type TaskType @aws_cognito_user_pools
@aws_api_key {
id: ID!
qualificationsId: [ID]
qualifications: [Qualification]
}
type Qualification @aws_cognito_user_pools
@aws_api_key {
id: ID!
name: String
}
type Query {
@aws_api_key
getTask(id: ID!): Task
@aws_cognito_user_pools
@aws_api_key
getTaskType(id: ID!): TaskType
@aws_cognito_user_pools
@aws_api_key
getQualification(id: ID!): Qualification
@aws_cognito_user_pools
@aws_api_key
}
The data is stored in three separate DynamoDB tables:
- TaskTable
- TaskTypeTable
- QualificationTable
When I execute my getTask query, I use a pipeline resolver that does the following:
- Gets the Task.
- Gets the TaskType attributes via the TaskTypeId in the Task object.
- BatchGets Qualifications via the qualificationsId array in the TaskType object.
My issue is the Qualifications array returns null.
This is what the root resolver looks like from my "getTask" query:
/**
* Starts the resolver execution
* @param {import('@aws-appsync/utils').Context} ctx the context
* @returns {*} the return value sent to the first AppSync function
*/
export function request(ctx) {
return {};
}
/**
* Returns the resolver result
* @param {import('@aws-appsync/utils').Context} ctx the context
* @returns {*} the return value of the last AppSync function response handler
*/
export function response(ctx) {
console.log("Final result: ", ctx.result);
return ctx.result;
}
The console log looks like this in CloudWatch:
be1e3005-a95b-4281-a198-a417a70ad319 INFO - code.js:16:5: "Final result: " {
"id": "1",
"taskTypeId": "1",
"taskType": {
"qualificationsId": [
"q1",
"q2",
"q3"
],
"taskName": "Task 1",
"id": "1",
"qualifications": [
{
"name": "Qualification 2",
"description": "Certified Medic",
"id": "q1"
},
{
"name": "Qualification 1",
"id": "q2"
},
{
"name": "Qualification 3",
"id": "q3"
}
]
}
}
So the qualifications is definitely being fetched and returned but still returns null.
Query:
query TestQuery {
getTask(id: "1") {
taskType {
qualifications {
id
name
}
taskName
id
}
}
}
Response:
{
"data": {
"getTask": {
"taskType": {
"qualifications": null,
"taskName": "Task 1",
"id": "1"
}
}
}
}
When I execute the "getTaskType" query I am able to get the qualifications data out as expected, so the resolver is working fine in that regard, just not when its nested inside a nested query.