Unable to convert $util.toJson($context.source.lessons)\n to class com.amazonaws.deepdish.transform.model.lambda.LambdaVersionedConfig
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
- 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]}
])
}
-
Execute a
createLessonMaterialmutation -
Execute a
listMaterialsquery
{
listMaterials {
items {
id
lessons {
items {
lesson {
id
}
}
}
}
}
}
- 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
it's the same for me, any solution?
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
@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:
- Which group does the current user doing the query belongs to? (Member or Admin)
- Is this an API where you have conflict detection enabled?
Hi @TheBenck
Are you still stuck on this Issue? If yes, Can you provide details mentioned in comment above?
This issue has been automatically closed because of inactivity. Please open a new issue if you are still encountering problems.
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.