我创建了这个 GraphQL 架构并通过 Amplify 将其传递给 AppSync:
type Member @model {
id: ID!
name: String!
}
type Team @model {
id: ID!
title: String!
members: [Member]
}
并且 AWS Amplify 为团队更新生成了以下突变:
export const updateTeam = /* GraphQL */ `
mutation UpdateTeam(
$input: UpdateTeamInput!
$condition: ModelTeamConditionInput
) {
updateTeam(input: $input, condition: $condition) {
id
name
...
}
}
`;
我想通过以下方式更新团队:
const doSomething = async (id) => {
try {
const team = teams[id];
team.title = // new title
// cut off automatically added bits
const teamData = await API.graphql(
graphqlOperation(updateTeam, { input: team })
);
} catch (error) {
console.error(`Mutation failed`, error);
}
};
我正在阅读team
成功,我可以看到这members
是团队对象的一部分。但是,它会引发错误:
message: "The variables input contains a field name 'members' that is not defined for input object type 'UpdateTeamInput' "
我应该在哪里以及如何解决这个问题?我的意思是我必须使用类似的东西:
...
graphqlOperation(updateTeam, { input: team, members: team.members })
...
虽然我没有触摸members
物体team[id]
?