No items are returned by GraphQL call on many-to-many relation. Items exist in the correctly named DynamoDB join table. Specific error is "TypeError: checklistModel.actionModels.items is not iterable"
The definition of the ChecklistModel and ActionModel types are below. All models in the schema file are public (to eliminate any security related errors that may be causing this issue).
type ActionModel @model @auth(rules: [{ allow: public }]){
id: ID!
company: String!
name: String
notes: String
duration: Int
checklists: [ChecklistModel] @manyToMany(relationName: "ChecklistActions")
}
type ChecklistModel @model @auth(rules: [{ allow: public }]){
id: ID!
company: String!
name: String
notes: String
duration: Int
preCharter: Boolean
actionModels: [ActionModel] @manyToMany(relationName: "ChecklistActions")
workflows: [WorkflowModel] @manyToMany(relationName: "WorkflowChecklists")
}
Expected behavior
checklistModel.actionModels.items is an array with one item (and so therefore iterable)
Reproduction steps
Select 'Checklist Admin'
Select a Checklist item
Open the context-based menu, and select 'edit'
The error occurs when the EditChecklist component is opened.
Code Snippet
// Put your code below this line.
// Code used to create a Checklist Model with Action Models
// In the add-checklist component
async onAddChecklistPressed(model: ChecklistModel, formDirective: FormGroupDirective) {
try {
this._checklistModelsService.createChecklistModel(model, this.checklist).then(() => {
this._snackBar.open('Created a new checklist', 'OK', { duration: 3000 });
this.checklistForm.reset();
formDirective.resetForm();
this.checklist = [];
this._getActions();
});
} catch (error) {
this._snackBar.open('Error creating the checklist', 'OK', { duration: 3000 });
}
}
// In the ChecklistModel service
async createChecklistModel(checklistModel: ChecklistModel, actions: ActionModel[]) {
const checklistMutationResult = await this.client.graphql({
query: createChecklistModel,
variables: {
input: {
company: 'seaforth',
name: checklistModel.name,
duration: checklistModel.duration,
notes: checklistModel.notes,
preCharter: checklistModel.preCharter,
}
}
});
const checklist = checklistMutationResult.data.createChecklistModel;
for (const action of actions) {
await this.client.graphql({
query: createChecklistActions,
variables: {
input: {
actionModelId: action.id,
checklistModelId: checklist.id
},
}
});
}
const updatedChecklist = await this.getChecklistModelFromId(checklist.id);
console.log(updatedChecklist.actionModels);
}
// Code to retrieve the ChecklistModel
// In the ChecklistModel service
async getChecklistModelFromId(id: string): Promise<ChecklistModel> {
const checklistResult = await this.client.graphql({
query: getChecklistModel,
variables: { id: id }
})
return checklistResult.data.getChecklistModel as ChecklistModel;
}
Log output
The item from the join table is shown below. The actionModelId and checklistModelId match the ids from the corresponding ActionModel and ChecklistModel tables. The value returned from the getChecklistModelFromId is also attached.
Before opening, please confirm:
JavaScript Framework
Angular
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
api
Backend
Amplify CLI
Environment information
Describe the bug
No items are returned by GraphQL call on many-to-many relation. Items exist in the correctly named DynamoDB join table. Specific error is "TypeError: checklistModel.actionModels.items is not iterable"
The definition of the ChecklistModel and ActionModel types are below. All models in the schema file are public (to eliminate any security related errors that may be causing this issue).
Expected behavior
checklistModel.actionModels.items is an array with one item (and so therefore iterable)
Reproduction steps
The error occurs when the EditChecklist component is opened.
Code Snippet
Log output
The item from the join table is shown below. The actionModelId and checklistModelId match the ids from the corresponding ActionModel and ChecklistModel tables. The value returned from the getChecklistModelFromId is also attached.
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response