Lambda returning wrong data – type mismatch error, expected type LIST

Lambda returning wrong data – type mismatch error, expected type LIST


0

In my schema.graphql I have set query:

type Query {
  listCourses(param1: String, param2: String): [Course]

and type Course:

type Course {
  id: ID!
  fullname: String
  shortname: String
  idnumber: String
  summary: String
}

And in my frontend application I am calling this query that triggers lambda:
async getDataByCodeType()
{

  const query = /* GraphQL */ `
        query ListCourses(
          $param1: String!
          $param2: String!
        ) {
          listCourses(
            param1: $param1
            param2: $param2
          ) {
            id
            fullname
            shortname
          }
      }
    `

  const variables = {
    param1: 'param1',
    param2: 'param1',
  }

  try {
    const result = await API.graphql(graphqlOperation(query, variables))
    console.log(result)
  } catch (error) {
    console.error('Error retrieving data:', error)
  }
}

And in my lambda I am returning the data:

const payload = {
    param1: para1,
    param2: para2,
  };
  const apiResponse = await lambda.invoke({
    FunctionName: FunctionName,
    InvocationType: "RequestResponse",
    Payload: JSON.stringify(payload),
  }).promise();
  const responsePayload = JSON.parse(apiResponse.Payload);
  let data;
  switch (event.target) {
    case 'list_course':
      data = responsePayload.body.courses;
      break;
    default:
      throw new Error("Invalid event target");
  }
  return {
    statusCode: 200,
    listCourse: data
  };

If I console.log(data) I get array of objects:

[
  {
    id: 1,
    name: 'test',
    idnumber: 'eee',
    description: ''
  },
  {
    id: 2,
    name: 'test2',
    idnumber: 'ccc',
    description: ''
  },
]

but still I get error: "message":"Can’t resolve value (/listAudiences) : type mismatch error, expected type LIST"}]} even if I test it via Appsync.

1

  • Your returned data has name and description but Course does not.

    – jarmod

    17 mins ago


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *