-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL Call on Many-to-many Relationship Does Not Return Related Items #13860
Comments
Hi @desert-digital 👋 thanks for raising this issue and providing detailed reproduction steps! I will attempt to reproduce and report back with any findings. |
hey @chrisbonifacio: any insight on this? thanks! |
...or perhaps @HuiSF / @chrisbonifacio this is a good opportunity to move this to Gen 2? Does many-to-many work in Gen 2? I ask because the Data table at this link says "No" for manyToMany but the documentation at this link shows how a many-to-many relationship can be built. Thanks again! |
Hi @HuiSF and @chrisbonifacio: I am kind of stuck here. Any update? Thanks! Ian. |
Hi @desert-digital, I was not able to reproduce the behavior described in this issue. I deployed this graphql schema: 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")
} and used this code to create the checklistModel, actionModel, and the checklistAction join table record. const getChecklistModelQuery = async (id: string) => {
const checklistModel = await client.graphql({
query: getChecklistModel,
variables: {
id,
} as GetChecklistModelQueryVariables,
});
console.log(checklistModel.data.getChecklistModel);
return checklistModel.data.getChecklistModel;
};
const createCheckListModelMutation = async () => {
const result = await client.graphql<
GraphQLQuery<CreateChecklistModelMutation>
>({
query: createChecklistModel,
variables: {
input: {
company: "testChecklist",
},
} as CreateChecklistModelMutationVariables,
});
console.log(result.data.createChecklistModel);
return result.data.createChecklistModel;
};
const createActionModelMutation = async () => {
const result = await client.graphql<
GraphQLQuery<CreateActionModelMutation>
>({
query: createActionModel,
variables: {
input: {
company: "testAction",
},
} as CreateActionModelMutationVariables,
});
console.log(result.data.createActionModel);
return result.data.createActionModel;
};
const createChecklistActionsMutation = async () => {
const checklistModel = await createCheckListModelMutation();
setId(checklistModel?.id as string);
const actionModel = await createActionModelMutation();
const result = await client.graphql<
GraphQLQuery<CreateChecklistActionsMutation>
>({
query: createChecklistActions,
variables: {
input: {
actionModelId: actionModel?.id,
checklistModelId: checklistModel?.id,
},
} as CreateChecklistActionsMutationVariables,
});
const checklistModelQueryResult = await getChecklistModelQuery(
checklistModel?.id as string
);
console.log("ChecklistAction:", result.data.createChecklistActions);
console.log("ChecklistModel:", checklistModelQueryResult);
}; This is the result: The join record is created. The result of the getChecklistModel query doesn't return any related actionModels can be explained because the query does not include it in the selection set: export const getChecklistModel = /* GraphQL */ `query GetChecklistModel($id: ID!) {
getChecklistModel(id: $id) {
id
company
name
notes
duration
preCharter
actionModels {
nextToken
__typename
}
createdAt
updatedAt
__typename
}
}
` as GeneratedQuery<
APITypes.GetChecklistModelQueryVariables,
APITypes.GetChecklistModelQuery
>; if i adjust the query to include actionModel items, i get the related actionModel items: |
I tried reproducing with the latest versions of the amplify packages. Can you make sure you are using the latest versions of the amplify packages? Try upgrading and let me know if that helps resolve the issue. |
Hi: thanks so much @chrisbonifacio. Just upgrading resulted in no change, unfortunately; was certainly worth a try. I created another Checklist, and can see a new ChecklistActions record, so the creation is (still) works. When I look at the query in queries.ts, it is the same as the query above that doesn't work
Interestingly, the GraphQL query in queries.graphql is different:
So my next question is: shouldn't the query in queries.ts (which is generated by codegen) include the action model items?! Do I need to generate the queries using typecript instead of angular (when I created the API)? Thanks! Ian. |
Is this the correct place to get the queries?
|
OK: it's working. I ran
and selected typescript, and then the defaults. The queries.ts file (in the graphql/queries folder) was updated, and I could see the correct GraphQL is there now. Thanks so much for pointing me in the right direction! |
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
The text was updated successfully, but these errors were encountered: