amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Unable to convert $util.toJson($context.source.lessons)\n to class com.amazonaws.deepdish.transform.model.lambda.LambdaVersionedConfig

Open TheBenck opened this issue 6 years ago • 6 comments

Describe the bug An error is thrown when accessing a many-to-many connection: "Unable to convert $util.toJson($context.source.lessons)\n to class com.amazonaws.deepdish.transform.model.lambda.LambdaVersionedConfig."

Amplify CLI Version 4.21.3

To Reproduce

  1. With the following schema:
type Lesson
  @model(subscriptions: {level: public})
  @auth(
    rules: [
      {allow: groups, groups: ["Member"], operations: [read]},
      {allow: groups, groups: ["Admin"], operations: [create, read, update, delete]}
    ]
  )
{
  id: ID!
    @auth(rules: [
      {allow: public, provider: iam, operations: [read]},
      {allow: private, provider: userPools, operations: [read]}
    ])
  groupsCanAccess: [String]!
    @auth(rules: [
      {allow: public, provider: iam, operations: [read]},
      {allow: private, provider: userPools, operations: [read]}
    ])
  #...
  materials: [LessonMaterial]
    @connection(keyName: "byLesson", fields: ["id"])
    @auth(rules: [
      {allow: groups, groupsField: "groupsCanAccess", operations: [read]},
      {allow: groups, groups: ["Admin"], operations: [create, read, update, delete]}
    ])
}

type LessonVideo
  @model
  @key(name: "byLesson", fields: ["lessonId", "materialId"])
  @key(name: "byMaterial", fields: ["materialId", "lessonId"])
  @key(name: "byInstructor", fields: ["instructorId", "lessonId"])
  @auth(
    rules: [
      {allow: private, provider: userPools, operations: [read]},
      {allow: groups, groups: ["Admin"], operations: [create, read, update, delete]}
    ]
  )
{
  id: ID!
  lessonId: ID!
  materialId: ID!
  instructorId: ID!
  lesson: Lesson! @connection(fields: ["lessonId"])
  material: Material! @connection(fields: ["materialId"])
  instructor: Instructor! @connection(fields: ["instructorId"])
  skillLevel: Float!
}

type Material
  @model
  @auth(
    rules: [
      {allow: groups, groups: ["Member"], operations: [read]},
      {allow: groups, groups: ["Admin"], operations: [create, read, update, delete]}
    ]
  )
{
  id: ID!
  #...
  lessons: [LessonMaterial]
    @connection(keyName: "byMaterial", fields: ["id"])
    @auth(rules: [
      {allow: groups, groups: ["Admin"], operations: [create, read, update, delete]}
    ])
}

type Instructor
  @model
  @auth(
    rules: [
      {allow: groups, groups: ["Member"], operations: [read]},
      {allow: groups, groups: ["Admin"], operations: [create, read, update, delete]}
    ]
  )
{
  id: ID!
  #...
  lessons: [LessonMaterial!] @connection(keyName: "byInstructor", fields: ["id"])
    @auth(rules: [
      {allow: public, provider: iam, operations: [read]},
      {allow: groups, groups: ["Member"], operations: [read]},
      {allow: groups, groups: ["Admin"], operations: [create, read, update, delete]}
    ])
}
  1. Execute a createLessonMaterial mutation

  2. Execute a listMaterials query

{
  listMaterials {
    items {
      id
      lessons {
        items {
	  lesson {
            id
          }
        }
      }
    }
  }
}
  1. An error occurs
{
  "data": {
    "listMaterials": {
      "items": [
        {
          "id": "b38ce691-2699-4270-b2b6-1ea9c1452900",
          "lessons": null
        }
      ]
    }
  },
  "errors": [
    {
      "message": "Unable to convert $util.toJson($context.source.lessons)\n to class com.amazonaws.deepdish.transform.model.lambda.LambdaVersionedConfig.",
      "errorType": "MappingTemplate",
      "data": null,
      "errorInfo": null,
      "path": [
        "listMaterials",
        "items",
        0,
        "lessons"
      ],
      "locations": [
        {
          "line": 7,
          "column": 7,
          "sourceName": "GraphQL request"
        }
      ]
    }
  ]
}

Expected behavior The LessonMaterials should be returned without error.

Desktop (please complete the following information):

  • OS: macOS 10.15.3
  • Node Version: 10.15.0

TheBenck avatar Jun 19 '20 12:06 TheBenck

it's the same for me, any solution?

jorge-riberi avatar Jul 22 '20 22:07 jorge-riberi

In my case I had to delete the @auth from the attribute, lessons in your case. Then everything worked correctly.

It may be too late now, but I'll serve someone else

jorge-riberi avatar Jul 23 '20 11:07 jorge-riberi

@TheBenck the schema you posted above does not have LessonMaterial type. Is it a regualr Many to Many connection table? Do you have any @auth directive in for that table? I also see LessonVideo type which is also a connecting table. Did LessonMaterial got renamed to LessonVideo in your schema.

Could you also include information about the following:

  1. Which group does the current user doing the query belongs to? (Member or Admin)
  2. Is this an API where you have conflict detection enabled?

yuth avatar Aug 21 '20 18:08 yuth

Hi @TheBenck

Are you still stuck on this Issue? If yes, Can you provide details mentioned in comment above?

akshbhu avatar Oct 26 '20 18:10 akshbhu

This issue has been automatically closed because of inactivity. Please open a new issue if you are still encountering problems.

stale[bot] avatar Nov 05 '20 02:11 stale[bot]

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 25 '21 16:05 github-actions[bot]