Graphql Apollo UpdateSeries未调用?
我正在学习GitHunt React和GitHunt API中的阿波罗酒吧sub。当我运行这些应用程序并输入新注释时,该注释通过调用submit保存,然后UpdateSeries代码块在此处运行:Graphql Apollo UpdateSeries未调用?,graphql,apollo,react-apollo,Graphql,Apollo,React Apollo,我正在学习GitHunt React和GitHunt API中的阿波罗酒吧sub。当我运行这些应用程序并输入新注释时,该注释通过调用submit保存,然后UpdateSeries代码块在此处运行: const CommentsPageWithMutations = graphql(SUBMIT_COMMENT_MUTATION, { props({ ownProps, mutate }) { console.log('in CommentsPageWithMutations');
const CommentsPageWithMutations = graphql(SUBMIT_COMMENT_MUTATION, {
props({ ownProps, mutate }) {
console.log('in CommentsPageWithMutations');
return {
submit({ repoFullName, commentContent }) { <==RUNS THE MUTATION
debugger;
return mutate({
variables: { repoFullName, commentContent },
optimisticResponse: {
__typename: 'Mutation',
submitComment: {
__typename: 'Comment',
id: null,
postedBy: ownProps.currentUser,
createdAt: +new Date,
content: commentContent,
},
},
updateQueries: {
Comment: (prev, { mutationResult }) => {
debugger; // <== RUNS AFTER THE MUTATION IS SENT TO SERVER
const newComment = mutationResult.data.submitComment;
if (isDuplicateComment(newComment, prev.entry.comments)) {
return prev;
}
return update(prev, {
entry: {
comments: {
$unshift: [newComment],
},
},
});
},
},
});
},
};
},
})(CommentsPage);
更新:根据@fabio_oliveira on Slack的请求,以下是我正在更新的查询:
const GETIMS_QUERY = gql`
query getIMs($fromID: String!, $toID: String!){
instant_message(fromID:$fromID, toID: $toID){
id,
fromID,
toID,
msgText
}
} `;
@法比奥·奥里维拉(fabio_oliveira on Slack)提供了答案。在UpdateSeries中,我必须将密钥的名称更改为getIMS,即原始数据收集查询的名称--非变异查询的名称:
updateQueries: {
getIMs: (prev, { mutationResult }) => {
debugger;
[.....]
突变结果中的data.error确实没有设置吗?你能分享被称为“createIM”的查询定义的代码吗?。。。而且。。。什么版本的react apollo?react apollo v3.10.8。在哪里可以设置断点以查看突变的结果?变异成功地更新了数据库,但我很乐意查看data.error以查看是否有任何内容。我在ownProps中找到了data.error。Loading设置为false,预期记录已在数组中返回,data.error未定义。页面上是否有名为
createIM
的活动查询?
const GETIMS_QUERY = gql`
query getIMs($fromID: String!, $toID: String!){
instant_message(fromID:$fromID, toID: $toID){
id,
fromID,
toID,
msgText
}
} `;
updateQueries: {
getIMs: (prev, { mutationResult }) => {
debugger;
[.....]