저는 GitHunt-React와 GitHunt-API에서 Apollo pub-sub를 공부하고 있습니다. 나는 그 응용 프로그램을 실행하고 새 코멘트를 입력하면 코멘트가 제출 호출에 의해 저장 한 다음 updateQueries의 코드 블록은 여기에 실행됩니다 : 나는 내 응용 프로그램에이 코드를 복제 한Apollo updateQueries가 호출되지 않습니까?
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);
. 돌연변이가 올바르게 저장되지만 updateQueries 코드 블록은 을하지 않습니다 실행 :
const CreateIMPageWithMutations = graphql(CREATE_IM_MUTATION, {
props({ ownProps, mutate }) {
debugger;
return {
submit({ fromID, toID, msgText }) { <==SAVES SUCCESSFULLY
debugger;
return mutate({
variables: {
"fromID": fromID,
"toID": toID,
"msgText": msgText
},
optimisticResponse: {
__typename: 'Mutation',
createIM: {
__typename: 'createIM',
fromID: fromID,
toID: toID,
createdAt: +new Date,
msgText: msgText,
},
},
updateQueries: {
createIM: (prev, { mutationResult }) => {
debugger; <== THIS CODE BLOCK IS NEVER CALLED
const newMsg = mutationResult.data.createIM;
return update(prev, {
entry: {
IMs: {
$unshift: [newMsg],
},
},
});
},
},
});
},
};
},
})(CreateIM);
왜 내 updateQueries 실행 호출하지 않는 이유는 무엇입니까? 모든 정보에 대해 미리 감사드립니다.
업데이트 : 요청에 따라, 여기 CREATE_IM_MUTATION의 코드입니다 :
const CREATE_IM_MUTATION = gql`
mutation createIM ($fromID: String!, $toID: String!, $msgText: String!){
createIM(fromID: $fromID, toID: $toID, msgText: $msgText){
fromID
toID
msgText
}
}
`;
업데이트 :
const GETIMS_QUERY = gql`
query getIMs($fromID: String!, $toID: String!){
instant_message(fromID:$fromID, toID: $toID){
id,
fromID,
toID,
msgText
}
} `;
: 불황기에 @fabio_oliveira의 요청에 따라, 여기에 내가 업데이트하고 쿼리입니다
확실히 경우이를 그게 돌연변이 결과의 data.error가 설정되지 않았습니까? "createIM"이라는 정의 된 쿼리를 공유 할 수 있습니까? – GreenAsJade
... 그리고 ... 어떤 버전의 반응 - 아폴로? – GreenAsJade
React-Apollo v3.10.8. 어디에서 돌연변이 결과를보기 위해 중단 점을 설정할 수 있습니까? 해당 돌연변이가 데이터베이스를 성공적으로 업데이트하고 있지만, 거기에 아무 것도 없는지 확인하기 위해 data.error를 살펴 보니 매우 기쁩니다. – VikR