Double nested AppSync query in pipeline resolver returns null unexpected

0

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:

  1. Gets the Task.
  2. Gets the TaskType attributes via the TaskTypeId in the Task object.
  3. 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.

Gustav
질문됨 2달 전94회 조회
1개 답변
0

Hello,

Based on Schema and resolver code you provided I have tried to reproduce the issue at my end but I am not able to reproduce it. You shared that data is stored in three separate DynamoDB tables (TaskTable, TaskTypeTable, QualificationTable) so If you are deploying the AppSync API using Amplify CLI then I would request you to kindly refer Setup relationships between models and use the subscriptionsInheritPrimaryAuth feature flag under graphqltransformer in the amplify/backend/cli.json file.

If you are deploying AppSync API manually then to further investigate the issue I would request you to kindly create support case from the support centre dashboard as this will allow us to provide you resource specific guidance and dive deep into the same.

Best regards, Shiven D.

AWS
지원 엔지니어
답변함 2달 전

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

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

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

관련 콘텐츠