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
demandé il y a 2 mois99 vues
1 réponse
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
INGÉNIEUR EN ASSISTANCE TECHNIQUE
répondu il y a 2 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions