gpt4 book ai didi

graphql - 将结果写入存储以供查询时出错。无法读取未定义的属性 'query'

转载 作者:行者123 更新时间:2023-12-01 22:04:49 25 4
gpt4 key购买 nike

在更改后写入要存储的查询时出现错误。突变有效,我能够读取突变后的查询。当我将相同的查询写入商店缓存时,出现以下错误:

index.js:2178 Error: Error writing result to store for query:
query ($applicationId: Int) {
vApplicationApprovalChainList(ApplicationId: $applicationId) {
id
approvalOrder
approverId
name
applicationId
__typename
}
}

Cannot read property 'vApplicationApprovalChainList' of undefined
at writeToStore.js:101
at Array.forEach (<anonymous>)
at writeSelectionSetToStore (writeToStore.js:97)
at writeResultToStore (writeToStore.js:75)
at InMemoryCache../node_modules/apollo-cache-inmemory/lib/inMemoryCache.js.InMemoryCache.write (inMemoryCache.js:99)

这是我的代码.. 突变和 store.readQuery 有效,但 store.writeQuery 给出了上述错误。提前感谢您的任何反馈。

APPROVERSLIST_QUERY = gql`
query ($applicationId:Int){
vApplicationApprovalChainList(ApplicationId:$applicationId){
id
approvalOrder
approverId
name
applicationId

}
}

`;


handleClick() {
const { row, mutate} = this.props;
mutate({
variables: {
id: row.id
},
update: (store, { data: { deleteApprover } }) => {

const newdata = store.readQuery({
query: APPROVERSLIST_QUERY,
variables: { applicationId: row.applicationId }
});
console.log(newdata);
newdata.vApplicationApprovalChainList = newdata.vApplicationApprovalChainList.filter(approver => approver.id !== deleteApprover.id);
store.writeQuery({
query: APPROVERSLIST_QUERY, newdata });
}
});



}

最佳答案

您没有将新数据传递给 writeQuery。传递给 writeQuery 的对象必须有一个包含新数据的名为 data 的属性。此外,由于您的查询包含变量,因此您也需要包含该信息。

store.writeQuery({
query: APPROVERSLIST_QUERY,
data: newdata,
variables: {
applicationId: row.applicationId,
},
});

请参阅the official docs获取更多示例以及对这两种方法的更详尽解释。

关于graphql - 将结果写入存储以供查询时出错。无法读取未定义的属性 'query',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52489321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com