1
我有两个型号,存在以下关系:所有项目的Apollo客户端特定的更新查询?
组有许多 链接
所以基本上我的初始查询是getAllGroups,其中取各组及其链接。 我有一个简单的创建链接的突变,什么是最有效的方式来更新我的用户界面?
目前我有:
export const withCreateLink = graphql(createLink, {
props({ownProps, mutate}) {
return {
createLink(url, description, group) {
return mutate({
variables: {
url,
description,
group
},
updateQueries: {
getAllGroups: (prev, {mutationResult}) => {
const newLink = mutationResult.data.createLink;
return update(prev, {
allGroups: {
links: {
$push: [newLink]
}
}
})
}
}
})
}
}
}
});
基本上我只希望获取其中有添加到它的链接群,但我需要指定哪个组是。我如何去做这件事?
那么你想添加一个链接到特定的组?因为现在你给所有组添加新的链接 –
是的,但我想我已经知道了。我可以从我的道具中收到组索引,然后在我的查询中使用该索引:allGroups:{[groupIndex]:{links:{...}}}。对?我会补充说,作为答案。谢谢你的评论。 –
是看起来像正确的方式 –