2
기본적으로 돌연변이 이후 UI를 업데이트하고 싶지만, 지금은 고통스러워하고 며칠 동안 붙어 있습니다.돌연변이 이후 Apollo 클라이언트 업데이트가 원래 결과에 매핑되지 않습니다?
내 구성 요소 중 일부는 내 루트 쿼리에 의존하며 결과를 매핑합니다.
새 리소스를 만들고 루트 쿼리를 업데이트 할 때마다 원래 결과가 더 이상로드되지 않으므로 더 이상 결과가 없으므로 can't read property map of undefined
이됩니다. 수표를 추가하면 아무 것도 할 수 없으며 영원히 계속로드됩니다.
이 내 돌연변이 :
나는 단지 단지 내 자원이 추가 된 그룹을 새로 고쳐 내 UI를 업데이트 할export const withCreateLink = graphql(createLink, {
// Mutate normally gets passed as prop to wrapped component
props({ownProps, mutate}) {
return {
// But for updating the store we're actually hijacking mutate to a custom function
createLink(url, description, group) {
return mutate({
variables: {
url,
description,
group
},
optimisticResponse: {
createLink: {
__typename: 'Link',
id: -1,
url,
description,
group: {
id: group
}
}
},
update: (proxy, mutationResult) => {
const query = getAllGroups;
const data = proxy.readQuery({query});
data.allGroups.forEach((groupData) => {
if(groupData.id == group)
groupData.links.push(mutationResult.data.createLink);
});
proxy.writeQuery({
query,
data
})
}
})
}
}
}
});
. 아무도 나를 도울 수 있습니까?
dataIdFromObject: (result) => {
if (result.id && result.__typename) {
return result.__typename + ':' + result.id;
}
return null;
}
난 그냥 ID를 사용하여 내 캐시에 쓸 수 없습니다 추측 : 유형 이름을 확인하는 dataIdFromObject 변형
는
이것은 1.0 이후의 기본값이므로 dataIdFromObject를 제공하지 않아도됩니다. – helfer